[dm-devel] [PATCH] md: fix compiler warning: large integer implicitly truncated to unsigned type
Thadeu Lima de Souza Cascardo
cascardo at linux.vnet.ibm.com
Tue Dec 3 13:47:19 UTC 2013
On Mon, Dec 02, 2013 at 08:12:20PM +0100, Helge Deller wrote:
> Compiling a 32bit kernel with CONFIG_LBDAF=n gives this compiler warning:
> /drivers/md/md.c: In function ‘super_90_load’:
> /drivers/md/md.c:1068:3: warning: large integer implicitly truncated to unsigned type [-Woverflow]
>
> Fix it by casting the calculated value to a sector_t type.
>
> Signed-off-by: Helge Deller <deller at gmx.de>
>
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index e60cebf..b56f1c7 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -1065,7 +1065,7 @@ static int super_90_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor
> * record this size)
> */
> if (rdev->sectors >= (2ULL << 32) && sb->level >= 1)
> - rdev->sectors = (2ULL << 32) - 2;
> + rdev->sectors = (sector_t) ((2ULL << 32) - 2);
>
> if (rdev->sectors < ((sector_t)sb->size) * 2 && sb->level >= 1)
> /* "this cannot possibly happen" ... */
> @@ -1356,7 +1356,7 @@ super_90_rdev_size_change(struct md_rdev *rdev, sector_t num_sectors)
> * 4TB == 2^32 KB, or 2*2^32 sectors.
> */
> if (num_sectors >= (2ULL << 32) && rdev->mddev->level >= 1)
> - num_sectors = (2ULL << 32) - 2;
> + num_sectors = (sector_t) ((2ULL << 32) - 2);
> md_super_write(rdev->mddev, rdev, rdev->sb_start, rdev->sb_size,
> rdev->sb_page);
> md_super_wait(rdev->mddev);
>
It does overflow and get truncated on 32-bit systems without LABDF.
Casting is just hiding the problem! 32-bit systems without LABDF do not
support block devices larger than 2TB, and thus, should not worry about
larger than 4TB devices.
This code should either be ifdef'd to 64-bit or LABDF, or should test
for the size of sector_t. The second option would still need some change
in the code in order to avoid the warning, or we should don't care about
them, since testing for num_sectors >= (2ULL << 32) should always be
false.
Regards.
Cascardo.
More information about the dm-devel
mailing list