public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Nicolas Ferre <nicolas.ferre@atmel•com>
To: Florian Fainelli <f.fainelli@gmail•com>, <netdev@vger•kernel.org>,
	Alexandre Belloni <alexandre.belloni@free-electrons•com>
Cc: <davem@davemloft•net>
Subject: Re: [PATCH net] net: macb: Probe MDIO bus before registering netdev
Date: Tue, 3 May 2016 10:33:05 +0200	[thread overview]
Message-ID: <57286241.9050405@atmel.com> (raw)
In-Reply-To: <1462239525-22723-1-git-send-email-f.fainelli@gmail.com>

Le 03/05/2016 03:38, Florian Fainelli a écrit :
> The current sequence makes us register for a network device prior to
> registering and probing the MDIO bus which could lead to some unwanted
> consequences, like a thread of execution calling into ndo_open before
> register_netdev() returns, while the MDIO bus is not ready yet.
> 
> Rework the sequence to register for the MDIO bus, and therefore attach
> to a PHY prior to calling register_netdev(), which implies reworking the
> error path a bit.
> 
> Signed-off-by: Florian Fainelli <f.fainelli@gmail•com>

Thanks a lot Florian for this follow-up and the advices you had given to
Alexandre during the debug session when you spotted this problem.

Acked-by: Nicolas Ferre <nicolas.ferre@atmel•com>

> ---
> Tracking down the exact commit which started doing that was a little
> difficult, so I can't really provide a proper Fixes tag yet that does
> not reference 4-5 commits

Yes, indeed. Macb is moving quite a bit those days ;-)


Bye,


>  drivers/net/ethernet/cadence/macb.c | 31 +++++++++++++++++++------------
>  1 file changed, 19 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c
> index 48a7d7dee846..e9b470a5ddd0 100644
> --- a/drivers/net/ethernet/cadence/macb.c
> +++ b/drivers/net/ethernet/cadence/macb.c
> @@ -441,7 +441,7 @@ static int macb_mii_init(struct macb *bp)
>  	snprintf(bp->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
>  		bp->pdev->name, bp->pdev->id);
>  	bp->mii_bus->priv = bp;
> -	bp->mii_bus->parent = &bp->dev->dev;
> +	bp->mii_bus->parent = &bp->pdev->dev;
>  	pdata = dev_get_platdata(&bp->pdev->dev);
>  
>  	dev_set_drvdata(&bp->dev->dev, bp->mii_bus);
> @@ -3019,29 +3019,36 @@ static int macb_probe(struct platform_device *pdev)
>  	if (err)
>  		goto err_out_free_netdev;
>  
> +	err = macb_mii_init(bp);
> +	if (err)
> +		goto err_out_free_netdev;
> +
> +	phydev = bp->phy_dev;
> +
> +	netif_carrier_off(dev);
> +
>  	err = register_netdev(dev);
>  	if (err) {
>  		dev_err(&pdev->dev, "Cannot register net device, aborting.\n");
> -		goto err_out_unregister_netdev;
> +		goto err_out_unregister_mdio;
>  	}
>  
> -	err = macb_mii_init(bp);
> -	if (err)
> -		goto err_out_unregister_netdev;
> -
> -	netif_carrier_off(dev);
> +	phy_attached_info(phydev);
>  
>  	netdev_info(dev, "Cadence %s rev 0x%08x at 0x%08lx irq %d (%pM)\n",
>  		    macb_is_gem(bp) ? "GEM" : "MACB", macb_readl(bp, MID),
>  		    dev->base_addr, dev->irq, dev->dev_addr);
>  
> -	phydev = bp->phy_dev;
> -	phy_attached_info(phydev);
> -
>  	return 0;
>  
> -err_out_unregister_netdev:
> -	unregister_netdev(dev);
> +err_out_unregister_mdio:
> +	phy_disconnect(bp->phy_dev);
> +	mdiobus_unregister(bp->mii_bus);
> +	mdiobus_free(bp->mii_bus);
> +
> +	/* Shutdown the PHY if there is a GPIO reset */
> +	if (bp->reset_gpio)
> +		gpiod_set_value(bp->reset_gpio, 0);
>  
>  err_out_free_netdev:
>  	free_netdev(dev);
> 


-- 
Nicolas Ferre

  reply	other threads:[~2016-05-03  8:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-03  1:38 [PATCH net] net: macb: Probe MDIO bus before registering netdev Florian Fainelli
2016-05-03  8:33 ` Nicolas Ferre [this message]
2016-05-03 20:06 ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=57286241.9050405@atmel.com \
    --to=nicolas.ferre@atmel$(echo .)com \
    --cc=alexandre.belloni@free-electrons$(echo .)com \
    --cc=davem@davemloft$(echo .)net \
    --cc=f.fainelli@gmail$(echo .)com \
    --cc=netdev@vger$(echo .)kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox