From patchwork Thu May 19 03:53:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei-Ning Huang X-Patchwork-Id: 9123771 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 18BC69F30C for ; Thu, 19 May 2016 03:54:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2D7892022A for ; Thu, 19 May 2016 03:54:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 449DB201FA for ; Thu, 19 May 2016 03:54:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752272AbcESDyE (ORCPT ); Wed, 18 May 2016 23:54:04 -0400 Received: from mail-pf0-f169.google.com ([209.85.192.169]:33404 "EHLO mail-pf0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752240AbcESDyB (ORCPT ); Wed, 18 May 2016 23:54:01 -0400 Received: by mail-pf0-f169.google.com with SMTP id 206so25577105pfu.0 for ; Wed, 18 May 2016 20:54:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=TO0xL2ADcBvjfwhdvFaWfw0kiw14G0apyw6l+xk1PwQ=; b=O3qKJlMMmqq7Nmd1mBhID81wc/jO1cLSwFqt7504bmO3LBpHaqQsSntSL5tO/WZ3xw tc9F8x9Ea2EhIXNWGDFLBU60A2DrZztP3mseomaBq3iw9fiIU9u7ZsdRBUIVwzX4Jc7C LdJ/7pJ9uB37euJSgZyPhBq+Tm8WiQ0nzsXlI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=TO0xL2ADcBvjfwhdvFaWfw0kiw14G0apyw6l+xk1PwQ=; b=SzL76REaFrGIJcCftT70f30cjU9TkXIdPWl4b5YmBFv23z0pHjiZiwOR0Mv/Vy+g5h ZzjUbQhxITL8q95Mc762capOmx/mjASWn+pTUOkJljoC0gMyqi/UQwaqoB0MRYKSDFnn 1f3pPUoVHVk1h9D2nmWMd0mrmT0L7nk2yz2P95C4uCdN0+MQXRgm7USKtZ8BmmXvRbed 9WTI5JDUv5JXJnYF4NUZjHY6vH5864tYDgmX9wwCZzM0dr1/EIy7oYvf/fFexxnnMEyw odKq/5Ufbl3+lI9hQKmj9ZSpaesqd+VYCATIfjdKQ67Gat4h5QEdbuANWckUytduWO/b m2Tw== X-Gm-Message-State: AOPr4FVIvZTrUkvajhirJ0PaWtisQFb1go0FrUFwysKspTcQs1UFv/JidFADnAiDyxNl5aNf X-Received: by 10.98.35.15 with SMTP id j15mr674987pfj.108.1463630040732; Wed, 18 May 2016 20:54:00 -0700 (PDT) Received: from wnhuang0.tpe.corp.google.com ([172.30.210.18]) by smtp.gmail.com with ESMTPSA id p1sm15620030paz.8.2016.05.18.20.53.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 May 2016 20:54:00 -0700 (PDT) From: Wei-Ning Huang To: Linux-Wireless Cc: LKML , akarwar@marvell.com, djkurtz@chromium.org, Wei-Ning Huang Subject: [PATCH] mwifiex: fix racing condition when downloading firmware Date: Thu, 19 May 2016 11:53:43 +0800 Message-Id: <1463630023-5258-1-git-send-email-wnhuang@chromium.org> X-Mailer: git-send-email 2.1.2 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The action 'check for winner' and 'download firmware' should be an atomic action. This is true for btmrvl driver but not mwmfiex, which cause firmware download to fail when the following senerio happens: 1) mwifiex check winner status: true 2) btmrvl check winner status: true, and start downloading firmware 3) mwfieix tries to download firmware, but failed because btmrvl is already downloading. This won't happen if 1) and 3) is an atomic action. This patch adds sdio_claim/release_host call around those two actions to make sure it's atomic. Signed-off-by: Wei-Ning Huang --- drivers/net/wireless/marvell/mwifiex/main.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/marvell/mwifiex/main.c b/drivers/net/wireless/marvell/mwifiex/main.c index 8b67a55..2b65334 100644 --- a/drivers/net/wireless/marvell/mwifiex/main.c +++ b/drivers/net/wireless/marvell/mwifiex/main.c @@ -21,6 +21,7 @@ #include "wmm.h" #include "cfg80211.h" #include "11n.h" +#include "sdio.h" #define VERSION "1.0" @@ -514,6 +515,7 @@ static void mwifiex_fw_dpc(const struct firmware *firmware, void *context) struct semaphore *sem = adapter->card_sem; bool init_failed = false; struct wireless_dev *wdev; + struct sdio_mmc_card *card = adapter->card; if (!firmware) { mwifiex_dbg(adapter, ERROR, @@ -526,10 +528,16 @@ static void mwifiex_fw_dpc(const struct firmware *firmware, void *context) fw.fw_buf = (u8 *) adapter->firmware->data; fw.fw_len = adapter->firmware->size; - if (adapter->if_ops.dnld_fw) + if (adapter->if_ops.dnld_fw) { ret = adapter->if_ops.dnld_fw(adapter, &fw); - else + } else { + if (adapter->iface_type == MWIFIEX_SDIO) + sdio_claim_host(card->func); ret = mwifiex_dnld_fw(adapter, &fw); + if (adapter->iface_type == MWIFIEX_SDIO) + sdio_release_host(card->func); + } + if (ret == -1) goto err_dnld_fw;