netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/2] phylib: add module owner to the mii_bus structure
@ 2007-12-21 13:57 Ionut Nicu
  2007-12-21 20:55 ` Medve Emilian
  2007-12-21 23:37 ` Stephen Hemminger
  0 siblings, 2 replies; 6+ messages in thread
From: Ionut Nicu @ 2007-12-21 13:57 UTC (permalink / raw)
  To: netdev; +Cc: Ionut Nicu

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);
+
 	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);
-- 
1.5.4.rc0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* RE: [PATCH 2/2] phylib: add module owner to the mii_bus structure
  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
  1 sibling, 0 replies; 6+ messages in thread
From: Medve Emilian @ 2007-12-21 20:55 UTC (permalink / raw)
  To: Nicu Ioan Petru, netdev

Tested-by: Emil Medve <Emilian.Medve@Freescale.com>


> -----Original Message-----
> From: netdev-owner@vger.kernel.org 
> [mailto:netdev-owner@vger.kernel.org] On Behalf Of Nicu Ioan Petru
> Sent: Friday, December 21, 2007 7:58 AM
> To: netdev@vger.kernel.org
> Cc: Nicu Ioan Petru
> Subject: [PATCH 2/2] phylib: add module owner to the mii_bus structure
> 
> 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);
> +
>  	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);
> -- 
> 1.5.4.rc0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] phylib: add module owner to the mii_bus structure
  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
       [not found]   ` <785b16e8da057c6efb259494258bb30314ccac4c.1198861866.git.ionut.nicu@freescale.com>
  1 sibling, 1 reply; 6+ messages in thread
From: Stephen Hemminger @ 2007-12-21 23:37 UTC (permalink / raw)
  To: netdev

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>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH][v2] phylib: add module owner to the mii_bus structure
       [not found]   ` <785b16e8da057c6efb259494258bb30314ccac4c.1198861866.git.ionut.nicu@freescale.com>
@ 2007-12-28 17:31     ` Ionut Nicu
  2008-01-14 18:56       ` Andy Fleming
  0 siblings, 1 reply; 6+ messages in thread
From: Ionut Nicu @ 2007-12-28 17:31 UTC (permalink / raw)
  To: netdev; +Cc: shemminger, Ionut Nicu

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>
Tested-by: Emil Medve <Emilian.Medve@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..ca617ec 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -171,6 +171,10 @@ struct phy_device * phy_connect(struct net_device *dev, const char *phy_id,
 	if (IS_ERR(phydev))
 		return phydev;
 
+	/* Increment the usage count of the mii bus owner */
+	if (!try_module_get(phydev->bus->owner))
+		return ERR_PTR(-EFAULT);
+
 	phy_prepare_link(phydev, handler);
 
 	phy_start_machine(phydev, NULL);
@@ -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);
-- 
1.5.4.rc1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH][v2] phylib: add module owner to the mii_bus structure
  2007-12-28 17:31     ` [PATCH][v2] " Ionut Nicu
@ 2008-01-14 18:56       ` Andy Fleming
  2008-01-21 12:13         ` Nicu Ioan Petru
  0 siblings, 1 reply; 6+ messages in thread
From: Andy Fleming @ 2008-01-14 18:56 UTC (permalink / raw)
  To: Ionut Nicu; +Cc: netdev, shemminger


On Dec 28, 2007, at 11:31, Ionut Nicu 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>
> Tested-by: Emil Medve <Emilian.Medve@Freescale.com>
> ---
>  drivers/net/phy/phy_device.c |    9 ++++++++-
>  drivers/net/ucc_geth_mii.c   |    3 +++


> 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",


Any reason you didn't update the other drivers?

 > git grep mdiobus_register drivers/net/          // duplicates and  
mdio_bus.c edited out
drivers/net/au1000_eth.c:       mdiobus_register(&aup->mii_bus);
drivers/net/bfin_mac.c: mdiobus_register(&lp->mii_bus);
drivers/net/cpmac.c:    res = mdiobus_register(&cpmac_mii);
drivers/net/fec_mpc52xx_phy.c:  err = mdiobus_register(bus);
drivers/net/fs_enet/mii-bitbang.c:      ret = mdiobus_register(new_bus);
drivers/net/fs_enet/mii-fec.c:  ret = mdiobus_register(new_bus);
drivers/net/gianfar_mii.c:      err = mdiobus_register(new_bus);
drivers/net/macb.c:     if (mdiobus_register(&bp->mii_bus))
drivers/net/sb1250-mac.c:       err = mdiobus_register(&sc->mii_bus);
drivers/net/ucc_geth_mii.c:     err = mdiobus_register(new_bus);

I'm guessing this was only tested on the UEC, because unless I  
misunderstand the code, any other driver would now crash when you try  
to get the owner.

Andy

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH][v2] phylib: add module owner to the mii_bus structure
  2008-01-14 18:56       ` Andy Fleming
@ 2008-01-21 12:13         ` Nicu Ioan Petru
  0 siblings, 0 replies; 6+ messages in thread
From: Nicu Ioan Petru @ 2008-01-21 12:13 UTC (permalink / raw)
  To: Fleming Andy; +Cc: netdev, shemminger



> -----Original Message-----
> From: Fleming Andy 
> Sent: Monday, January 14, 2008 8:56 PM
> To: Nicu Ioan Petru
> Cc: netdev@vger.kernel.org; shemminger@linux-foundation.org
> Subject: Re: [PATCH][v2] phylib: add module owner to the 
> mii_bus structure
>
> Any reason you didn't update the other drivers?
> 
>  > git grep mdiobus_register drivers/net/          // duplicates and  
> mdio_bus.c edited out
> drivers/net/au1000_eth.c:       mdiobus_register(&aup->mii_bus);
> drivers/net/bfin_mac.c: mdiobus_register(&lp->mii_bus);
> drivers/net/cpmac.c:    res = mdiobus_register(&cpmac_mii);
> drivers/net/fec_mpc52xx_phy.c:  err = mdiobus_register(bus);
> drivers/net/fs_enet/mii-bitbang.c:      ret = 
> mdiobus_register(new_bus);
> drivers/net/fs_enet/mii-fec.c:  ret = mdiobus_register(new_bus);
> drivers/net/gianfar_mii.c:      err = mdiobus_register(new_bus);
> drivers/net/macb.c:     if (mdiobus_register(&bp->mii_bus))
> drivers/net/sb1250-mac.c:       err = mdiobus_register(&sc->mii_bus);
> drivers/net/ucc_geth_mii.c:     err = mdiobus_register(new_bus);
> 
> I'm guessing this was only tested on the UEC, because unless 
> I misunderstand the code, any other driver would now crash 
> when you try to get the owner.
> 

That's not true. If you look closely at the implementation of
try_module_get(), you'll see it returns 1 when module is NULL. So my
change should make no difference for the other drivers.

If that's really a concern for you, I can update the other drivers as
well. How do you propose to do this? Resubmit this patch or send a new
one?

Ionut.
 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-01-21 12:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
     [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

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).