Skip to content

Commit d5de9fd

Browse files
Fabian Fredericktorvalds
authored andcommitted
fs/affs: add validation block function
Avoid repeating 4 times the same calculation. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Fabian Frederick <[email protected]> Cc: Al Viro <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 7981a05 commit d5de9fd

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

fs/affs/affs.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,12 @@ extern const struct address_space_operations affs_aops_ofs;
212212
extern const struct dentry_operations affs_dentry_operations;
213213
extern const struct dentry_operations affs_intl_dentry_operations;
214214

215+
static inline bool affs_validblock(struct super_block *sb, int block)
216+
{
217+
return(block >= AFFS_SB(sb)->s_reserved &&
218+
block < AFFS_SB(sb)->s_partition_size);
219+
}
220+
215221
static inline void
216222
affs_set_blocksize(struct super_block *sb, int size)
217223
{
@@ -221,15 +227,15 @@ static inline struct buffer_head *
221227
affs_bread(struct super_block *sb, int block)
222228
{
223229
pr_debug("%s: %d\n", __func__, block);
224-
if (block >= AFFS_SB(sb)->s_reserved && block < AFFS_SB(sb)->s_partition_size)
230+
if (affs_validblock(sb, block))
225231
return sb_bread(sb, block);
226232
return NULL;
227233
}
228234
static inline struct buffer_head *
229235
affs_getblk(struct super_block *sb, int block)
230236
{
231237
pr_debug("%s: %d\n", __func__, block);
232-
if (block >= AFFS_SB(sb)->s_reserved && block < AFFS_SB(sb)->s_partition_size)
238+
if (affs_validblock(sb, block))
233239
return sb_getblk(sb, block);
234240
return NULL;
235241
}
@@ -238,7 +244,7 @@ affs_getzeroblk(struct super_block *sb, int block)
238244
{
239245
struct buffer_head *bh;
240246
pr_debug("%s: %d\n", __func__, block);
241-
if (block >= AFFS_SB(sb)->s_reserved && block < AFFS_SB(sb)->s_partition_size) {
247+
if (affs_validblock(sb, block)) {
242248
bh = sb_getblk(sb, block);
243249
lock_buffer(bh);
244250
memset(bh->b_data, 0 , sb->s_blocksize);
@@ -253,7 +259,7 @@ affs_getemptyblk(struct super_block *sb, int block)
253259
{
254260
struct buffer_head *bh;
255261
pr_debug("%s: %d\n", __func__, block);
256-
if (block >= AFFS_SB(sb)->s_reserved && block < AFFS_SB(sb)->s_partition_size) {
262+
if (affs_validblock(sb, block)) {
257263
bh = sb_getblk(sb, block);
258264
wait_on_buffer(bh);
259265
set_buffer_uptodate(bh);

0 commit comments

Comments
 (0)