Commit 83744791 authored by Bing Zhao's avatar Bing Zhao Committed by Ben Hutchings

mwifiex: fix wrong return values in add_virtual_intf() error cases

commit 858faa57 upstream

backported for linux-3.2.y, linux-3.3.y, linux-3.4.y

add_virtual_intf() needs to return an ERR_PTR(), instead of NULL,
on errors, otherwise cfg80211 will crash.
Reported-by: default avatarJohannes Berg <johannes@sipsolutions.net>
Signed-off-by: default avatarBing Zhao <bzhao@marvell.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent 907e461a
...@@ -1177,11 +1177,11 @@ struct net_device *mwifiex_add_virtual_intf(struct wiphy *wiphy, ...@@ -1177,11 +1177,11 @@ struct net_device *mwifiex_add_virtual_intf(struct wiphy *wiphy,
void *mdev_priv; void *mdev_priv;
if (!priv) if (!priv)
return NULL; return ERR_PTR(-EFAULT);
adapter = priv->adapter; adapter = priv->adapter;
if (!adapter) if (!adapter)
return NULL; return ERR_PTR(-EFAULT);
switch (type) { switch (type) {
case NL80211_IFTYPE_UNSPECIFIED: case NL80211_IFTYPE_UNSPECIFIED:
...@@ -1190,7 +1190,7 @@ struct net_device *mwifiex_add_virtual_intf(struct wiphy *wiphy, ...@@ -1190,7 +1190,7 @@ struct net_device *mwifiex_add_virtual_intf(struct wiphy *wiphy,
if (priv->bss_mode) { if (priv->bss_mode) {
wiphy_err(wiphy, "cannot create multiple" wiphy_err(wiphy, "cannot create multiple"
" station/adhoc interfaces\n"); " station/adhoc interfaces\n");
return NULL; return ERR_PTR(-EINVAL);
} }
if (type == NL80211_IFTYPE_UNSPECIFIED) if (type == NL80211_IFTYPE_UNSPECIFIED)
...@@ -1208,14 +1208,15 @@ struct net_device *mwifiex_add_virtual_intf(struct wiphy *wiphy, ...@@ -1208,14 +1208,15 @@ struct net_device *mwifiex_add_virtual_intf(struct wiphy *wiphy,
break; break;
default: default:
wiphy_err(wiphy, "type not supported\n"); wiphy_err(wiphy, "type not supported\n");
return NULL; return ERR_PTR(-EINVAL);
} }
dev = alloc_netdev_mq(sizeof(struct mwifiex_private *), name, dev = alloc_netdev_mq(sizeof(struct mwifiex_private *), name,
ether_setup, 1); ether_setup, 1);
if (!dev) { if (!dev) {
wiphy_err(wiphy, "no memory available for netdevice\n"); wiphy_err(wiphy, "no memory available for netdevice\n");
goto error; priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
return ERR_PTR(-ENOMEM);
} }
dev_net_set(dev, wiphy_net(wiphy)); dev_net_set(dev, wiphy_net(wiphy));
...@@ -1240,7 +1241,9 @@ struct net_device *mwifiex_add_virtual_intf(struct wiphy *wiphy, ...@@ -1240,7 +1241,9 @@ struct net_device *mwifiex_add_virtual_intf(struct wiphy *wiphy,
/* Register network device */ /* Register network device */
if (register_netdevice(dev)) { if (register_netdevice(dev)) {
wiphy_err(wiphy, "cannot register virtual network device\n"); wiphy_err(wiphy, "cannot register virtual network device\n");
goto error; free_netdev(dev);
priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
return ERR_PTR(-EFAULT);
} }
sema_init(&priv->async_sem, 1); sema_init(&priv->async_sem, 1);
...@@ -1252,12 +1255,6 @@ struct net_device *mwifiex_add_virtual_intf(struct wiphy *wiphy, ...@@ -1252,12 +1255,6 @@ struct net_device *mwifiex_add_virtual_intf(struct wiphy *wiphy,
mwifiex_dev_debugfs_init(priv); mwifiex_dev_debugfs_init(priv);
#endif #endif
return dev; return dev;
error:
if (dev && (dev->reg_state == NETREG_UNREGISTERED))
free_netdev(dev);
priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
return NULL;
} }
EXPORT_SYMBOL_GPL(mwifiex_add_virtual_intf); EXPORT_SYMBOL_GPL(mwifiex_add_virtual_intf);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment