fs/affs: add validation block function

Avoid repeating 4 times the same calculation.

Link: http://lkml.kernel.org/r/20170109191208.6085-3-fabf@skynet.be
Signed-off-by: Fabian Frederick <fabf@skynet.be>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Fabian Frederick 2017-02-27 14:27:46 -08:00 committed by Linus Torvalds
parent 7981a05a0e
commit d5de9fd594
1 changed files with 10 additions and 4 deletions

View File

@ -212,6 +212,12 @@ extern const struct address_space_operations affs_aops_ofs;
extern const struct dentry_operations affs_dentry_operations; extern const struct dentry_operations affs_dentry_operations;
extern const struct dentry_operations affs_intl_dentry_operations; extern const struct dentry_operations affs_intl_dentry_operations;
static inline bool affs_validblock(struct super_block *sb, int block)
{
return(block >= AFFS_SB(sb)->s_reserved &&
block < AFFS_SB(sb)->s_partition_size);
}
static inline void static inline void
affs_set_blocksize(struct super_block *sb, int size) affs_set_blocksize(struct super_block *sb, int size)
{ {
@ -221,7 +227,7 @@ static inline struct buffer_head *
affs_bread(struct super_block *sb, int block) affs_bread(struct super_block *sb, int block)
{ {
pr_debug("%s: %d\n", __func__, block); pr_debug("%s: %d\n", __func__, block);
if (block >= AFFS_SB(sb)->s_reserved && block < AFFS_SB(sb)->s_partition_size) if (affs_validblock(sb, block))
return sb_bread(sb, block); return sb_bread(sb, block);
return NULL; return NULL;
} }
@ -229,7 +235,7 @@ static inline struct buffer_head *
affs_getblk(struct super_block *sb, int block) affs_getblk(struct super_block *sb, int block)
{ {
pr_debug("%s: %d\n", __func__, block); pr_debug("%s: %d\n", __func__, block);
if (block >= AFFS_SB(sb)->s_reserved && block < AFFS_SB(sb)->s_partition_size) if (affs_validblock(sb, block))
return sb_getblk(sb, block); return sb_getblk(sb, block);
return NULL; return NULL;
} }
@ -238,7 +244,7 @@ affs_getzeroblk(struct super_block *sb, int block)
{ {
struct buffer_head *bh; struct buffer_head *bh;
pr_debug("%s: %d\n", __func__, block); pr_debug("%s: %d\n", __func__, block);
if (block >= AFFS_SB(sb)->s_reserved && block < AFFS_SB(sb)->s_partition_size) { if (affs_validblock(sb, block)) {
bh = sb_getblk(sb, block); bh = sb_getblk(sb, block);
lock_buffer(bh); lock_buffer(bh);
memset(bh->b_data, 0 , sb->s_blocksize); memset(bh->b_data, 0 , sb->s_blocksize);
@ -253,7 +259,7 @@ affs_getemptyblk(struct super_block *sb, int block)
{ {
struct buffer_head *bh; struct buffer_head *bh;
pr_debug("%s: %d\n", __func__, block); pr_debug("%s: %d\n", __func__, block);
if (block >= AFFS_SB(sb)->s_reserved && block < AFFS_SB(sb)->s_partition_size) { if (affs_validblock(sb, block)) {
bh = sb_getblk(sb, block); bh = sb_getblk(sb, block);
wait_on_buffer(bh); wait_on_buffer(bh);
set_buffer_uptodate(bh); set_buffer_uptodate(bh);