Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1268666

Re: [PATCH v2] stmmac: avoid ipq806x constant overflow warning

From Geert Uytterhoeven <geert@linux-m68k.org>
Newsgroups linux.kernel
Subject Re: [PATCH v2] stmmac: avoid ipq806x constant overflow warning
Date 2015-11-13 08:40 +0100
Message-ID <quh7H-3re-9@gated-at.bofh.it> (permalink)
References <qu0Th-1x8-31@gated-at.bofh.it> <qu3R7-3nW-5@gated-at.bofh.it> <qu78m-5oc-17@gated-at.bofh.it> <qu7i2-5GE-17@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Thu, Nov 12, 2015 at 10:03 PM, Arnd Bergmann <arnd@arndb.de> wrote:
> Building dwmac-ipq806x on a 64-bit architecture produces a harmless
> warning from gcc:
>
> stmmac/dwmac-ipq806x.c: In function 'ipq806x_gmac_probe':
> include/linux/bitops.h:6:19: warning: overflow in implicit constant conversion [-Woverflow]
>   val = QSGMII_PHY_CDR_EN |
> stmmac/dwmac-ipq806x.c:333:8: note: in expansion of macro 'QSGMII_PHY_CDR_EN'
>  #define QSGMII_PHY_CDR_EN   BIT(0)
>  #define BIT(nr)   (1UL << (nr))
>
> This is a result of the type conversion rules in C, when we take the
> logical OR of multiple different types. In particular, we have
> and unsigned long
>
>         QSGMII_PHY_CDR_EN == BIT(0) == (1ul << 0) == 0x0000000000000001ul
>
> and a signed int
>
>         0xC << QSGMII_PHY_TX_DRV_AMP_OFFSET == 0xc0000000
>
> which together gives a signed long value
>
>         0xffffffffc0000001l
>
> and when this is passed into a function that takes an unsigned int type,
> gcc warns about the signed overflow and the loss of the upper 32-bits that
> are all ones.
>
> This patch adds 'ul' type modifiers to the literal numbers passed in
> here, so now the expression remains an 'unsigned long' with the upper
> bits all zero, and that avoids the signed overflow and the warning.

FWIW, the 64-bitness of BIT() on 64-bit platforms is also causing subtle
warnings in other places, e.g. when inverting them to create bit mask, cfr.
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=a9efeca613a8fe5281d7c91f5c8c9ea46f2312f6

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

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@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] stmmac: avoid ipq806x constant overflow warning Arnd Bergmann <arnd@arndb.de> - 2015-11-12 15:20 +0100
  Re: [PATCH] stmmac: avoid ipq806x constant overflow warning David Miller <davem@davemloft.net> - 2015-11-12 18:30 +0100
    Re: [PATCH] stmmac: avoid ipq806x constant overflow warning Arnd Bergmann <arnd@arndb.de> - 2015-11-12 22:00 +0100
      [PATCH v2] stmmac: avoid ipq806x constant overflow warning Arnd Bergmann <arnd@arndb.de> - 2015-11-12 22:10 +0100
        Re: [PATCH v2] stmmac: avoid ipq806x constant overflow warning David Miller <davem@davemloft.net> - 2015-11-12 22:20 +0100
        Re: [PATCH v2] stmmac: avoid ipq806x constant overflow warning Geert Uytterhoeven <geert@linux-m68k.org> - 2015-11-13 08:40 +0100
          Re: [PATCH v2] stmmac: avoid ipq806x constant overflow warning Joe Perches <joe@perches.com> - 2015-11-13 09:00 +0100
            Re: [PATCH v2] stmmac: avoid ipq806x constant overflow warning Geert Uytterhoeven <geert@linux-m68k.org> - 2015-11-13 09:10 +0100

csiph-web