Re: [PATCH 13/13] DRBD: Fix comparison always false warning due tolong/long long compare

From: Geert Uytterhoeven
Date: Wed Oct 12 2011 - 09:35:49 EST


On Wed, Oct 12, 2011 at 14:27, Philipp Reisner
<philipp.reisner@xxxxxxxxxx> wrote:
> From: David Howells <dhowells@xxxxxxxxxx>
>
> Fix warnings of the following nature in the drbd header:
>
> In file included from drivers/block/drbd/drbd_bitmap.c:32:
> drivers/block/drbd/drbd_int.h: In function 'drbd_get_syncer_progress':
> drivers/block/drbd/drbd_int.h:2234: warning: comparison is always false due to limited range of data
>
> where mdev->rs_total (an unsigned long) is being compared to 1ULL << 32, which
> is always false on a 32-bit machine.

But on 32-bit, unsigned long is never larger than UINT_MAX neither, so
it doesn't
really change anything??

> Signed-off-by: David Howells <dhowells@xxxxxxxxxx>
> Signed-off-by: Lars Ellenberg <lars.ellenberg@xxxxxxxxxx>
>
> Signed-off-by: Philipp Reisner <philipp.reisner@xxxxxxxxxx>
> Signed-off-by: Lars Ellenberg <lars.ellenberg@xxxxxxxxxx>
> ---
> Âdrivers/block/drbd/drbd_int.h | Â Â2 +-
> Â1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
> index ece2e4a..de42c7c 100644
> --- a/drivers/block/drbd/drbd_int.h
> +++ b/drivers/block/drbd/drbd_int.h
> @@ -2071,7 +2071,7 @@ static inline void drbd_get_syncer_progress(struct drbd_conf *mdev,
> Â Â Â Â Â Â Â Â * Note: currently we don't support such large bitmaps on 32bit
> Â Â Â Â Â Â Â Â * arch anyways, but no harm done to be prepared for it here.
> Â Â Â Â Â Â Â Â */
> - Â Â Â Â Â Â Â unsigned int shift = mdev->rs_total >= (1ULL << 32) ? 16 : 10;
> + Â Â Â Â Â Â Â unsigned int shift = mdev->rs_total > UINT_MAX ? 16 : 10;
> Â Â Â Â Â Â Â Âunsigned long left = *bits_left >> shift;
> Â Â Â Â Â Â Â Âunsigned long total = 1UL + (mdev->rs_total >> shift);
> Â Â Â Â Â Â Â Âunsigned long tmp = 1000UL - left * 1000UL/total;

Gr{oetje,eeting}s,

            Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
             Â Â -- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/