Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fat: move MAX_FAT to fat.h and change it to inline function

MAX_FAT is useless in msdos_fs.h, since it uses the MSDOS_SB function
that is defined in fat.h. So really, this macro can be only called from
code that already includes fat.h.

Hence, this patch moves it to fat.h, right after MSDOS_SB is defined. I
also changed it to an inline function in order to save the double call
to MSDOS_SB. This was suggested by joe@perches.com in the previous
version.

This patch is required for the next in the series, in which the variant
(whether this is FAT12, FAT16 or FAT32) checks are replaced with new
macros.

Link: http://lkml.kernel.org/r/1544990640-11604-3-git-send-email-carmeli.tamir@gmail.com
Signed-off-by: Carmeli Tamir <carmeli.tamir@gmail.com>
Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Bart Van Assche <bvanassche@acm.org>
Cc: Johannes Thumshirn <jthumshirn@suse.de>
Cc: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Carmeli Tamir and committed by
Linus Torvalds
d19dc016 b553337a

+10 -3
+9
fs/fat/fat.h
··· 142 142 return sb->s_fs_info; 143 143 } 144 144 145 + /* Maximum number of clusters */ 146 + static inline u32 max_fat(struct super_block *sb) 147 + { 148 + struct msdos_sb_info *sbi = MSDOS_SB(sb); 149 + 150 + return sbi->fat_bits == 32 ? MAX_FAT32 : 151 + sbi->fat_bits == 16 ? MAX_FAT16 : MAX_FAT12; 152 + } 153 + 145 154 static inline struct msdos_inode_info *MSDOS_I(struct inode *inode) 146 155 { 147 156 return container_of(inode, struct msdos_inode_info, vfs_inode);
+1 -1
fs/fat/inode.c
··· 1781 1781 /* check that FAT table does not overflow */ 1782 1782 fat_clusters = calc_fat_clusters(sb); 1783 1783 total_clusters = min(total_clusters, fat_clusters - FAT_START_ENT); 1784 - if (total_clusters > MAX_FAT(sb)) { 1784 + if (total_clusters > max_fat(sb)) { 1785 1785 if (!silent) 1786 1786 fat_msg(sb, KERN_ERR, "count of clusters too big (%u)", 1787 1787 total_clusters);
-2
include/uapi/linux/msdos_fs.h
··· 65 65 #define MAX_FAT12 0xFF4 66 66 #define MAX_FAT16 0xFFF4 67 67 #define MAX_FAT32 0x0FFFFFF6 68 - #define MAX_FAT(s) (MSDOS_SB(s)->fat_bits == 32 ? MAX_FAT32 : \ 69 - MSDOS_SB(s)->fat_bits == 16 ? MAX_FAT16 : MAX_FAT12) 70 68 71 69 /* bad cluster mark */ 72 70 #define BAD_FAT12 0xFF7