diff mbox series

[net-next,1/3] net: dsa: sja1105: allow XPCS to handle mdiodev lifetime

Message ID E1q55IZ-00Bp4w-6V@rmk-PC.armlinux.org.uk (mailing list archive)
State Accepted
Commit 9607eaadba68732b76c744bd22635fb1da5a7622
Delegated to: Netdev Maintainers
Headers show
Series convert sja1105 xpcs creation and remove xpcs_create | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 21 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Russell King (Oracle) June 2, 2023, 1:58 p.m. UTC
Put the mdiodev after xpcs_create() so that the XPCS driver can manage
the lifetime of the mdiodev its using.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
 drivers/net/dsa/sja1105/sja1105_mdio.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Vladimir Oltean June 2, 2023, 2:30 p.m. UTC | #1
On Fri, Jun 02, 2023 at 02:58:35PM +0100, Russell King (Oracle) wrote:
> Put the mdiodev after xpcs_create() so that the XPCS driver can manage
> the lifetime of the mdiodev its using.

nitpick: "it's using"

> 
> Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
> ---
>  drivers/net/dsa/sja1105/sja1105_mdio.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/net/dsa/sja1105/sja1105_mdio.c b/drivers/net/dsa/sja1105/sja1105_mdio.c
> index 01f1cb719042..166fe747f70a 100644
> --- a/drivers/net/dsa/sja1105/sja1105_mdio.c
> +++ b/drivers/net/dsa/sja1105/sja1105_mdio.c
> @@ -417,6 +417,7 @@ static int sja1105_mdiobus_pcs_register(struct sja1105_private *priv)
>  		}
>  
>  		xpcs = xpcs_create(mdiodev, priv->phy_mode[port]);
> +		mdio_device_put(mdiodev);
>  		if (IS_ERR(xpcs)) {
>  			rc = PTR_ERR(xpcs);
>  			goto out_pcs_free;
> @@ -434,7 +435,6 @@ static int sja1105_mdiobus_pcs_register(struct sja1105_private *priv)
>  		if (!priv->xpcs[port])
>  			continue;
>  
> -		mdio_device_free(priv->xpcs[port]->mdiodev);
>  		xpcs_destroy(priv->xpcs[port]);
>  		priv->xpcs[port] = NULL;
>  	}
> @@ -457,7 +457,6 @@ static void sja1105_mdiobus_pcs_unregister(struct sja1105_private *priv)
>  		if (!priv->xpcs[port])
>  			continue;
>  
> -		mdio_device_free(priv->xpcs[port]->mdiodev);
>  		xpcs_destroy(priv->xpcs[port]);
>  		priv->xpcs[port] = NULL;
>  	}
> -- 
> 2.30.2
> 

So before this patch, sja1105 was using xpcs with an mdiodev refcount
of 2 (a transition phase after commit 9a5d500cffdb ("net: pcs: xpcs: add
xpcs_create_mdiodev()")), and now it's back to using it with a refcount
of 1? okay.

Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Tested-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Russell King (Oracle) June 2, 2023, 2:44 p.m. UTC | #2
On Fri, Jun 02, 2023 at 05:30:20PM +0300, Vladimir Oltean wrote:
> On Fri, Jun 02, 2023 at 02:58:35PM +0100, Russell King (Oracle) wrote:
> > Put the mdiodev after xpcs_create() so that the XPCS driver can manage
> > the lifetime of the mdiodev its using.
> 
> nitpick: "it's using"
> 
> > 
> > Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
> > ---
> >  drivers/net/dsa/sja1105/sja1105_mdio.c | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> > 
> > diff --git a/drivers/net/dsa/sja1105/sja1105_mdio.c b/drivers/net/dsa/sja1105/sja1105_mdio.c
> > index 01f1cb719042..166fe747f70a 100644
> > --- a/drivers/net/dsa/sja1105/sja1105_mdio.c
> > +++ b/drivers/net/dsa/sja1105/sja1105_mdio.c
> > @@ -417,6 +417,7 @@ static int sja1105_mdiobus_pcs_register(struct sja1105_private *priv)
> >  		}
> >  
> >  		xpcs = xpcs_create(mdiodev, priv->phy_mode[port]);
> > +		mdio_device_put(mdiodev);
> >  		if (IS_ERR(xpcs)) {
> >  			rc = PTR_ERR(xpcs);
> >  			goto out_pcs_free;
> > @@ -434,7 +435,6 @@ static int sja1105_mdiobus_pcs_register(struct sja1105_private *priv)
> >  		if (!priv->xpcs[port])
> >  			continue;
> >  
> > -		mdio_device_free(priv->xpcs[port]->mdiodev);
> >  		xpcs_destroy(priv->xpcs[port]);
> >  		priv->xpcs[port] = NULL;
> >  	}
> > @@ -457,7 +457,6 @@ static void sja1105_mdiobus_pcs_unregister(struct sja1105_private *priv)
> >  		if (!priv->xpcs[port])
> >  			continue;
> >  
> > -		mdio_device_free(priv->xpcs[port]->mdiodev);
> >  		xpcs_destroy(priv->xpcs[port]);
> >  		priv->xpcs[port] = NULL;
> >  	}
> > -- 
> > 2.30.2
> > 
> 
> So before this patch, sja1105 was using xpcs with an mdiodev refcount
> of 2 (a transition phase after commit 9a5d500cffdb ("net: pcs: xpcs: add
> xpcs_create_mdiodev()")), and now it's back to using it with a refcount
> of 1? okay.

Absolutely correct, but the key thing is the owners of the refcount(s)
on the object have changed.

> Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
> Tested-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Thanks.
diff mbox series

Patch

diff --git a/drivers/net/dsa/sja1105/sja1105_mdio.c b/drivers/net/dsa/sja1105/sja1105_mdio.c
index 01f1cb719042..166fe747f70a 100644
--- a/drivers/net/dsa/sja1105/sja1105_mdio.c
+++ b/drivers/net/dsa/sja1105/sja1105_mdio.c
@@ -417,6 +417,7 @@  static int sja1105_mdiobus_pcs_register(struct sja1105_private *priv)
 		}
 
 		xpcs = xpcs_create(mdiodev, priv->phy_mode[port]);
+		mdio_device_put(mdiodev);
 		if (IS_ERR(xpcs)) {
 			rc = PTR_ERR(xpcs);
 			goto out_pcs_free;
@@ -434,7 +435,6 @@  static int sja1105_mdiobus_pcs_register(struct sja1105_private *priv)
 		if (!priv->xpcs[port])
 			continue;
 
-		mdio_device_free(priv->xpcs[port]->mdiodev);
 		xpcs_destroy(priv->xpcs[port]);
 		priv->xpcs[port] = NULL;
 	}
@@ -457,7 +457,6 @@  static void sja1105_mdiobus_pcs_unregister(struct sja1105_private *priv)
 		if (!priv->xpcs[port])
 			continue;
 
-		mdio_device_free(priv->xpcs[port]->mdiodev);
 		xpcs_destroy(priv->xpcs[port]);
 		priv->xpcs[port] = NULL;
 	}