netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: Arnd Bergmann <arnd@kernel.org>
Cc: Andrew Lunn <andrew@lunn.ch>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Florian Fainelli <f.fainelli@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Arnd Bergmann <arnd@arndb.de>,
	Russell King <linux@armlinux.org.uk>,
	Ioana Ciornei <ioana.ciornei@nxp.com>,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mdio: use inline functions for to_mdio_device() etc
Date: Tue, 27 Oct 2020 18:16:13 -0700	[thread overview]
Message-ID: <20201027181613.03f3f67a@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> (raw)
In-Reply-To: <20201026165113.3723159-1-arnd@kernel.org>

On Mon, 26 Oct 2020 17:51:09 +0100 Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> Nesting container_of() causes warnings with W=2, and doing this
> in a header means we see a lot of them, like:
> 
> In file included from drivers/net/mdio/of_mdio.c:11:
> drivers/net/mdio/of_mdio.c: In function 'of_phy_find_device':
> include/linux/kernel.h:852:8: warning: declaration of '__mptr' shadows a previous local [-Wshadow]
>   852 |  void *__mptr = (void *)(ptr);     \
>       |        ^~~~~~
> include/linux/phy.h:655:26: note: in expansion of macro 'container_of'
>   655 | #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:655:39: note: in expansion of macro 'to_mdio_device'
>   655 | #define to_phy_device(d) container_of(to_mdio_device(d), \
>       |                                       ^~~~~~~~~~~~~~
> drivers/net/mdio/of_mdio.c:379:10: note: in expansion of macro 'to_phy_device'
>   379 |   return to_phy_device(&mdiodev->dev);
>       |          ^~~~~~~~~~~~~
> include/linux/kernel.h:852:8: note: shadowed declaration is here
>   852 |  void *__mptr = (void *)(ptr);     \
>       |        ^~~~~~
> include/linux/phy.h:655:26: note: in expansion of macro 'container_of'
>   655 | #define to_phy_device(d) container_of(to_mdio_device(d), \
>       |                          ^~~~~~~~~~~~
> drivers/net/mdio/of_mdio.c:379:10: note: in expansion of macro 'to_phy_device'
>   379 |   return to_phy_device(&mdiodev->dev);
>       |          ^~~~~~~~~~~~~
> 
> Redefine the macros in linux/mdio.h as inline functions to avoid this
> problem.
> 
> Fixes: a9049e0c513c ("mdio: Add support for mdio drivers.")

I feel like this is slightly onerous, please drop the tag. 

Harmless W=2 warnings hardly call for getting this into the cogs of
the stable machinery.

> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  include/linux/mdio.h | 20 +++++++++++++++-----
>  1 file changed, 15 insertions(+), 5 deletions(-)
> 
> diff --git a/include/linux/mdio.h b/include/linux/mdio.h
> index dbd69b3d170b..7c059cb8e069 100644
> --- a/include/linux/mdio.h
> +++ b/include/linux/mdio.h
> @@ -49,7 +49,10 @@ struct mdio_device {
>  	unsigned int reset_assert_delay;
>  	unsigned int reset_deassert_delay;
>  };
> -#define to_mdio_device(d) container_of(d, struct mdio_device, dev)

empty line

> +static inline struct mdio_device *to_mdio_device(struct device *dev)
> +{
> +	return container_of(dev, struct mdio_device, dev);
> +}
>  
>  /* struct mdio_driver_common: Common to all MDIO drivers */
>  struct mdio_driver_common {
> @@ -57,8 +60,11 @@ struct mdio_driver_common {
>  	int flags;
>  };
>  #define MDIO_DEVICE_FLAG_PHY		1
> -#define to_mdio_common_driver(d) \
> -	container_of(d, struct mdio_driver_common, driver)

and here

> +static inline struct mdio_driver_common *
> +to_mdio_common_driver(struct device_driver *drv)
> +{
> +	return container_of(drv, struct mdio_driver_common, driver);
> +}
>  
>  /* struct mdio_driver: Generic MDIO driver */
>  struct mdio_driver {
> @@ -73,8 +79,12 @@ struct mdio_driver {
>  	/* Clears up any memory if needed */
>  	void (*remove)(struct mdio_device *mdiodev);
>  };
> -#define to_mdio_driver(d)						\
> -	container_of(to_mdio_common_driver(d), struct mdio_driver, mdiodrv)
> +
> +static inline struct mdio_driver *to_mdio_driver(struct device_driver *drv)
> +{
> +	struct mdio_driver_common *common = to_mdio_common_driver(drv);

and here

Otherwise we're trading W=2 warnings for checkpatch warnings :)

Thanks!

> +	return container_of(common, struct mdio_driver, mdiodrv);
> +}
>  
>  /* device driver data */
>  static inline void mdiodev_set_drvdata(struct mdio_device *mdio, void *data)


  parent reply	other threads:[~2020-10-29  0:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-26 16:51 [PATCH] mdio: use inline functions for to_mdio_device() etc Arnd Bergmann
2020-10-26 19:20 ` Andrew Lunn
2020-10-28  1:16 ` Jakub Kicinski [this message]
2020-10-28 15:34   ` Arnd Bergmann

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=20201027181613.03f3f67a@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com \
    --to=kuba@kernel.org \
    --cc=andrew@lunn.ch \
    --cc=arnd@arndb.de \
    --cc=arnd@kernel.org \
    --cc=bgolaszewski@baylibre.com \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=hkallweit1@gmail.com \
    --cc=ioana.ciornei@nxp.com \
    --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).