u-boot: fix error check in eth init
PATCH 1/1 u-boot: fix error check in eth init
eth_start_udev can fail but errno could still be zero which causes the function ignores the error silently. This fix catches the error properly.
---
net/eth-uclass.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
net/eth-uclass.c +6 -5
@@ -347,12 +347,13 @@ int eth_init(void)debug ("Trying %s\n" , current->name); ret =eth_start_udev (current); -if (ret <0 ) - ret = eth_errno; -else +if (ret <0 ) { +if (eth_errno <0 ) + ret = eth_errno; +debug ("%s start failed (ret=%d)\n" , current->name, ret); + }else {break ; - -debug ("FAIL\n" ); + } }else {debug ("PROBE FAIL\n" ); }
---
base-commit: 4d499701629ec07d32e3dacbf9d9bd43d9e8032f
branch: main
Signature · 1 line
2.55.0.887.g758fc8c411-goog
Quoted 23 lines · Yuxiao Zhang
eth_start_udevcan fail but errno could still be zero which causes the function ignores the error silently. This fix catches the error properly.Signed-off-by Yuxiao Zhang <[email protected]>---
net/eth-uclass.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)net/eth-uclass.c +2
-3@@ -347,12 +347,13 @@ int eth_init(void)debug ("Trying %s\n" , current->name); ret =eth_start_udev (current); -if (ret <0 ) - ret = eth_errno; -else +if (ret <0 ) { +if (eth_errno <0 )
net/eth-uclass.c int eth_init(void) · line 359
Quoted 10 lines
net/eth-uclass.c +4
-2+ ret = eth_errno; +debug ("%s start failed (ret=%d)\n" , current->name, ret); + }else {break ; - -debug ("FAIL\n" ); + } }else {debug ("PROBE FAIL\n" ); }
Is it a valid case for eth_start_udev to have failed and not set eth_errno?
Signature · 1 line
Tom
IMHO at least the activation check is a valid case. It just check the status flag and returns EINVAL without setting errno:
292 if (!device_active(dev))
293 return -EINVAL;
Thanks,
-Yuxiao
Quoted 42 lines · Tom Rini
Quoted 15 lines · Yuxiao Zhang
eth_start_udevcan fail but errno could still be zero which causes the function ignores the error silently. This fix catches the error properly.Signed-off-by Yuxiao Zhang <[email protected]>---
net/eth-uclass.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)net/eth-uclass.c +0
-0net/eth-uclass.c int eth_init(void) · line 353
Quoted 10 lines
net/eth-uclass.c +4
-3@@ -347,12 +347,13 @@ int eth_init(void)debug ("Trying %s\n" , current->name); ret =eth_start_udev (current); -if (ret <0 ) - ret = eth_errno; -else +if (ret <0 ) { +if (eth_errno <0 ) + ret = eth_errno; + debug("%s start failed (ret=%d)\n",
current->name, ret);net/eth-uclass.c int eth_init(void) · line 359
Quoted 8 lines
net/eth-uclass.c +2
-2+ }else {break ; - -debug ("FAIL\n" ); + } }else {debug ("PROBE FAIL\n" ); }Is it a valid case for
eth_start_udevto have failed and not seteth_errno?--
Tom
Tom Rini
Reviewed-by Ilias ApalodimasQuoted 5 lines · Yuxiao Zhang
IMHO at least the activation check is a valid case. It just check the status flag and returns EINVAL without setting errno:
292 if (!device_active(dev))
293 return-EINVAL;
Please don't top-post, it makes following context harder. And, this isn't quite what I was asking about. If we look at commit:
commit 7ad5e878cd850102e13ee2a5f8a5fb69742f70b0
Author: Jerome Forissier <[email protected]> Date: Wed Oct 16 12:04:01 2024 +0200
net: eth-uclass: add function eth_start_udev()
Add a function to start a given network device, and update eth_init() to use it.
Which introduces this function, and examine the code before/after, we aren't quite doing the same things as before.
So yes, we aren't handling the error case you describe correctly, but my first thought is that the caller here should be doing eth_errno = eth_start_udev(); and then setting ret = eth_errno if we get a problem. But that might not be quite right either, I've only spent a few minutes on this,
Quoted 50 lines
Thanks,
-YuxiaoQuoted 42 lines · Tom Rini
Quoted 15 lines · Yuxiao Zhang
eth_start_udevcan fail but errno could still be zero which causes the function ignores the error silently. This fix catches the error properly.Signed-off-by Yuxiao Zhang <[email protected]>---
net/eth-uclass.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)net/eth-uclass.c +0
-0net/eth-uclass.c int eth_init(void) · line 353
Quoted 10 lines
net/eth-uclass.c +4
-3@@ -347,12 +347,13 @@ int eth_init(void)debug ("Trying %s\n" , current->name); ret =eth_start_udev (current); -if (ret <0 ) - ret = eth_errno; -else +if (ret <0 ) { +if (eth_errno <0 ) + ret = eth_errno; + debug("%s start failed (ret=%d)\n",
current->name, ret);net/eth-uclass.c int eth_init(void) · line 359
Quoted 8 lines
net/eth-uclass.c +2
-2+ }else {break ; - -debug ("FAIL\n" ); + } }else {debug ("PROBE FAIL\n" ); }Is it a valid case for
eth_start_udevto have failed and not seteth_errno?--
Tom
Signature · 1 line
Tom
Quoted 78 lines · Tom Rini
Quoted 5 lines · Yuxiao Zhang
IMHO at least the activation check is a valid case. It just check the status flag and returns EINVAL without setting errno:
292 if (!device_active(dev))
293 return-EINVAL;Please don't top-post, it makes following context harder. And, this isn't quite what I was asking about. If we look at commit:
commit7ad5e878cd850102e13ee2a5f8a5fb69742f70b0Author: Jerome Forissier <[email protected]> Date: Wed Oct 16 12:04:01 2024 +0200net: eth-uclass: add function
eth_start_udev()Add a function to start a given network device, and update
eth_init()to use it.Signed-off-by Jerome Forissier <[email protected]>Reviewed-by Ilias Apalodimas <[email protected]>Which introduces this function, and examine the code before/after, we aren't quite doing the same things as before.
So yes, we aren't handling the error case you describe correctly, but my first thought is that the caller here should be doing
eth_errno=eth_start_udev(); and then setting ret =eth_errnoif we get a problem. But that might not be quite right either, I've only spent a few minutes on this,Quoted 11 lines
Thanks,
-YuxiaoQuoted 3 lines · Tom Rini
Quoted 1 line · Yuxiao Zhang
eth_start_udevcan fail but errno could still be zero which causesthe
Quoted 34 lines
Quoted 34 lines
Quoted 14 lines
function ignores the error silently. This fix catches the error properly.
Signed-off-by Yuxiao Zhang <[email protected]>---
net/eth-uclass.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)net/eth-uclass.c +0
-0net/eth-uclass.c int eth_init(void) · line 353
Quoted 10 lines
net/eth-uclass.c +4
-3@@ -347,12 +347,13 @@ int eth_init(void)debug ("Trying %s\n" , current->name); ret =eth_start_udev (current); -if (ret <0 ) - ret = eth_errno; -else +if (ret <0 ) { +if (eth_errno <0 ) + ret = eth_errno; + debug("%s start failed (ret=%d)\n",
current->name, ret);Quoted 8 lines
net/eth-uclass.c +2
-2+ }else {break ; - -debug ("FAIL\n" ); + } }else {debug ("PROBE FAIL\n" ); }Quoted 1 line
Quoted 1 line
Is it a valid case for
eth_start_udevto have failed and not set
Quoted 9 lines
eth_errno?Quoted 4 lines
Quoted 4 lines
--
Tom--
Tom
Sorry for the late reply. I checked the commit 7ad5e878cd850102e13ee2a5f8a5fb69742f70b0 and looks like the issue still exists before that commit. If the check "device_active(current)" failed then the errno is also not set and we still return 0. I am not sure if "eth_errno
= eth_start_udev();" since that just ignores the real errno. The fix I proposed is just to capture the corner case that errno is 0 but eth_start_udev still failed for whatever reason. Otherwise the logic keeps the same as before.
Thanks,
-Yuxiao
Quoted 90 lines · Yuxiao Zhang
Quoted 78 lines · Tom Rini
Quoted 5 lines · Yuxiao Zhang
IMHO at least the activation check is a valid case. It just check the status flag and returns EINVAL without setting errno:
292 if (!device_active(dev))
293 return-EINVAL;Please don't top-post, it makes following context harder. And, this isn't quite what I was asking about. If we look at commit:
commit7ad5e878cd850102e13ee2a5f8a5fb69742f70b0Author: Jerome Forissier <[email protected]> Date: Wed Oct 16 12:04:01 2024 +0200net: eth-uclass: add function
eth_start_udev()Add a function to start a given network device, and update
eth_init()to use it.Signed-off-by Jerome Forissier <[email protected]>Reviewed-by Ilias Apalodimas <[email protected]>Which introduces this function, and examine the code before/after, we aren't quite doing the same things as before.
So yes, we aren't handling the error case you describe correctly, but my first thought is that the caller here should be doing
eth_errno=eth_start_udev(); and then setting ret =eth_errnoif we get a problem. But that might not be quite right either, I've only spent a few minutes on this,Quoted 11 lines
Thanks,
-YuxiaoQuoted 3 lines · Tom Rini
Quoted 1 line · Yuxiao Zhang
eth_start_udevcan fail but errno could still be zero which causesthe
Quoted 34 lines
Quoted 34 lines
Quoted 14 lines
function ignores the error silently. This fix catches the error properly.
Signed-off-by Yuxiao Zhang <[email protected]>---
net/eth-uclass.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)net/eth-uclass.c +0
-0net/eth-uclass.c int eth_init(void) · line 353
Quoted 10 lines
net/eth-uclass.c +4
-3@@ -347,12 +347,13 @@ int eth_init(void)debug ("Trying %s\n" , current->name); ret =eth_start_udev (current); -if (ret <0 ) - ret = eth_errno; -else +if (ret <0 ) { +if (eth_errno <0 ) + ret = eth_errno; + debug("%s start failed (ret=%d)\n",
current->name, ret);Quoted 8 lines
net/eth-uclass.c +2
-2+ }else {break ; - -debug ("FAIL\n" ); + } }else {debug ("PROBE FAIL\n" ); }Quoted 1 line
Quoted 1 line
Is it a valid case for
eth_start_udevto have failed and not setQuoted 9 lines
eth_errno?Quoted 4 lines
Quoted 4 lines
--
Tom--
Tom
Quoted 9 lines
Sorry for the late reply. I checked the commit
7ad5e878cd850102e13ee2a5f8a5fb69742f70b0and looks like the issue still exists before that commit. If the check "device_active(current)" failed then the errno is also not set and we still return 0. I am not sure if "eth_errno
=eth_start_udev();" since that just ignores the real errno. The fix I proposed is just to capture the corner case that errno is 0 buteth_start_udevstill failed for whatever reason. Otherwise the logic keeps the same as before.
Yes, before if device_active(current) is false (it's just a flag check), we would only end up with something in eth_errno if eth_get_dev() had failed.
So at this point, it should be clear that, as I had asked originally, this isn't some special case but rather a problem in handling errors from eth_start_udev to solve. Perhaps it should be setting eth_errno instead of directly returning? Or perhaps as I suggested at first we should be doing 'eth_errno = eth_start_udev();' and going from there?
Signature · 1 line
Tom
Quoted 109 lines · Tom Rini
Quoted 16 lines · Yuxiao Zhang
Quoted 14 lines · Tom Rini
Quoted 5 lines · Yuxiao Zhang
IMHO at least the activation check is a valid case. It just check the status flag and returns EINVAL without setting errno:
292 if (!device_active(dev))
293 return-EINVAL;Please don't top-post, it makes following context harder. And, this isn't quite what I was asking about. If we look at commit:
commit7ad5e878cd850102e13ee2a5f8a5fb69742f70b0Author: Jerome Forissier <[email protected]> Date: Wed Oct 16 12:04:01 2024 +0200Quoted 3 lines
Quoted 3 lines
net: eth-uclass: add function
eth_start_udev()Add a function to start a given network device, and update
eth_init()Quoted 9 lines
Quoted 9 lines
to use it.
Signed-off-by Jerome Forissier <[email protected]>Reviewed-by Ilias Apalodimas <[email protected]>Which introduces this function, and examine the code before/after, we aren't quite doing the same things as before.
So yes, we aren't handling the error case you describe correctly, but
my
Quoted 11 lines
Quoted 11 lines
first thought is that the caller here should be doing
eth_errno=eth_start_udev(); and then setting ret =eth_errnoif we get a problem. But that might not be quite right either, I've only spent a few minutes on this,Quoted 6 lines
Thanks,
-YuxiaoQuoted 5 lines
Quoted 5 lines
Quoted 5 lines · Tom Rini
Quoted 4 lines · Yuxiao Zhang
Quoted 2 lines
eth_start_udevcan fail but errno could still be zero whichcauses
Quoted 46 lines
Quoted 36 lines
the
Quoted 34 lines
Quoted 34 lines
Quoted 14 lines
function ignores the error silently. This fix catches the error properly.
Signed-off-by Yuxiao Zhang <[email protected]>---
net/eth-uclass.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)net/eth-uclass.c +0
-0net/eth-uclass.c int eth_init(void) · line 353
Quoted 10 lines
net/eth-uclass.c +4
-3@@ -347,12 +347,13 @@ int eth_init(void)debug ("Trying %s\n" , current->name); ret =eth_start_udev (current); -if (ret <0 ) - ret = eth_errno; -else +if (ret <0 ) { +if (eth_errno <0 ) + ret = eth_errno; + debug("%s start failed (ret=%d)\n",
current->name, ret);Quoted 8 lines
net/eth-uclass.c +2
-2+ }else {break ; - -debug ("FAIL\n" ); + } }else {debug ("PROBE FAIL\n" ); }Quoted 1 line
Quoted 1 line
Is it a valid case for
eth_start_udevto have failed and not setQuoted 9 lines
eth_errno?Quoted 4 lines
Quoted 4 lines
--
Tom--
TomQuoted 7 lines
Sorry for the late reply. I checked the commit
7ad5e878cd850102e13ee2a5f8a5fb69742f70b0and looks like the issue still exists before that commit. If the check "device_active(current)" failed then the errno is also not set and we still return 0. I am not sure if "eth_errno
=eth_start_udev();" since that just ignores the real errno. The fix I proposed is just to capture the corner case that errno is 0 but
eth_start_udevQuoted 2 lines
still failed for whatever reason. Otherwise the logic keeps the same as before.
Yes, before if
device_active(current)is false (it's just a flag check), we would only end up with something ineth_errnoifeth_get_dev()had failed.
Quoted 9 lines
So at this point, it should be clear that, as I had asked originally, this isn't some special case but rather a problem in handling errors from
eth_start_udevto solve. Perhaps it should be settingeth_errnoinstead of directly returning? Or perhaps as I suggested at first we should be doing 'eth_errno=eth_start_udev();' and going from there?--
Tom
Ok makes sense, I will send out a new version which also set the eth_errno if the flag check failed.
Thanks,
-Yuxiao
A message that is not in the archive (sent off-list or not yet received): "<CAOOoKeR5oAcouuG1EO2fQNubKsfVB=O5qf0aj-FhSSGJeOH-LQ@mail.gmail.com
PATCH 1/1 u-boot: fix error check in eth init
eth_start_udev can fail but errno could still be zero which causes the function ignores the error silently. This fix catches the error properly.
---
net/eth-uclass.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/eth-uclass.c +3 -1
@@ -289,8 +289,10 @@ int eth_start_udev(struct udevice *dev)if (priv->running)return 0 ; -if (!device_active (dev)) +if (!device_active (dev)) { + eth_errno = -EINVAL ;return -EINVAL ; + } ret =eth_get_ops (dev)->start (dev);if (ret <0 )
---
base-commit: 3f19667468fb93bcb5702d23aa057b72639e3ac8
branch: main
Signature · 1 line
2.55.0.966.g6673acef38-goog
Quoted 5 lines · Yuxiao Zhang
eth_start_udevcan fail but errno could still be zero which causes the function ignores the error silently. This fix catches the error properly.Signed-off-by Yuxiao Zhang <[email protected]>
Thanks.
Signature · 1 line
Tom
Quoted 5 lines · Yuxiao Zhang
eth_start_udevcan fail but errno could still be zero which causes the function ignores the error silently. This fix catches the error properly.
Applied to u-boot-net branch for-main, thanks!
[1/1] u-boot: fix error check in eth init
commit: 1d48033d57329dad77e5656267b60601258dbb3d
Best regards,
Signature · 1 line
Jerome Forissier <[email protected]>