netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Alexander Lobakin <alobakin@pm.me>
Cc: "David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Russell King <linux@armlinux.org.uk>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next] mdio, phy: fix -Wshadow warnings triggered by nested container_of()
Date: Tue, 19 Jan 2021 16:21:35 +0100	[thread overview]
Message-ID: <YAb4/7Nb1qaGiS0f@lunn.ch> (raw)
In-Reply-To: <20210116161246.67075-1-alobakin@pm.me>

On Sat, Jan 16, 2021 at 04:13:22PM +0000, Alexander Lobakin wrote:
> container_of() macro hides a local variable '__mptr' inside. This
> becomes a problem when several container_of() are nested in each
> other within single line or plain macros.
> As C preprocessor doesn't support generating random variable names,
> the sole solution is to avoid defining macros that consist only of
> container_of() calls, or they will self-shadow '__mptr' each time:
> 
> In file included from ./include/linux/bitmap.h:10,
>                  from drivers/net/phy/phy_device.c:12:
> drivers/net/phy/phy_device.c: In function ‘phy_device_release’:
> ./include/linux/kernel.h:693:8: warning: declaration of ‘__mptr’ shadows a previous local [-Wshadow]
>   693 |  void *__mptr = (void *)(ptr);     \
>       |        ^~~~~~
> ./include/linux/phy.h:647:26: note: in expansion of macro ‘container_of’
>   647 | #define to_phy_device(d) container_of(to_mdio_device(d), \
>       |                          ^~~~~~~~~~~~
> ./include/linux/mdio.h:52:27: note: in expansion of macro ‘container_of’
>    52 | #define to_mdio_device(d) container_of(d, struct mdio_device, dev)
>       |                           ^~~~~~~~~~~~
> ./include/linux/phy.h:647:39: note: in expansion of macro ‘to_mdio_device’
>   647 | #define to_phy_device(d) container_of(to_mdio_device(d), \
>       |                                       ^~~~~~~~~~~~~~
> drivers/net/phy/phy_device.c:217:8: note: in expansion of macro ‘to_phy_device’
>   217 |  kfree(to_phy_device(dev));
>       |        ^~~~~~~~~~~~~
> ./include/linux/kernel.h:693:8: note: shadowed declaration is here
>   693 |  void *__mptr = (void *)(ptr);     \
>       |        ^~~~~~
> ./include/linux/phy.h:647:26: note: in expansion of macro ‘container_of’
>   647 | #define to_phy_device(d) container_of(to_mdio_device(d), \
>       |                          ^~~~~~~~~~~~
> drivers/net/phy/phy_device.c:217:8: note: in expansion of macro ‘to_phy_device’
>   217 |  kfree(to_phy_device(dev));
>       |        ^~~~~~~~~~~~~
> 
> As they are declared in header files, these warnings are highly
> repetitive and very annoying (along with the one from linux/pci.h).
> 
> Convert the related macros from linux/{mdio,phy}.h to static inlines
> to avoid self-shadowing and potentially improve bug-catching.
> No functional changes implied.
> 
> Signed-off-by: Alexander Lobakin <alobakin@pm.me>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

  reply	other threads:[~2021-01-19 15:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-16 16:13 [PATCH net-next] mdio, phy: fix -Wshadow warnings triggered by nested container_of() Alexander Lobakin
2021-01-19 15:21 ` Andrew Lunn [this message]
2021-01-19 19:48   ` Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YAb4/7Nb1qaGiS0f@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=alobakin@pm.me \
    --cc=davem@davemloft.net \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).