diff mbox series

[net-next,v4,3/3] net: lan743x: Return PTR_ERR() for fixed_phy_register()

Message ID 20230821025020.1971520-4-ruanjinjie@huawei.com (mailing list archive)
State Not Applicable
Delegated to: Netdev Maintainers
Headers show
Series net: Return PTR_ERR() for fixed_phy_register() | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/apply success Patch already applied to net-next

Commit Message

Jinjie Ruan Aug. 21, 2023, 2:50 a.m. UTC
fixed_phy_register() returns -EPROBE_DEFER, -EINVAL and -EBUSY,
etc, in addition to -EIO. The Best practice is to return these
error codes with PTR_ERR().

Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
v4:
- Update to bring the author's name before.
v3:
- Update the commit title and message.
---
 drivers/net/ethernet/microchip/lan743x_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jakub Kicinski Aug. 23, 2023, 12:03 a.m. UTC | #1
On Mon, 21 Aug 2023 10:50:20 +0800 Jinjie Ruan wrote:
> fixed_phy_register() returns -EPROBE_DEFER, -EINVAL and -EBUSY,
> etc, in addition to -EIO. The Best practice is to return these
> error codes with PTR_ERR().

EPROBE_DEFER is not a unix error code. We can't return it to user
space, so propagating it from ndo_open is not correct.

> diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c
> index a36f6369f132..c81cdeb4d4e7 100644
> --- a/drivers/net/ethernet/microchip/lan743x_main.c
> +++ b/drivers/net/ethernet/microchip/lan743x_main.c
> @@ -1515,7 +1515,7 @@ static int lan743x_phy_open(struct lan743x_adapter *adapter)
>  							    &fphy_status, NULL);
>  				if (IS_ERR(phydev)) {
>  					netdev_err(netdev, "No PHY/fixed_PHY found\n");
> -					return -EIO;
> +					return PTR_ERR(phydev);
>  				}
>  			} else {
>  				goto return_error;
Jinjie Ruan Aug. 23, 2023, 7:43 a.m. UTC | #2
On 2023/8/23 8:03, Jakub Kicinski wrote:
> On Mon, 21 Aug 2023 10:50:20 +0800 Jinjie Ruan wrote:
>> fixed_phy_register() returns -c, -EINVAL and -EBUSY,
>> etc, in addition to -EIO. The Best practice is to return these
>> error codes with PTR_ERR().
> 
> EPROBE_DEFER is not a unix error code. We can't return it to user
> space, so propagating it from ndo_open is not correct.

When the error is EPROBE_DEFER, Whether print the netdev_err is ok? And
what should it return?

How about this?

if (IS_ERR(phydev)) {
     ......
     if (PTR_ERR(phydev) != -EPROBE_DEFER)
         return PTR_ERR(phydev);
     else
         return -EIO;
}

> 
>> diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c
>> index a36f6369f132..c81cdeb4d4e7 100644
>> --- a/drivers/net/ethernet/microchip/lan743x_main.c
>> +++ b/drivers/net/ethernet/microchip/lan743x_main.c
>> @@ -1515,7 +1515,7 @@ static int lan743x_phy_open(struct lan743x_adapter *adapter)
>>  							    &fphy_status, NULL);
>>  				if (IS_ERR(phydev)) {
>>  					netdev_err(netdev, "No PHY/fixed_PHY found\n");
>> -					return -EIO;
>> +					return PTR_ERR(phydev);
>>  				}
>>  			} else {
>>  				goto return_error;
Jakub Kicinski Aug. 23, 2023, 2:37 p.m. UTC | #3
On Wed, 23 Aug 2023 15:43:58 +0800 Ruan Jinjie wrote:
> > EPROBE_DEFER is not a unix error code. We can't return it to user
> > space, so propagating it from ndo_open is not correct.  
> 
> When the error is EPROBE_DEFER, Whether print the netdev_err is ok? And
> what should it return?
> 
> How about this?
> 
> if (IS_ERR(phydev)) {
>      ......
>      if (PTR_ERR(phydev) != -EPROBE_DEFER)
>          return PTR_ERR(phydev);
>      else
>          return -EIO;
> }

That's too much code to copy & paste into every driver.

Someone who understands the code flow very well should tackle this.
Please leave the cases where fixed_phy_register() is called outside 
of probe alone.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c
index a36f6369f132..c81cdeb4d4e7 100644
--- a/drivers/net/ethernet/microchip/lan743x_main.c
+++ b/drivers/net/ethernet/microchip/lan743x_main.c
@@ -1515,7 +1515,7 @@  static int lan743x_phy_open(struct lan743x_adapter *adapter)
 							    &fphy_status, NULL);
 				if (IS_ERR(phydev)) {
 					netdev_err(netdev, "No PHY/fixed_PHY found\n");
-					return -EIO;
+					return PTR_ERR(phydev);
 				}
 			} else {
 				goto return_error;