[U-Boot] [PATCH v3 4/9] dm: eth: Correctly detect alias in eth_get_dev_by_name()

Bin Meng bmeng.cn at gmail.com
Fri Aug 28 07:25:54 CEST 2015


When given a device name string, we should test to see if it is
really an alias like "eth#".

Signed-off-by: Bin Meng <bmeng.cn at gmail.com>
Acked-by: Joe Hershberger <joe.hershberger at ni.com>

---

Changes in v3: None
Changes in v2:
- Change to use strncmp()

 net/eth.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/eth.c b/net/eth.c
index c46a8c3..26520d3 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -195,10 +195,11 @@ struct udevice *eth_get_dev_by_name(const char *devname)
 	const char *startp = NULL;
 	struct udevice *it;
 	struct uclass *uc;
+	int len = strlen("eth");
 
 	/* Must be longer than 3 to be an alias */
-	if (strlen(devname) > strlen("eth")) {
-		startp = devname + strlen("eth");
+	if (!strncmp(devname, "eth", len) && strlen(devname) > len) {
+		startp = devname + len;
 		seq = simple_strtoul(startp, &endp, 10);
 	}
 
-- 
1.8.2.1



More information about the U-Boot mailing list