Skip to content

Commit e9cb929

Browse files
gregkhkuba-moo
authored andcommitted
net: phy: fix up const issues in to_mdio_device() and to_phy_device()
Both to_mdio_device() and to_phy_device() "throw away" the const pointer attribute passed to them and return a non-const pointer, which generally is not a good thing overall. Fix this up by using container_of_const() which was designed for this very problem. Cc: Alexander Lobakin <alobakin@pm.me> Cc: Andrew Lunn <andrew@lunn.ch> Cc: Heiner Kallweit <hkallweit1@gmail.com> Cc: Russell King <linux@armlinux.org.uk> Fixes: 7eab14d ("mdio, phy: fix -Wshadow warnings triggered by nested container_of()") Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Link: https://patch.msgid.link/2025052246-conduit-glory-8fc9@gregkh Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent cb575e5 commit e9cb929

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

include/linux/mdio.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ struct mdio_device {
4545
unsigned int reset_deassert_delay;
4646
};
4747

48-
static inline struct mdio_device *to_mdio_device(const struct device *dev)
49-
{
50-
return container_of(dev, struct mdio_device, dev);
51-
}
48+
#define to_mdio_device(__dev) container_of_const(__dev, struct mdio_device, dev)
5249

5350
/* struct mdio_driver_common: Common to all MDIO drivers */
5451
struct mdio_driver_common {

include/linux/phy.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -744,10 +744,7 @@ struct phy_device {
744744
#define PHY_F_NO_IRQ 0x80000000
745745
#define PHY_F_RXC_ALWAYS_ON 0x40000000
746746

747-
static inline struct phy_device *to_phy_device(const struct device *dev)
748-
{
749-
return container_of(to_mdio_device(dev), struct phy_device, mdio);
750-
}
747+
#define to_phy_device(__dev) container_of_const(to_mdio_device(__dev), struct phy_device, mdio)
751748

752749
/**
753750
* struct phy_tdr_config - Configuration of a TDR raw test

0 commit comments

Comments
 (0)