* [PATCH] md: fix compiler warning: large integer implicitly truncated to unsigned type
@ 2013-12-02 19:12 Helge Deller
2013-12-03 13:47 ` [dm-devel] " Thadeu Lima de Souza Cascardo
0 siblings, 1 reply; 2+ messages in thread
From: Helge Deller @ 2013-12-02 19:12 UTC (permalink / raw)
To: dm-devel, linux-parisc
Compiling a 32bit kernel with CONFIG_LBDAF=3Dn gives this compiler warn=
ing:
/drivers/md/md.c: In function =E2=80=98super_90_load=E2=80=99:
/drivers/md/md.c:1068:3: warning: large integer implicitly truncated to=
unsigned type [-Woverflow]
=46ix it by casting the calculated value to a sector_t type.
Signed-off-by: Helge Deller <deller@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, st=
ruct md_rdev *refdev, int minor
* record this size)
*/
if (rdev->sectors >=3D (2ULL << 32) && sb->level >=3D 1)
- rdev->sectors =3D (2ULL << 32) - 2;
+ rdev->sectors =3D (sector_t) ((2ULL << 32) - 2);
=20
if (rdev->sectors < ((sector_t)sb->size) * 2 && sb->level >=3D 1)
/* "this cannot possibly happen" ... */
@@ -1356,7 +1356,7 @@ super_90_rdev_size_change(struct md_rdev *rdev, s=
ector_t num_sectors)
* 4TB =3D=3D 2^32 KB, or 2*2^32 sectors.
*/
if (num_sectors >=3D (2ULL << 32) && rdev->mddev->level >=3D 1)
- num_sectors =3D (2ULL << 32) - 2;
+ num_sectors =3D (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 majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [dm-devel] [PATCH] md: fix compiler warning: large integer implicitly truncated to unsigned type
2013-12-02 19:12 [PATCH] md: fix compiler warning: large integer implicitly truncated to unsigned type Helge Deller
@ 2013-12-03 13:47 ` Thadeu Lima de Souza Cascardo
0 siblings, 0 replies; 2+ messages in thread
From: Thadeu Lima de Souza Cascardo @ 2013-12-03 13:47 UTC (permalink / raw)
To: Helge Deller; +Cc: dm-devel, linux-parisc
On Mon, Dec 02, 2013 at 08:12:20PM +0100, Helge Deller wrote:
> Compiling a 32bit kernel with CONFIG_LBDAF=3Dn gives this compiler wa=
rning:
> /drivers/md/md.c: In function =E2=80=98super_90_load=E2=80=99:
> /drivers/md/md.c:1068:3: warning: large integer implicitly truncated =
to unsigned type [-Woverflow]
>=20
> Fix it by casting the calculated value to a sector_t type.
>=20
> Signed-off-by: Helge Deller <deller@gmx.de>
>=20
> 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 >=3D (2ULL << 32) && sb->level >=3D 1)
> - rdev->sectors =3D (2ULL << 32) - 2;
> + rdev->sectors =3D (sector_t) ((2ULL << 32) - 2);
> =20
> if (rdev->sectors < ((sector_t)sb->size) * 2 && sb->level >=3D 1)
> /* "this cannot possibly happen" ... */
> @@ -1356,7 +1356,7 @@ super_90_rdev_size_change(struct md_rdev *rdev,=
sector_t num_sectors)
> * 4TB =3D=3D 2^32 KB, or 2*2^32 sectors.
> */
> if (num_sectors >=3D (2ULL << 32) && rdev->mddev->level >=3D 1)
> - num_sectors =3D (2ULL << 32) - 2;
> + num_sectors =3D (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);
>=20
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 chang=
e
in the code in order to avoid the warning, or we should don't care abou=
t
them, since testing for num_sectors >=3D (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 majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-12-03 13:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-02 19:12 [PATCH] md: fix compiler warning: large integer implicitly truncated to unsigned type Helge Deller
2013-12-03 13:47 ` [dm-devel] " Thadeu Lima de Souza Cascardo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).