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

md: avoid warning for 32-bit sector_t

When CONFIG_LBDAF is not set, sector_t is only 32-bits wide, which
means we cannot have devices with more than 2TB, and the code that
is trying to handle compatibility support for large devices in
md version 0.90 is meaningless but also causes a compile-time warning:

drivers/md/md.c: In function 'super_90_load':
drivers/md/md.c:1029:19: warning: large integer implicitly truncated to unsigned type [-Woverflow]
drivers/md/md.c: In function 'super_90_rdev_size_change':
drivers/md/md.c:1323:17: warning: large integer implicitly truncated to unsigned type [-Woverflow]

This adds a check for CONFIG_LBDAF to avoid even getting into this
code path, and also adds an explicit cast to let the compiler know
it doesn't have to warn about the truncation.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: NeilBrown <neilb@suse.com>

authored by

Arnd Bergmann and committed by
NeilBrown
3312c951 ad66d445

+6 -4
+6 -4
drivers/md/md.c
··· 1026 1026 * (not needed for Linear and RAID0 as metadata doesn't 1027 1027 * record this size) 1028 1028 */ 1029 - if (rdev->sectors >= (2ULL << 32) && sb->level >= 1) 1030 - rdev->sectors = (2ULL << 32) - 2; 1029 + if (IS_ENABLED(CONFIG_LBDAF) && (u64)rdev->sectors >= (2ULL << 32) && 1030 + sb->level >= 1) 1031 + rdev->sectors = (sector_t)(2ULL << 32) - 2; 1031 1032 1032 1033 if (rdev->sectors < ((sector_t)sb->size) * 2 && sb->level >= 1) 1033 1034 /* "this cannot possibly happen" ... */ ··· 1321 1320 /* Limit to 4TB as metadata cannot record more than that. 1322 1321 * 4TB == 2^32 KB, or 2*2^32 sectors. 1323 1322 */ 1324 - if (num_sectors >= (2ULL << 32) && rdev->mddev->level >= 1) 1325 - num_sectors = (2ULL << 32) - 2; 1323 + if (IS_ENABLED(CONFIG_LBDAF) && (u64)num_sectors >= (2ULL << 32) && 1324 + rdev->mddev->level >= 1) 1325 + num_sectors = (sector_t)(2ULL << 32) - 2; 1326 1326 md_super_write(rdev->mddev, rdev, rdev->sb_start, rdev->sb_size, 1327 1327 rdev->sb_page); 1328 1328 md_super_wait(rdev->mddev);