Skip to content
Snippets Groups Projects
Commit ac1d3138 authored by Bin Meng's avatar Bin Meng Committed by Joe Hershberger
Browse files

net: eth: Check return value in various places


eth_get_dev() can return NULL which means device_probe() fails for
that ethernet device. Add return value check in various places or
U-Boot will crash due to NULL pointer access.

With this commit, 'dm_test_eth_act' test case passes.

Signed-off-by: default avatarBin Meng <bmeng.cn@gmail.com>
Acked-by: default avatarJoe Hershberger <joe.hershberger@ni.com>
parent 6d9764c2
No related branches found
No related tags found
No related merge requests found
...@@ -179,8 +179,12 @@ struct udevice *eth_get_dev(void) ...@@ -179,8 +179,12 @@ struct udevice *eth_get_dev(void)
*/ */
static void eth_set_dev(struct udevice *dev) static void eth_set_dev(struct udevice *dev)
{ {
if (dev && !device_active(dev)) if (dev && !device_active(dev)) {
eth_errno = device_probe(dev); eth_errno = device_probe(dev);
if (eth_errno)
dev = NULL;
}
eth_get_uclass_priv()->current = dev; eth_get_uclass_priv()->current = dev;
} }
...@@ -213,10 +217,9 @@ struct udevice *eth_get_dev_by_name(const char *devname) ...@@ -213,10 +217,9 @@ struct udevice *eth_get_dev_by_name(const char *devname)
* match an alias or it will match a literal name and we'll pick * match an alias or it will match a literal name and we'll pick
* up the error when we try to probe again in eth_set_dev(). * up the error when we try to probe again in eth_set_dev().
*/ */
device_probe(it); if (device_probe(it))
/* continue;
* Check for the name or the sequence number to match /* Check for the name or the sequence number to match */
*/
if (strcmp(it->name, devname) == 0 || if (strcmp(it->name, devname) == 0 ||
(endp > startp && it->seq == seq)) (endp > startp && it->seq == seq))
return it; return it;
...@@ -346,23 +349,27 @@ int eth_init(void) ...@@ -346,23 +349,27 @@ int eth_init(void)
old_current = current; old_current = current;
do { do {
debug("Trying %s\n", current->name); if (current) {
debug("Trying %s\n", current->name);
if (device_active(current)) {
ret = eth_get_ops(current)->start(current); if (device_active(current)) {
if (ret >= 0) { ret = eth_get_ops(current)->start(current);
struct eth_device_priv *priv = if (ret >= 0) {
current->uclass_priv; struct eth_device_priv *priv =
current->uclass_priv;
priv->state = ETH_STATE_ACTIVE;
return 0; priv->state = ETH_STATE_ACTIVE;
return 0;
}
} else {
ret = eth_errno;
} }
debug("FAIL\n");
} else { } else {
ret = eth_errno; debug("PROBE FAIL\n");
} }
debug("FAIL\n");
/* /*
* If ethrotate is enabled, this will change "current", * If ethrotate is enabled, this will change "current",
* otherwise we will drop out of this while loop immediately * otherwise we will drop out of this while loop immediately
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment