From: Heinrich Schuchardt Date: Thu, 5 Dec 2024 19:17:36 +0000 (+0100) Subject: net: lwip: check if network device is available in do_dhcp X-Git-Url: http://git.dujemihanovic.xyz/img/%7B%7B%20.RelPermalink%20%7D%7D?a=commitdiff_plain;h=d701c6ab4220a3f5e0fdef06720816d67c46f56d;p=u-boot.git net: lwip: check if network device is available in do_dhcp eth_get_dev() returns NULL if no network device is available. Not checking the return value leads to a crash when the device pointer is dereferenced. Signed-off-by: Heinrich Schuchardt Reviewed-by: Jerome Forissier --- diff --git a/net/lwip/dhcp.c b/net/lwip/dhcp.c index 9b882cf5b8..e7d9147455 100644 --- a/net/lwip/dhcp.c +++ b/net/lwip/dhcp.c @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -112,10 +113,17 @@ static int dhcp_loop(struct udevice *udev) int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { int ret; + struct udevice *dev; eth_set_current(); - ret = dhcp_loop(eth_get_dev()); + dev = eth_get_dev(); + if (!dev) { + log_err("No network device\n"); + return CMD_RET_FAILURE; + } + + ret = dhcp_loop(dev); if (ret) return ret;