]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
fat: avoid stack overflow warning
authorArnd Bergmann <arnd@arndb.de>
Fri, 15 May 2026 20:44:46 +0000 (22:44 +0200)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 9 Jul 2026 22:48:55 +0000 (15:48 -0700)
Building the fat kunit tests on with -fsanitize=alignment reveals some
rather excessive stack usage:

fs/fat/fat_test.c: In function 'fat_clus_to_blknr_test':
fs/fat/fat_test.c:33:1: error: the frame size of 4736 bytes is larger than 1536 bytes [-Werror=frame-larger-than=]
   33 | }
      | ^
fs/fat/fat_test.c: In function 'fat_get_blknr_offset_test':
fs/fat/fat_test.c:52:1: error: the frame size of 4800 bytes is larger than 1536 bytes [-Werror=frame-larger-than=]

The problem is clearly related to the on-stack copy of a local
msdos_sb_info structure.  Avoid this by making that copy 'static const'
and changing the called functions to accept a constant input.

Link: https://lore.kernel.org/20260515204456.2692208-1-arnd@kernel.org
Fixes: 410002f8139c ("kunit: fat: test cluster and directory i_pos layout helpers")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Jan Kara <jack@suse.cz>
Cc: Adi Nata <adinata.softwareengineer@gmail.com>
Cc: David Laight <david.laight.linux@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/fat/fat.h
fs/fat/fat_test.c

index 99ed9228a677be754b815753ba9e5dbf82efd423..2772675bd35a361e493e928f016260326a5cd7f6 100644 (file)
@@ -249,13 +249,13 @@ static inline unsigned char fat_checksum(const __u8 *name)
        return s;
 }
 
-static inline sector_t fat_clus_to_blknr(struct msdos_sb_info *sbi, int clus)
+static inline sector_t fat_clus_to_blknr(const struct msdos_sb_info *sbi, int clus)
 {
        return ((sector_t)clus - FAT_START_ENT) * sbi->sec_per_clus
                + sbi->data_start;
 }
 
-static inline void fat_get_blknr_offset(struct msdos_sb_info *sbi,
+static inline void fat_get_blknr_offset(const struct msdos_sb_info *sbi,
                                loff_t i_pos, sector_t *blknr, int *offset)
 {
        *blknr = i_pos >> sbi->dir_per_block_bits;
index 4eeed9dca5494033b154d7b29f16f3197535bcf1..9583ce66dca3cdc1f783577c35bbd7676cb9bf2f 100644 (file)
@@ -22,7 +22,7 @@ static void fat_checksum_test(struct kunit *test)
 
 static void fat_clus_to_blknr_test(struct kunit *test)
 {
-       struct msdos_sb_info sbi = {
+       static const struct msdos_sb_info sbi = {
                .sec_per_clus = 4,
                .data_start = 100,
        };
@@ -34,7 +34,7 @@ static void fat_clus_to_blknr_test(struct kunit *test)
 
 static void fat_get_blknr_offset_test(struct kunit *test)
 {
-       struct msdos_sb_info sbi = {
+       static const struct msdos_sb_info sbi = {
                .dir_per_block = 16,
                .dir_per_block_bits = 4,
        };