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

From: "Russell King (Oracle)" <[email-masked]>
Date: Fri, 2 Jun 2023 15:44:06 +0100

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) <[email-masked]>
> > ---
> >  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 <[email-masked]>
> Tested-by: Vladimir Oltean <[email-masked]>

Thanks.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!