nl80211: Clean up if_add() for hostapd use

The allocation of new_bss and its use was separated by a lot of code in
this function. This can be cleaned up by moving the allocation next to
the use, so that this all can be within a single #ifdef HOSTAPD block.
The i802_check_bridge() call was outside type == WPA_IF_AP_BSS case, but
in practice, it is only used for WPA_IF_AP_BSS (and if used for
something else, this would have resulted in NULL pointer dereference
anyway).

Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2013-10-26 12:14:03 +03:00
parent a288da61b6
commit f5eb9da304

View file

@ -9117,15 +9117,6 @@ static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type,
struct i802_bss *bss = priv;
struct wpa_driver_nl80211_data *drv = bss->drv;
int ifidx;
#ifdef HOSTAPD
struct i802_bss *new_bss = NULL;
if (type == WPA_IF_AP_BSS) {
new_bss = os_zalloc(sizeof(*new_bss));
if (new_bss == NULL)
return -1;
}
#endif /* HOSTAPD */
if (addr)
os_memcpy(if_addr, addr, ETH_ALEN);
@ -9154,9 +9145,6 @@ static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type,
ifidx = nl80211_create_iface(drv, ifname, nlmode, addr,
0, NULL, NULL);
if (ifidx < 0) {
#ifdef HOSTAPD
os_free(new_bss);
#endif /* HOSTAPD */
return -1;
}
}
@ -9201,16 +9189,23 @@ static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type,
#endif /* CONFIG_P2P */
#ifdef HOSTAPD
if (bridge &&
i802_check_bridge(drv, new_bss, bridge, ifname) < 0) {
wpa_printf(MSG_ERROR, "nl80211: Failed to add the new "
"interface %s to a bridge %s", ifname, bridge);
nl80211_remove_iface(drv, ifidx);
os_free(new_bss);
return -1;
}
if (type == WPA_IF_AP_BSS) {
struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss));
if (new_bss == NULL) {
nl80211_remove_iface(drv, ifidx);
return -1;
}
if (bridge &&
i802_check_bridge(drv, new_bss, bridge, ifname) < 0) {
wpa_printf(MSG_ERROR, "nl80211: Failed to add the new "
"interface %s to a bridge %s",
ifname, bridge);
nl80211_remove_iface(drv, ifidx);
os_free(new_bss);
return -1;
}
if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1))
{
nl80211_remove_iface(drv, ifidx);