UPSTREAM: mwifiex: fix wrong return values in add_virtual_intf() error cases
authorBing Zhao <bzhao@marvell.com>
Thu, 2 Aug 2012 21:52:20 +0000 (14:52 -0700)
committerGerrit <chrome-bot@google.com>
Fri, 3 Aug 2012 00:45:14 +0000 (17:45 -0700)
commit 858faa57dd9e2b91f3f870fbb1185982e42f5a2b upstream

add_virtual_intf() needs to return an ERR_PTR(), instead of NULL,
on errors, otherwise cfg80211 will crash.

Reported-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: Bing Zhao <bzhao@marvell.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
BUG=chrome-os-partner:12190
TEST=Build and run autotest WiFiMatFunc, WiFiSecMat, WiFiManager, WiFiPerf

Change-Id: I90c07d50d50f25476a0495b3beff6a9b3f74226d
Reviewed-on: https://gerrit.chromium.org/gerrit/29091
Reviewed-by: Sam Leffler <sleffler@chromium.org>
Tested-by: Bing Zhao <bzhao@marvell.com>
Commit-Ready: Bing Zhao <bzhao@marvell.com>

drivers/net/wireless/mwifiex/cfg80211.c

index bff30ee..d83c29f 100644 (file)
@@ -1300,11 +1300,11 @@ struct net_device *mwifiex_add_virtual_intf(struct wiphy *wiphy,
        void *mdev_priv;
 
        if (!priv)
-               return NULL;
+               return ERR_PTR(-EFAULT);
 
        adapter = priv->adapter;
        if (!adapter)
-               return NULL;
+               return ERR_PTR(-EFAULT);
 
        switch (type) {
        case NL80211_IFTYPE_UNSPECIFIED:
@@ -1313,7 +1313,7 @@ struct net_device *mwifiex_add_virtual_intf(struct wiphy *wiphy,
                if (priv->bss_mode) {
                        wiphy_err(wiphy, "cannot create multiple"
                                        " station/adhoc interfaces\n");
-                       return NULL;
+                       return ERR_PTR(-EINVAL);
                }
 
                if (type == NL80211_IFTYPE_UNSPECIFIED)
@@ -1330,14 +1330,15 @@ struct net_device *mwifiex_add_virtual_intf(struct wiphy *wiphy,
                break;
        default:
                wiphy_err(wiphy, "type not supported\n");
-               return NULL;
+               return ERR_PTR(-EINVAL);
        }
 
        dev = alloc_netdev_mq(sizeof(struct mwifiex_private *), name,
                              ether_setup, 1);
        if (!dev) {
                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));
@@ -1362,7 +1363,9 @@ struct net_device *mwifiex_add_virtual_intf(struct wiphy *wiphy,
        /* Register network device */
        if (register_netdevice(dev)) {
                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);
@@ -1374,12 +1377,6 @@ struct net_device *mwifiex_add_virtual_intf(struct wiphy *wiphy,
        mwifiex_dev_debugfs_init(priv);
 #endif
        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);