Re: [PATCH v6 13/20] net: eth-uclass: Do not set device on error

2022-10-17 Thread Simon Glass
eth_get_dev relies on the broken behavior that returns an error but not
the device on which the error happened which gives the caller no
reasonable way to report or handle the error.

In a later patch uclass_first_device_err will be changed to return the
device on error but eth_get_dev stores the returned device pointer
directly in a global state without checking the return value. Unset the
pointer again in the error case.

Signed-off-by: Michal Suchanek 
Reviewed-by: Simon Glass 
---
v6: split off as separate patch
---
 net/eth-uclass.c | 2 ++
 1 file changed, 2 insertions(+)

Applied to u-boot-dm, thanks!


[PATCH v6 13/20] net: eth-uclass: Do not set device on error

2022-10-12 Thread Michal Suchanek
eth_get_dev relies on the broken behavior that returns an error but not
the device on which the error happened which gives the caller no
reasonable way to report or handle the error.

In a later patch uclass_first_device_err will be changed to return the
device on error but eth_get_dev stores the returned device pointer
directly in a global state without checking the return value. Unset the
pointer again in the error case.

Signed-off-by: Michal Suchanek 
Reviewed-by: Simon Glass 
---
v6: split off as separate patch
---
 net/eth-uclass.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/eth-uclass.c b/net/eth-uclass.c
index 8c3f9cc31b..f41da4b37b 100644
--- a/net/eth-uclass.c
+++ b/net/eth-uclass.c
@@ -93,6 +93,8 @@ struct udevice *eth_get_dev(void)
if (eth_errno)
eth_errno = uclass_first_device_err(UCLASS_ETH,
_priv->current);
+   if (eth_errno)
+   uc_priv->current = NULL;
}
return uc_priv->current;
 }
-- 
2.37.3