netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Fainelli <f.fainelli@gmail.com>
To: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
Cc: netdev <netdev@vger.kernel.org>,
	David Miller <davem@davemloft.net>,
	Thomas Petazzoni <thomas.petazzoni@free-electrons.com>,
	Gregory Clement <gregory.clement@free-electrons.com>
Subject: Re: [PATCH v2 2/2] net: phy: Ensure the MDIO bus module is held
Date: Wed, 23 Jul 2014 14:46:46 -0700	[thread overview]
Message-ID: <CAGVrzcah6rRHhfxAXpRWg9f1YGNtry27TxUuLstuewnzF97s4A@mail.gmail.com> (raw)
In-Reply-To: <1406144852-7379-3-git-send-email-ezequiel.garcia@free-electrons.com>

2014-07-23 12:47 GMT-07:00 Ezequiel Garcia <ezequiel.garcia@free-electrons.com>:
> This commit adds proper module_{get,put} to prevent the MDIO bus module
> from being unloaded while the phydev is connected. By doing so, we fix
> a kernel panic produced when a MDIO driver is removed, but the phydev
> that relies on it is attached and running.
>
> Signed-off-by: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Tested-by: Florian Fainelli <f.fainelli@gmail.com>

Thanks Ezequiel!

> ---
>  drivers/net/phy/phy_device.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
>
> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index 4f4568e..1a5815c 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -575,6 +575,7 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
>                       u32 flags, phy_interface_t interface)
>  {
>         struct device *d = &phydev->dev;
> +       struct module *bus_module;
>         int err;
>
>         /* Assume that if there is no driver, that it doesn't
> @@ -599,6 +600,14 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
>                 return -EBUSY;
>         }
>
> +       /* Increment the bus module reference count */
> +       bus_module = phydev->bus->dev.driver ?
> +                    phydev->bus->dev.driver->owner : NULL;
> +       if (!try_module_get(bus_module)) {
> +               dev_err(&dev->dev, "failed to get the bus module\n");
> +               return -EIO;
> +       }
> +
>         phydev->attached_dev = dev;
>         dev->phydev = phydev;
>
> @@ -664,6 +673,10 @@ EXPORT_SYMBOL(phy_attach);
>  void phy_detach(struct phy_device *phydev)
>  {
>         int i;
> +
> +       if (phydev->bus->dev.driver)
> +               module_put(phydev->bus->dev.driver->owner);
> +
>         phydev->attached_dev->phydev = NULL;
>         phydev->attached_dev = NULL;
>         phy_suspend(phydev);
> --
> 2.0.1
>



-- 
Florian

  reply	other threads:[~2014-07-23 21:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-23 19:47 [PATCH v2 0/2] net: phy: Prevent an MDIO bus from being unloaded while in use Ezequiel Garcia
2014-07-23 19:47 ` [PATCH v2 1/2] net: phy: Set the driver when registering an MDIO bus device Ezequiel Garcia
2014-08-05  2:55   ` Fabio Estevam
2014-08-05  3:22     ` Shawn Guo
2014-08-05  4:01       ` Florian Fainelli
2014-08-05  4:41         ` Shawn Guo
2014-08-05 10:43           ` Ezequiel Garcia
2014-08-05 11:02             ` Fabio Estevam
2014-07-23 19:47 ` [PATCH v2 2/2] net: phy: Ensure the MDIO bus module is held Ezequiel Garcia
2014-07-23 21:46   ` Florian Fainelli [this message]
2014-07-25  1:10 ` [PATCH v2 0/2] net: phy: Prevent an MDIO bus from being unloaded while in use 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=CAGVrzcah6rRHhfxAXpRWg9f1YGNtry27TxUuLstuewnzF97s4A@mail.gmail.com \
    --to=f.fainelli@gmail.com \
    --cc=davem@davemloft.net \
    --cc=ezequiel.garcia@free-electrons.com \
    --cc=gregory.clement@free-electrons.com \
    --cc=netdev@vger.kernel.org \
    --cc=thomas.petazzoni@free-electrons.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
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;
as well as URLs for NNTP newsgroup(s).