mwifiex: resolve suspend() race with async FW init failure
authorBrian Norris <briannorris@chromium.org>
Fri, 18 Nov 2016 14:00:29 +0000 (19:30 +0530)
committerKalle Valo <kvalo@codeaurora.org>
Sat, 19 Nov 2016 07:18:49 +0000 (09:18 +0200)
Signed-off-by: Brian Norris <briannorris@chromium.org>
Tested-by: Xinming Hu <huxm@marvell.com>
Signed-off-by: Amitkumar Karwar <akarwar@marvell.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
drivers/net/wireless/marvell/mwifiex/pcie.c
drivers/net/wireless/marvell/mwifiex/sdio.c
drivers/net/wireless/marvell/mwifiex/usb.c

index cecf1a076640862032b88740f6e1c46d527e2d16..6176cb78d9d674b8cb2148dd9ca128df694b0286 100644 (file)
@@ -118,12 +118,20 @@ static int mwifiex_pcie_suspend(struct device *dev)
        struct pci_dev *pdev = to_pci_dev(dev);
 
        card = pci_get_drvdata(pdev);
-       if (!card || !card->adapter) {
-               pr_err("Card or adapter structure is not valid\n");
+       if (!card) {
+               dev_err(dev, "card structure is not valid\n");
                return 0;
        }
 
+       /* Might still be loading firmware */
+       wait_for_completion(&card->fw_done);
+
        adapter = card->adapter;
+       if (!adapter) {
+               dev_err(dev, "adapter is not valid\n");
+               return 0;
+       }
+
        mwifiex_enable_wake(adapter);
 
        /* Enable the Host Sleep */
index 2f5b01fbc04e7034099e52229549d0077e51c4a4..5077d56b1bd493a03446a0b5d75d48850ed8ee2f 100644 (file)
@@ -283,8 +283,8 @@ static int mwifiex_sdio_suspend(struct device *dev)
                }
 
                card = sdio_get_drvdata(func);
-               if (!card || !card->adapter) {
-                       pr_err("suspend: invalid card or adapter\n");
+               if (!card) {
+                       dev_err(dev, "suspend: invalid card\n");
                        return 0;
                }
        } else {
@@ -292,7 +292,15 @@ static int mwifiex_sdio_suspend(struct device *dev)
                return 0;
        }
 
+       /* Might still be loading firmware */
+       wait_for_completion(&card->fw_done);
+
        adapter = card->adapter;
+       if (!adapter) {
+               dev_err(dev, "adapter is not valid\n");
+               return 0;
+       }
+
        mwifiex_enable_wake(adapter);
 
        /* Enable the Host Sleep */
index 45c9430aaf90797f79a9ab688006178126276fd8..64a40205201d12507b05be5033ff5db2ce79d8b2 100644 (file)
@@ -503,11 +503,19 @@ static int mwifiex_usb_suspend(struct usb_interface *intf, pm_message_t message)
        struct usb_tx_data_port *port;
        int i, j;
 
-       if (!card || !card->adapter) {
-               pr_err("%s: card or card->adapter is NULL\n", __func__);
+       if (!card) {
+               dev_err(&intf->dev, "%s: card is NULL\n", __func__);
                return 0;
        }
+
+       /* Might still be loading firmware */
+       wait_for_completion(&card->fw_done);
+
        adapter = card->adapter;
+       if (!adapter) {
+               dev_err(&intf->dev, "card is not valid\n");
+               return 0;
+       }
 
        if (unlikely(adapter->is_suspended))
                mwifiex_dbg(adapter, WARN,