From: Stephen Hemminger <shemminger@linux-foundation.org>
To: netdev@vger.kernel.org
Subject: Re: [PATCH 2/2] phylib: add module owner to the mii_bus structure
Date: Fri, 21 Dec 2007 15:37:13 -0800 [thread overview]
Message-ID: <20071221153713.641f010e@deepthought> (raw)
In-Reply-To: <1198245451-13929-1-git-send-email-ionut.nicu@freescale.com>
On Fri, 21 Dec 2007 15:57:31 +0200
Ionut Nicu <ionut.nicu@freescale.com> wrote:
> Prevent unloading mii bus driver module when other modules have references to some
> phydevs on that bus. Added a new member (module owner) to struct mii_bus and added
> code to increment the mii bus owner module usage count on phy_connect and decrement
> it on phy_disconnect
>
> Set the module owner in the ucc_geth_mdio driver.
>
> Signed-off-by: Ionut Nicu <ionut.nicu@freescale.com>
> ---
> drivers/net/phy/phy_device.c | 9 ++++++++-
> drivers/net/ucc_geth_mii.c | 3 +++
> include/linux/phy.h | 4 ++++
> 3 files changed, 15 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index 5b9e175..7dc5480 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -178,6 +178,10 @@ struct phy_device * phy_connect(struct net_device *dev, const char *phy_id,
> if (phydev->irq > 0)
> phy_start_interrupts(phydev);
>
> + /* Increment the usage count of the mii bus owner */
> + if (!try_module_get(phydev->bus->owner))
> + return ERR_PTR(-EFAULT);
Shouldn't you get a handle before the first usage (start_interrupts)?
> +
> return phydev;
> }
> EXPORT_SYMBOL(phy_connect);
> @@ -192,9 +196,12 @@ void phy_disconnect(struct phy_device *phydev)
> phy_stop_interrupts(phydev);
>
> phy_stop_machine(phydev);
> -
> +
> phydev->adjust_link = NULL;
>
> + /* Decrement the reference count for the mii bus owner */
> + module_put(phydev->bus->owner);
> +
> phy_detach(phydev);
> }
> EXPORT_SYMBOL(phy_disconnect);
> diff --git a/drivers/net/ucc_geth_mii.c b/drivers/net/ucc_geth_mii.c
> index a3af4ea..84c7295 100644
> --- a/drivers/net/ucc_geth_mii.c
> +++ b/drivers/net/ucc_geth_mii.c
> @@ -217,6 +217,9 @@ static int uec_mdio_probe(struct of_device *ofdev, const struct of_device_id *ma
> }
> }
>
> + /* register ourselves as the owner of this bus */
> + new_bus->owner = THIS_MODULE;
> +
> err = mdiobus_register(new_bus);
> if (0 != err) {
> printk(KERN_ERR "%s: Cannot register as MDIO bus\n",
> diff --git a/include/linux/phy.h b/include/linux/phy.h
> index 554836e..04ff6a5 100644
> --- a/include/linux/phy.h
> +++ b/include/linux/phy.h
> @@ -82,6 +82,10 @@ struct mii_bus {
> const char *name;
> int id;
> void *priv;
> +
> + /* The module that owns this bus */
> + struct module *owner;
> +
> int (*read)(struct mii_bus *bus, int phy_id, int regnum);
> int (*write)(struct mii_bus *bus, int phy_id, int regnum, u16 val);
> int (*reset)(struct mii_bus *bus);
--
Stephen Hemminger <stephen.hemminger@vyatta.com>
next prev parent reply other threads:[~2007-12-22 0:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-21 13:57 [PATCH 2/2] phylib: add module owner to the mii_bus structure Ionut Nicu
2007-12-21 20:55 ` Medve Emilian
2007-12-21 23:37 ` Stephen Hemminger [this message]
[not found] ` <785b16e8da057c6efb259494258bb30314ccac4c.1198861866.git.ionut.nicu@freescale.com>
2007-12-28 17:31 ` [PATCH][v2] " Ionut Nicu
2008-01-14 18:56 ` Andy Fleming
2008-01-21 12:13 ` Nicu Ioan Petru
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=20071221153713.641f010e@deepthought \
--to=shemminger@linux-foundation.org \
--cc=netdev@vger.kernel.org \
/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).