There is only one difference between fat12_ent_blocknr and fat_ent_blocknr
functions in bytes calculation. Let's add bits checking to fat_ent_blocknr
instead code duplication.

Signed-off-by: Alexander Kuleshov <[email protected]>
---
 fs/fat/fatent.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/fs/fat/fatent.c b/fs/fat/fatent.c
index 260705c..314ab50 100644
--- a/fs/fat/fatent.c
+++ b/fs/fat/fatent.c
@@ -21,21 +21,16 @@ struct fatent_operations {
 
 static DEFINE_SPINLOCK(fat12_entry_lock);
 
-static void fat12_ent_blocknr(struct super_block *sb, int entry,
-                             int *offset, sector_t *blocknr)
-{
-       struct msdos_sb_info *sbi = MSDOS_SB(sb);
-       int bytes = entry + (entry >> 1);
-       WARN_ON(entry < FAT_START_ENT || sbi->max_cluster <= entry);
-       *offset = bytes & (sb->s_blocksize - 1);
-       *blocknr = sbi->fat_start + (bytes >> sb->s_blocksize_bits);
-}
-
 static void fat_ent_blocknr(struct super_block *sb, int entry,
                            int *offset, sector_t *blocknr)
 {
        struct msdos_sb_info *sbi = MSDOS_SB(sb);
-       int bytes = (entry << sbi->fatent_shift);
+       int bytes;
+
+       if (sbi->fat_bits == 12)
+               bytes = entry + (entry >> 1);
+       else
+               bytes = (entry << sbi->fatent_shift);
        WARN_ON(entry < FAT_START_ENT || sbi->max_cluster <= entry);
        *offset = bytes & (sb->s_blocksize - 1);
        *blocknr = sbi->fat_start + (bytes >> sb->s_blocksize_bits);
@@ -250,7 +245,7 @@ static int fat32_ent_next(struct fat_entry *fatent)
 }
 
 static struct fatent_operations fat12_ops = {
-       .ent_blocknr    = fat12_ent_blocknr,
+       .ent_blocknr    = fat_ent_blocknr,
        .ent_set_ptr    = fat12_ent_set_ptr,
        .ent_bread      = fat12_ent_bread,
        .ent_get        = fat12_ent_get,
-- 
2.3.0.80.g18d0fec

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to