net: Check device driver API pointer
It is possible that the device driver API pointer is null. For example if the device driver returns an error, the device code will make the API pointer NULL so that the API would not be used. This can cause errors in networking code where we typically do not check the NULL value. Fixes #15003 Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
parent
9a6e3012da
commit
9a6bbbfb69
9 changed files with 97 additions and 18 deletions
|
@ -528,6 +528,11 @@ static int ethernet_send(struct net_if *iface, struct net_pkt *pkt)
|
|||
u16_t ptype;
|
||||
int ret;
|
||||
|
||||
if (!api) {
|
||||
ret = -ENOENT;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_NET_IPV4) &&
|
||||
net_pkt_family(pkt) == AF_INET) {
|
||||
struct net_pkt *tmp;
|
||||
|
@ -621,6 +626,10 @@ static inline int ethernet_enable(struct net_if *iface, bool state)
|
|||
const struct ethernet_api *eth =
|
||||
net_if_get_device(iface)->driver_api;
|
||||
|
||||
if (!eth) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
if (!state) {
|
||||
net_arp_clear_cache(iface);
|
||||
|
||||
|
@ -781,6 +790,10 @@ int net_eth_vlan_enable(struct net_if *iface, u16_t tag)
|
|||
struct ethernet_vlan *vlan;
|
||||
int i;
|
||||
|
||||
if (!eth) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
if (net_if_l2(iface) != &NET_L2_GET_NAME(ETHERNET)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
@ -838,6 +851,10 @@ int net_eth_vlan_disable(struct net_if *iface, u16_t tag)
|
|||
net_if_get_device(iface)->driver_api;
|
||||
struct ethernet_vlan *vlan;
|
||||
|
||||
if (!eth) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
if (net_if_l2(iface) != &NET_L2_GET_NAME(ETHERNET)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
@ -932,6 +949,10 @@ struct device *net_eth_get_ptp_clock(struct net_if *iface)
|
|||
struct device *dev = net_if_get_device(iface);
|
||||
const struct ethernet_api *api = dev->driver_api;
|
||||
|
||||
if (!api) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (net_if_l2(iface) != &NET_L2_GET_NAME(ETHERNET)) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue