Skip to content

Commit

Permalink
fat: move MAX_FAT to fat.h and change it to inline function
Browse files Browse the repository at this point in the history
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 [email protected] 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/[email protected]
Signed-off-by: Carmeli Tamir <[email protected]>
Acked-by: OGAWA Hirofumi <[email protected]>
Reviewed-by: Sergey Senozhatsky <[email protected]>
Cc: Bart Van Assche <[email protected]>
Cc: Johannes Thumshirn <[email protected]>
Cc: Martin K. Petersen <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
carmeli-tamir authored and torvalds committed Jan 4, 2019
1 parent b553337 commit d19dc01
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
9 changes: 9 additions & 0 deletions fs/fat/fat.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ static inline struct msdos_sb_info *MSDOS_SB(struct super_block *sb)
return sb->s_fs_info;
}

/* Maximum number of clusters */
static inline u32 max_fat(struct super_block *sb)
{
struct msdos_sb_info *sbi = MSDOS_SB(sb);

return sbi->fat_bits == 32 ? MAX_FAT32 :
sbi->fat_bits == 16 ? MAX_FAT16 : MAX_FAT12;
}

static inline struct msdos_inode_info *MSDOS_I(struct inode *inode)
{
return container_of(inode, struct msdos_inode_info, vfs_inode);
Expand Down
2 changes: 1 addition & 1 deletion fs/fat/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1781,7 +1781,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat,
/* check that FAT table does not overflow */
fat_clusters = calc_fat_clusters(sb);
total_clusters = min(total_clusters, fat_clusters - FAT_START_ENT);
if (total_clusters > MAX_FAT(sb)) {
if (total_clusters > max_fat(sb)) {
if (!silent)
fat_msg(sb, KERN_ERR, "count of clusters too big (%u)",
total_clusters);
Expand Down
2 changes: 0 additions & 2 deletions include/uapi/linux/msdos_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@
#define MAX_FAT12 0xFF4
#define MAX_FAT16 0xFFF4
#define MAX_FAT32 0x0FFFFFF6
#define MAX_FAT(s) (MSDOS_SB(s)->fat_bits == 32 ? MAX_FAT32 : \
MSDOS_SB(s)->fat_bits == 16 ? MAX_FAT16 : MAX_FAT12)

/* bad cluster mark */
#define BAD_FAT12 0xFF7
Expand Down

0 comments on commit d19dc01

Please sign in to comment.