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 <heinrich.schuchardt@canonical.com> Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
This commit is contained in:

committed by
Tom Rini

parent
b6691d0add
commit
d701c6ab42
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <command.h>
|
#include <command.h>
|
||||||
#include <console.h>
|
#include <console.h>
|
||||||
|
#include <log.h>
|
||||||
#include <dm/device.h>
|
#include <dm/device.h>
|
||||||
#include <linux/delay.h>
|
#include <linux/delay.h>
|
||||||
#include <linux/errno.h>
|
#include <linux/errno.h>
|
||||||
@@ -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 do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
struct udevice *dev;
|
||||||
|
|
||||||
eth_set_current();
|
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)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user