net: phy: fix up const issues in to_mdio_device() and to_phy_device()
Subsystems (3)
PATCH 1/1 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.
--- include/linux/mdio.h | 5 +---- include/linux/phy.h | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-)
include/linux/mdio.h +1 -4
@@ -45,10 +45,7 @@ struct mdio_device {unsigned int reset_deassert_delay; }; -static inline struct mdio_device *to_mdio_device (const struct device *dev) -{ - return container_of(dev, struct mdio_device, dev); -} +#define to_mdio_device (__dev) container_of_const(__dev, struct mdio_device, dev)/* struct mdio_driver_common: Common to all MDIO drivers */ struct mdio_driver_common {
include/linux/phy.h +1 -4
@@ -744,10 +744,7 @@ struct phy_device {#define PHY_F_NO_IRQ 0x80000000#define PHY_F_RXC_ALWAYS_ON 0x40000000 -static inline struct phy_device *to_phy_device (const struct device *dev) -{ - return container_of(to_mdio_device(dev), struct phy_device, mdio); -} +#define to_phy_device (__dev) container_of_const(to_mdio_device(__dev), struct phy_device, mdio)/** * struct phy_tdr_config - Configuration of a TDR raw test
Signature · 1 line
2.49.0
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 5 lines · On Thu, 22 May 2025 13:21:47 +0200 you wrote:
Both
to_mdio_device()andto_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 usingcontainer_of_const()which was designed for this very problem.
Quoted 8 lines
Cc Alexander Lobakin <[email protected]>Cc Andrew Lunn <[email protected]>Cc Heiner Kallweit <[email protected]>Cc Russell King <[email protected]>Fixes 7eab14de73a8 ("mdio, phy: fix -Wshadow warnings triggered by nested container_of()")Signed-off-by Greg Kroah-Hartman <[email protected]>[...]
Here is the summary with links:
- [net-next] net: phy: fix up const issues in to_mdio_device() and to_phy_device()
https://git.kernel.org/netdev/net-next/c/e9cb929670a1
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html