net: stmmac: mdio: use netdev_priv() directly
Subsystems (4)
PATCH 1/1 net: stmmac: mdio: use netdev_priv() directly
netdev_priv() is an inline function, taking a struct net_device pointer. When passing in the MII bus->priv, which is a void pointer, there is no need to go via a local ndev variable to type it first.
Thus, instead of:
struct net_device *ndev = bus->priv; struct stmmac_priv *priv; ... priv = netdev_priv(ndev);
we can simply do:
struct stmmac_priv *priv = netdev_priv(bus->priv);
which simplifies the code.
--- .../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 38 +++++-------------- 1 file changed, 10 insertions(+), 28 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +10 -28
@@ -131,12 +131,9 @@ static int stmmac_xgmac2_mdio_read(struct stmmac_priv *priv, u32 addr,static int stmmac_xgmac2_mdio_read_c22 (struct mii_bus *bus,int phyaddr,int phyreg) { -struct net_device *ndev = bus->priv; -struct stmmac_priv *priv; +struct stmmac_priv *priv =netdev_priv (bus->priv);u32 addr; - priv =netdev_priv (ndev); -/* Until ver 2.20 XGMAC does not support C22 addr >= 4 */ if (priv->synopsys_id <DWXGMAC_CORE_2_20 && phyaddr >MII_XGMAC_MAX_C22ADDR )
@@ -150,12 +147,9 @@ static int stmmac_xgmac2_mdio_read_c22(struct mii_bus *bus, int phyaddr,static int stmmac_xgmac2_mdio_read_c45 (struct mii_bus *bus,int phyaddr,int devad,int phyreg) { -struct net_device *ndev = bus->priv; -struct stmmac_priv *priv; +struct stmmac_priv *priv =netdev_priv (bus->priv);u32 addr; - priv =netdev_priv (ndev); -stmmac_xgmac2_c45_format (priv, phyaddr, devad, phyreg, &addr);return stmmac_xgmac2_mdio_read (priv, addr,MII_XGMAC_BUSY );
@@ -209,12 +203,9 @@ static int stmmac_xgmac2_mdio_write(struct stmmac_priv *priv, u32 addr,static int stmmac_xgmac2_mdio_write_c22 (struct mii_bus *bus,int phyaddr,int phyreg,u16 phydata) { -struct net_device *ndev = bus->priv; -struct stmmac_priv *priv; +struct stmmac_priv *priv =netdev_priv (bus->priv);u32 addr; - priv =netdev_priv (ndev); -/* Until ver 2.20 XGMAC does not support C22 addr >= 4 */ if (priv->synopsys_id <DWXGMAC_CORE_2_20 && phyaddr >MII_XGMAC_MAX_C22ADDR )
@@ -229,12 +220,9 @@ static int stmmac_xgmac2_mdio_write_c22(struct mii_bus *bus, int phyaddr,static int stmmac_xgmac2_mdio_write_c45 (struct mii_bus *bus,int phyaddr,int devad,int phyreg,u16 phydata) { -struct net_device *ndev = bus->priv; -struct stmmac_priv *priv; +struct stmmac_priv *priv =netdev_priv (bus->priv);u32 addr; - priv =netdev_priv (ndev); -stmmac_xgmac2_c45_format (priv, phyaddr, devad, phyreg, &addr); return stmmac_xgmac2_mdio_write(priv, addr, MII_XGMAC_BUSY,
@@ -274,8 +262,7 @@ static int stmmac_mdio_read(struct stmmac_priv *priv, int data, u32 value)*/ static int stmmac_mdio_read_c22 (struct mii_bus *bus,int phyaddr,int phyreg) { -struct net_device *ndev = bus->priv; -struct stmmac_priv *priv =netdev_priv (ndev); +struct stmmac_priv *priv =netdev_priv (bus->priv);u32 value =MII_BUSY ;int data =0 ;
@@ -312,8 +299,7 @@ static int stmmac_mdio_read_c22(struct mii_bus *bus, int phyaddr, int phyreg)static int stmmac_mdio_read_c45 (struct mii_bus *bus,int phyaddr,int devad,int phyreg) { -struct net_device *ndev = bus->priv; -struct stmmac_priv *priv =netdev_priv (ndev); +struct stmmac_priv *priv =netdev_priv (bus->priv);u32 value =MII_BUSY ;int data =0 ;
@@ -373,8 +359,7 @@ static int stmmac_mdio_write(struct stmmac_priv *priv, int data, u32 value)static int stmmac_mdio_write_c22 (struct mii_bus *bus,int phyaddr,int phyreg,u16 phydata) { -struct net_device *ndev = bus->priv; -struct stmmac_priv *priv =netdev_priv (ndev); +struct stmmac_priv *priv =netdev_priv (bus->priv);int ret, data = phydata;u32 value =MII_BUSY ;
@@ -412,8 +397,7 @@ static int stmmac_mdio_write_c22(struct mii_bus *bus, int phyaddr, int phyreg,static int stmmac_mdio_write_c45 (struct mii_bus *bus,int phyaddr,int devad,int phyreg,u16 phydata) { -struct net_device *ndev = bus->priv; -struct stmmac_priv *priv =netdev_priv (ndev); +struct stmmac_priv *priv =netdev_priv (bus->priv);int ret, data = phydata;u32 value =MII_BUSY ;
@@ -452,8 +436,7 @@ static int stmmac_mdio_write_c45(struct mii_bus *bus, int phyaddr,int stmmac_mdio_reset (struct mii_bus *bus) {#if IS_ENABLED (CONFIG_STMMAC_PLATFORM ) -struct net_device *ndev = bus->priv; -struct stmmac_priv *priv =netdev_priv (ndev); +struct stmmac_priv *priv =netdev_priv (bus->priv);unsigned int mii_address = priv->hw->mii.addr;#ifdef CONFIG_OF
@@ -497,12 +480,11 @@ int stmmac_mdio_reset(struct mii_bus *bus)int stmmac_pcs_setup (struct net_device *ndev) { +struct stmmac_priv *priv =netdev_priv (ndev);struct fwnode_handle *devnode, *pcsnode;struct dw_xpcs *xpcs =NULL ; -struct stmmac_priv *priv;int addr, ret; - priv =netdev_priv (ndev); devnode = priv->plat->port_node;if (priv->plat->pcs_init) {
Signature · 1 line
2.47.2
Quoted 11 lines · Russell King (Oracle)
netdev_priv()is an inline function, taking a structnet_devicepointer. When passing in the MIIbus->priv, which is a void pointer, there is no need to go via a local ndev variable to type it first.Thus, instead of:
struct net_device *ndev = bus->priv; struct stmmac_priv *priv; ... priv = netdev_priv(ndev);
Quoted 7 lines
we can simply do:
struct stmmac_priv *priv = netdev_priv(bus->priv);which simplifies the code.
Signed-off-by Russell King (Oracle) <[email protected]>
Thanks,
Sundeep
Quoted 131 lines
--- .../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 38 +++++-------------- 1 file changed, 10 insertions(+), 28 deletions(-)drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +10
-28@@ -131,12 +131,9 @@ static int stmmac_xgmac2_mdio_read(struct stmmac_priv *priv, u32 addr,static int stmmac_xgmac2_mdio_read_c22 (struct mii_bus *bus,int phyaddr,int phyreg) { -struct net_device *ndev = bus->priv; -struct stmmac_priv *priv; +struct stmmac_priv *priv =netdev_priv (bus->priv);u32 addr; - priv =netdev_priv (ndev); -/* Until ver 2.20 XGMAC does not support C22 addr >= 4 */ if (priv->synopsys_id <DWXGMAC_CORE_2_20 && phyaddr >MII_XGMAC_MAX_C22ADDR )@@ -150,12 +147,9 @@ static int stmmac_xgmac2_mdio_read_c22(struct mii_bus *bus, int phyaddr,static int stmmac_xgmac2_mdio_read_c45 (struct mii_bus *bus,int phyaddr,int devad,int phyreg) { -struct net_device *ndev = bus->priv; -struct stmmac_priv *priv; +struct stmmac_priv *priv =netdev_priv (bus->priv);u32 addr; - priv =netdev_priv (ndev); -stmmac_xgmac2_c45_format (priv, phyaddr, devad, phyreg, &addr);return stmmac_xgmac2_mdio_read (priv, addr,MII_XGMAC_BUSY );@@ -209,12 +203,9 @@ static int stmmac_xgmac2_mdio_write(struct stmmac_priv *priv, u32 addr,static int stmmac_xgmac2_mdio_write_c22 (struct mii_bus *bus,int phyaddr,int phyreg,u16 phydata) { -struct net_device *ndev = bus->priv; -struct stmmac_priv *priv; +struct stmmac_priv *priv =netdev_priv (bus->priv);u32 addr; - priv =netdev_priv (ndev); -/* Until ver 2.20 XGMAC does not support C22 addr >= 4 */ if (priv->synopsys_id <DWXGMAC_CORE_2_20 && phyaddr >MII_XGMAC_MAX_C22ADDR )@@ -229,12 +220,9 @@ static int stmmac_xgmac2_mdio_write_c22(struct mii_bus *bus, int phyaddr,static int stmmac_xgmac2_mdio_write_c45 (struct mii_bus *bus,int phyaddr,int devad,int phyreg,u16 phydata) { -struct net_device *ndev = bus->priv; -struct stmmac_priv *priv; +struct stmmac_priv *priv =netdev_priv (bus->priv);u32 addr; - priv =netdev_priv (ndev); -stmmac_xgmac2_c45_format (priv, phyaddr, devad, phyreg, &addr); return stmmac_xgmac2_mdio_write(priv, addr, MII_XGMAC_BUSY,@@ -274,8 +262,7 @@ static int stmmac_mdio_read(struct stmmac_priv *priv, int data, u32 value)*/ static int stmmac_mdio_read_c22 (struct mii_bus *bus,int phyaddr,int phyreg) { -struct net_device *ndev = bus->priv; -struct stmmac_priv *priv =netdev_priv (ndev); +struct stmmac_priv *priv =netdev_priv (bus->priv);u32 value =MII_BUSY ;int data =0 ;@@ -312,8 +299,7 @@ static int stmmac_mdio_read_c22(struct mii_bus *bus, int phyaddr, int phyreg)static int stmmac_mdio_read_c45 (struct mii_bus *bus,int phyaddr,int devad,int phyreg) { -struct net_device *ndev = bus->priv; -struct stmmac_priv *priv =netdev_priv (ndev); +struct stmmac_priv *priv =netdev_priv (bus->priv);u32 value =MII_BUSY ;int data =0 ;@@ -373,8 +359,7 @@ static int stmmac_mdio_write(struct stmmac_priv *priv, int data, u32 value)static int stmmac_mdio_write_c22 (struct mii_bus *bus,int phyaddr,int phyreg,u16 phydata) { -struct net_device *ndev = bus->priv; -struct stmmac_priv *priv =netdev_priv (ndev); +struct stmmac_priv *priv =netdev_priv (bus->priv);int ret, data = phydata;u32 value =MII_BUSY ;@@ -412,8 +397,7 @@ static int stmmac_mdio_write_c22(struct mii_bus *bus, int phyaddr, int phyreg,static int stmmac_mdio_write_c45 (struct mii_bus *bus,int phyaddr,int devad,int phyreg,u16 phydata) { -struct net_device *ndev = bus->priv; -struct stmmac_priv *priv =netdev_priv (ndev); +struct stmmac_priv *priv =netdev_priv (bus->priv);int ret, data = phydata;u32 value =MII_BUSY ;@@ -452,8 +436,7 @@ static int stmmac_mdio_write_c45(struct mii_bus *bus, int phyaddr,int stmmac_mdio_reset (struct mii_bus *bus) {#if IS_ENABLED (CONFIG_STMMAC_PLATFORM ) -struct net_device *ndev = bus->priv; -struct stmmac_priv *priv =netdev_priv (ndev); +struct stmmac_priv *priv =netdev_priv (bus->priv);unsigned int mii_address = priv->hw->mii.addr;#ifdef CONFIG_OF @@ -497,12 +480,11 @@ int stmmac_mdio_reset(struct mii_bus *bus)int stmmac_pcs_setup (struct net_device *ndev) { +struct stmmac_priv *priv =netdev_priv (ndev);struct fwnode_handle *devnode, *pcsnode;struct dw_xpcs *xpcs =NULL ; -struct stmmac_priv *priv;int addr, ret; - priv =netdev_priv (ndev); devnode = priv->plat->port_node;if (priv->plat->pcs_init) {Signature · 1 line
2.47.2
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 4 lines · On Wed, 27 Aug 2025 09:41:48 +0100 you wrote:
netdev_priv()is an inline function, taking a structnet_devicepointer. When passing in the MIIbus->priv, which is a void pointer, there is no need to go via a local ndev variable to type it first.
Quoted 8 lines
Thus, instead of:
struct net_device *ndev = bus->priv; struct stmmac_priv *priv; ... priv = netdev_priv(ndev);[...]
Here is the summary with links:
- [net-next] net: stmmac: mdio: use netdev_priv() directly
https://git.kernel.org/netdev/net-next/c/bafdd920a060
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html