Skip to contentSkip to conversation

md: fix compiler warning: large integer implicitly truncated to unsigned type

PATCH In review Helge Deller 2 participants 2 messages Dec 2, 2013 – Dec 3, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 md: fix compiler warning: large integer implicitly truncated to unsigned type

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.

drivers/md/md.c +2 -2
index e60cebf..b56f1c7 100644
@@ -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);

--
To unsubscribe from this list: send the line "unsubscribe linux-parisc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#1 lore raw
Quoted 23 lines · Helge Deller

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.

drivers/md/md.c +1 -1
index e60cebf..b56f1c7 100644
@@ -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" ... */

drivers/md/md.c super_90_rdev_size_change(struct md_rdev *rdev, sector_t num_sectors) · line 1362

Quoted 8 lines
drivers/md/md.c +1 -1
@@ -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.

--
To unsubscribe from this list: send the line "unsubscribe linux-parisc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html