All of lore.kernel.org
 help / color / mirror / Atom feed
From: Florian Fainelli <f.fainelli@gmail.com>
To: Andrew Lunn <andrew@lunn.ch>
Cc: netdev@vger.kernel.org, davem@davemloft.net,
	rmk+kernel@armlinux.org.uk, maowenan@huawei.com
Subject: Re: [PATCH net v2 1/3] net: phy: Fix PHY module checks
Date: Wed, 8 Feb 2017 09:55:49 -0800	[thread overview]
Message-ID: <a068e619-5288-7007-b172-cb5d4417b758@gmail.com> (raw)
In-Reply-To: <20170208165713.GD13281@lunn.ch>

On 02/08/2017 08:57 AM, Andrew Lunn wrote:
>> --- a/drivers/net/phy/phy_device.c
>> +++ b/drivers/net/phy/phy_device.c
>> @@ -920,7 +920,7 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
>>  		return -EIO;
>>  	}
>>  
>> -	if (!try_module_get(d->driver->owner)) {
>> +	if (d->driver && !try_module_get(d->driver->owner)) {
>>  		dev_err(&dev->dev, "failed to get the device driver module\n");
>>  		return -EIO;
>>  	}
>> @@ -943,7 +943,7 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
>>  			err = device_bind_driver(d);
>>  
>>  		if (err)
>> -			goto error;
>> +			goto error_put_device;
>>  	}
>>  
>>  	if (phydev->attached_dev) {
>> @@ -981,6 +981,7 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
>>  
>>  error:
>>  	phy_detach(phydev);
>> +error_put_device:
>>  	put_device(d);
>>  	module_put(d->driver->owner);
> 
> Can we get into problems here? Maybe we did not do a get?

Humm yes, that seems possible too.

> 
> 
>>  	if (ndev_owner != bus->owner)
>> @@ -1065,7 +1066,8 @@ void phy_detach(struct phy_device *phydev)
>>  	bus = phydev->mdio.bus;
>>  
>>  	put_device(&phydev->mdio.dev);
>> -	module_put(phydev->mdio.dev.driver->owner);
>> +	if (phydev->mdio.dev.driver)
>> +		module_put(phydev->mdio.dev.driver->owner);
> 
> Humm. By this point, havn't we assigned d->driver to genphy_driver?
> So this decrements something we never incremented?

Not really, the generic PHY drivers are built into libphy, so all PHY
drivers de facto going to depend on libphy.ko being loaded first, that's
why we can take shortcuts and not increment the refcount on the
genphy/libphy module here.

> 
> To me, it seems better to move the try_module_get() after assigning
> genphy_driver if needed. We then don't have any special conditions.

Sounds fair, let me fix that (and the problem reported by Mao about
error handling).

Thanks!
-- 
Florian

  reply	other threads:[~2017-02-08 17:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-08  7:37 [PATCH net v2 0/3] net: phy: Unbind/bind fixes Florian Fainelli
2017-02-08  7:37 ` [PATCH net v2 1/3] net: phy: Fix PHY module checks Florian Fainelli
2017-02-08  7:57   ` maowenan
2017-02-08 17:46     ` Florian Fainelli
2017-02-08 16:46   ` Fabio Estevam
2017-02-08 16:57   ` Andrew Lunn
2017-02-08 17:55     ` Florian Fainelli [this message]
2017-02-08  7:37 ` [PATCH net v2 2/3] net: phy: Check phydev->drv Florian Fainelli
2017-02-08  7:37 ` [PATCH net v2 3/3] net: phy: Fix PHY driver bind and unbind events Florian Fainelli

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=a068e619-5288-7007-b172-cb5d4417b758@gmail.com \
    --to=f.fainelli@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=maowenan@huawei.com \
    --cc=netdev@vger.kernel.org \
    --cc=rmk+kernel@armlinux.org.uk \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.