public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Sergei Shtylyov <sergei.shtylyov@cogentembedded•com>
To: Andrew Lunn <andrew@lunn•ch>,
	Vivien Didelot <vivien.didelot@savoirfairelinux•com>
Cc: "David S. Miller" <davem@davemloft•net>,
	f.fainelli@gmail•com, arnd@arndb•de, netdev@vger•kernel.org,
	kernel@savoirfairelinux•com
Subject: Re: [PATCH 1/5] phylib: don't return NULL from get_phy_device()
Date: Wed, 27 Apr 2016 23:09:37 +0300	[thread overview]
Message-ID: <57211C81.4000903@cogentembedded.com> (raw)
In-Reply-To: <20160427194932.GF29024@lunn.ch>

Hello.

On 04/27/2016 10:49 PM, Andrew Lunn wrote:

>> Sergei Shtylyov <sergei.shtylyov@cogentembedded•com> writes:
>>
>>> Arnd Bergmann asked that get_phy_device() returns either NULL or the error
>>> value,  not both on error.  Do as he said, return ERR_PTR(-ENODEV) instead
>>> of NULL when the PHY ID registers read as  all ones.
>>>
>>> Suggested-by: Arnd Bergmann <arnd@arndb•de>
>>> Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded•com>
>>>
>>> ---
>>>   drivers/net/phy/phy_device.c |    2 +-
>>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> Index: net-next/drivers/net/phy/phy_device.c
>>> ===================================================================
>>> --- net-next.orig/drivers/net/phy/phy_device.c
>>> +++ net-next/drivers/net/phy/phy_device.c
>>> @@ -529,7 +529,7 @@ struct phy_device *get_phy_device(struct
>>>
>>>   	/* If the phy_id is mostly Fs, there is no device there */
>>>   	if ((phy_id & 0x1fffffff) == 0x1fffffff)
>>> -		return NULL;
>>> +		return ERR_PTR(-ENODEV);
>>>
>>>   	return phy_device_create(bus, addr, phy_id, is_c45, &c45_ids);
>>>   }
>
> This change is wrong, it needs reverting, or the call sights need
> fixing to expect ENODEV.

    So this function had a good reason to return NULL, as it turned out... :-(

> The point is, the device not being there is not an error, with respect
> to the code calling this function.
>
> It gets called by mdiobus_scan()
>
> struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr)
> {
>          struct phy_device *phydev;
>          int err;
>
>          phydev = get_phy_device(bus, addr, false);
>          if (IS_ERR(phydev) || phydev == NULL)
>                  return phydev;
>
> So before, we return NULL, if the device was not there. Now we return
> ERR_PTR(-ENODEV).
>
> This is being called by:
>
> int __mdiobus_register(struct mii_bus *bus, struct module *owner)
> {
>          struct mdio_device *mdiodev;
> ...
>          for (i = 0; i < PHY_MAX_ADDR; i++) {
>                  if ((bus->phy_mask & (1 << i)) == 0) {
>                          struct phy_device *phydev;
>
>                          phydev = mdiobus_scan(bus, i);
>                          if (IS_ERR(phydev)) {
>                                  err = PTR_ERR(phydev);
>                                  goto error;
>                          }
>                  }
>          }
>
> This is treating ERR_PTR(-ENODEV) as a fatal error, where as before
> IS_ERR(NULL) would be false and it would continue scanning other
> addresses on the bus.

    Thank you for the detailed analysis! (And shame on me for the lack of it.)

> Please revert this, or fix all the callsites such that ENODEV is not a
> fatal error.

    OK, I'll do what DaveM decides.

> 	     Andrew

MBR, Sergei

  reply	other threads:[~2016-04-27 20:09 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-24 17:23 [PATCH 0/5] Don't return NULL from get_phy_device() anymore Sergei Shtylyov
2016-04-24 17:25 ` [PATCH 1/5] phylib: don't return NULL from get_phy_device() Sergei Shtylyov
2016-04-25 19:45   ` Florian Fainelli
     [not found]   ` <874mamzw5q.fsf@ketchup.mtl.sfl>
2016-04-27 19:49     ` Andrew Lunn
2016-04-27 20:09       ` Sergei Shtylyov [this message]
2016-04-27 20:23         ` David Miller
2016-04-27 22:03         ` Arnd Bergmann
2016-04-27 21:47       ` Florian Fainelli
2016-04-27 22:07         ` Arnd Bergmann
2016-04-27 20:12     ` Sergei Shtylyov
2016-04-27 20:11       ` Florian Fainelli
2016-04-24 17:27 ` [PATCH 2/5] xgene: get_phy_device() doesn't return NULL anymore Sergei Shtylyov
2016-04-25 19:46   ` Florian Fainelli
2016-04-24 17:29 ` [PATCH 3/5] fixed_phy: " Sergei Shtylyov
2016-04-25 19:46   ` Florian Fainelli
2016-04-24 17:30 ` [PATCH 4/5] mdio_bus: " Sergei Shtylyov
2016-04-25 19:46   ` Florian Fainelli
2016-04-24 17:31 ` [PATCH 5/5] of_mdio: " Sergei Shtylyov
2016-04-24 17:37   ` Sergei Shtylyov
2016-04-25 19:47   ` Florian Fainelli
2016-04-26 19:41 ` [PATCH 0/5] Don't return NULL from get_phy_device() anymore 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=57211C81.4000903@cogentembedded.com \
    --to=sergei.shtylyov@cogentembedded$(echo .)com \
    --cc=andrew@lunn$(echo .)ch \
    --cc=arnd@arndb$(echo .)de \
    --cc=davem@davemloft$(echo .)net \
    --cc=f.fainelli@gmail$(echo .)com \
    --cc=kernel@savoirfairelinux$(echo .)com \
    --cc=netdev@vger$(echo .)kernel.org \
    --cc=vivien.didelot@savoirfairelinux$(echo .)com \
    /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