Return-path: Received: from mx0a-0016f401.pphosted.com ([67.231.148.174]:53910 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S935962AbcJTN0x (ORCPT ); Thu, 20 Oct 2016 09:26:53 -0400 From: Amitkumar Karwar To: CC: Cathy Luo , Nishant Sarmukadam , , , Amitkumar Karwar Subject: [PATCH v5 3/4] mwifiex: check hw_status in suspend and resume handlers Date: Thu, 20 Oct 2016 18:56:18 +0530 Message-ID: <1476969979-28554-3-git-send-email-akarwar@marvell.com> (sfid-20161020_152656_864206_24E2E375) In-Reply-To: <1476969979-28554-1-git-send-email-akarwar@marvell.com> References: <1476969979-28554-1-git-send-email-akarwar@marvell.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-wireless-owner@vger.kernel.org List-ID: We have observed a kernel crash when system immediately suspends after booting. There is a race between suspend and driver initialization paths. This patch adds hw_status checks in suspend/resume to fix this issue and other corner cases. Signed-off-by: Amitkumar Karwar --- v2: Return failure in suspend/resume handler in this scenario. v3: Handle "hw_status" not READY cases carefully. Return 0 if init or shutdown is in progress. Return -EBUSY if firmware download failed or command timeout ocurred(non-recoverable). (Brian Norris) v4: In resume, we need not return failure. v5: Same as v4 --- drivers/net/wireless/marvell/mwifiex/pcie.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/marvell/mwifiex/pcie.c b/drivers/net/wireless/marvell/mwifiex/pcie.c index dd4006e..94f75be 100644 --- a/drivers/net/wireless/marvell/mwifiex/pcie.c +++ b/drivers/net/wireless/marvell/mwifiex/pcie.c @@ -104,13 +104,22 @@ 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 || !card->adapter || + card->adapter->hw_status == MWIFIEX_HW_STATUS_RESET || + card->adapter->hw_status == MWIFIEX_HW_STATUS_NOT_READY) { + pr_err("Card or adapter structure is not valid or hw_status shows failure\n"); return 0; } adapter = card->adapter; + if (adapter->hw_status == MWIFIEX_HW_STATUS_INITIALIZING || + adapter->hw_status == MWIFIEX_HW_STATUS_INIT_DONE || + adapter->hw_status == MWIFIEX_HW_STATUS_CLOSING) { + pr_err("We are in the middle of initialzaion or closing\n"); + return -EBUSY; + } + /* Enable the Host Sleep */ if (!mwifiex_enable_hs(adapter)) { mwifiex_dbg(adapter, ERROR, @@ -143,8 +152,10 @@ static int mwifiex_pcie_resume(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 || !card->adapter || + card->adapter->hw_status != MWIFIEX_HW_STATUS_READY) { + pr_err("Card or adapter structure is not valid or hw_status is not ready\n"); return 0; } -- 1.9.1