Skip to contentSkip to conversation

u-boot: fix error check in eth init

PATCH In review Yuxiao Zhang 3 participants 10 messages Aug 26 – Sep 11 1 message not in the archive Networking

lore
Share & tools
lore
#0 lore raw

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
index 5c437143a30..5518268bd68 100644
@@ -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
#1 lore raw
Quoted 23 lines · Yuxiao Zhang

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 +2 -3
index 5c437143a30..5518268bd68 100644
@@ -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
#2 lore raw

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_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 +0 -0
index 5c437143a30..5518268bd68 100644

net/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_udev to have failed and not set eth_errno?

--
Tom

Reviewed-by Ilias Apalodimas
#3 lore raw
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:
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,
-Yuxiao

Quoted 42 lines · Tom Rini
Quoted 15 lines · Yuxiao Zhang

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 +0 -0
index 5c437143a30..5518268bd68 100644

net/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_udev to have failed and not set eth_errno?

--
Tom

Signature · 1 line
Tom
#4 lore raw
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:
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 11 lines

Thanks,
-Yuxiao

Quoted 3 lines · Tom Rini
Quoted 1 line · Yuxiao Zhang

eth_start_udev can fail but errno could still be zero which causes

the

Quoted 34 lines
Quoted 34 lines
Quoted 14 lines

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 +0 -0
index 5c437143a30..5518268bd68 100644

net/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_udev to 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

#5 lore raw
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:
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 11 lines

Thanks,
-Yuxiao

Quoted 3 lines · Tom Rini
Quoted 1 line · Yuxiao Zhang

eth_start_udev can fail but errno could still be zero which causes

the

Quoted 34 lines
Quoted 34 lines
Quoted 14 lines

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 +0 -0
index 5c437143a30..5518268bd68 100644

net/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_udev to have failed and not set

Quoted 9 lines

eth_errno?

Quoted 4 lines
Quoted 4 lines

--
Tom

--
Tom

Quoted 9 lines

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.

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
#6 lore raw
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:
commit 7ad5e878cd850102e13ee2a5f8a5fb69742f70b0

Author: Jerome Forissier <[email protected]>
Date:   Wed Oct 16 12:04:01 2024 +0200
Quoted 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.

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_errno if 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,
-Yuxiao

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines · Tom Rini
Quoted 4 lines · Yuxiao Zhang
Quoted 2 lines

eth_start_udev can fail but errno could still be zero which

causes

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.

---

 net/eth-uclass.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
net/eth-uclass.c +0 -0
index 5c437143a30..5518268bd68 100644

net/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_udev to have failed and not set

Quoted 9 lines

eth_errno?

Quoted 4 lines
Quoted 4 lines

--
Tom

--
Tom

Quoted 7 lines

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

Quoted 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 in eth_errno if eth_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_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?

--
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

#8 lore raw

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
index 5c437143a30..07ec59b97f0 100644
@@ -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
#10 lore raw
In reply to Yuxiao Zhang
Quoted 5 lines · Yuxiao Zhang

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.

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]>