From patchwork Wed Sep 14 16:32:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Berg X-Patchwork-Id: 9331971 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6F3EF6077A for ; Wed, 14 Sep 2016 16:33:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 60BBA2A1C3 for ; Wed, 14 Sep 2016 16:33:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5521E2A1C8; Wed, 14 Sep 2016 16:33:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F2FBC2A1C3 for ; Wed, 14 Sep 2016 16:33:17 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bkD7R-0000hg-46; Wed, 14 Sep 2016 16:33:05 +0000 Received: from s3.sipsolutions.net ([5.9.151.49] helo=sipsolutions.net) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bkD7O-0000b5-3i for ath10k@lists.infradead.org; Wed, 14 Sep 2016 16:33:03 +0000 Received: by sipsolutions.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.87) (envelope-from ) id 1bkD6z-0005zn-DF; Wed, 14 Sep 2016 18:32:37 +0200 From: Benjamin Berg To: "Valo, Kalle" Subject: [PATCH] ath10k: Fix spinlock use in coverage class hack Date: Wed, 14 Sep 2016 18:32:31 +0200 Message-Id: <20160914163231.20863-1-benjamin@sipsolutions.net> X-Mailer: git-send-email 2.9.3 In-Reply-To: <8760q0j8st.fsf@kamboji.qca.qualcomm.com> References: <8760q0j8st.fsf@kamboji.qca.qualcomm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160914_093302_348193_8BEE836E X-CRM114-Status: UNSURE ( 9.78 ) X-CRM114-Notice: Please train this message. X-BeenThere: ath10k@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Simon Wunderlich , "Thiagarajan, Vasanthakumar" , Benjamin Berg , linux-wireless@vger.kernel.org, Sebastian Gottschall , "ath10k @ lists . infradead . org" , michal.kazior@tieto.com, Mathias Kretschmer MIME-Version: 1.0 Sender: "ath10k" Errors-To: ath10k-bounces+patchwork-ath10k=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP ath10k_hw_qca988x_set_coverage_class needs to hold both conf_mutex and the data_lock spin lock for parts of the function. However, data_lock is only needed while storing the coverage_class to store the value that the card is configured to. Fix the locking issue by only holding data_lock for the required duration. Signed-off-by: Benjamin Berg --- And yes, I fully agree with your points of it being rather fragile. But as you said, it should be entirely safe if not used. Obviously a firmware implementation would be preferential. This locking issue was pretty unnecessary. Lets see if any more issues show up in a closer review. drivers/net/wireless/ath/ath10k/core.h | 2 +- drivers/net/wireless/ath/ath10k/hw.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/ath/ath10k/core.h b/drivers/net/wireless/ath/ath10k/core.h index 89b07be..5f8c31f 100644 --- a/drivers/net/wireless/ath/ath10k/core.h +++ b/drivers/net/wireless/ath/ath10k/core.h @@ -915,7 +915,7 @@ struct ath10k { struct work_struct set_coverage_class_work; /* protected by conf_mutex */ struct { - /* protected by data_lock */ + /* writing also protected by data_lock */ s16 coverage_class; u32 reg_phyclk; diff --git a/drivers/net/wireless/ath/ath10k/hw.c b/drivers/net/wireless/ath/ath10k/hw.c index e182f09..bd5ca6a 100644 --- a/drivers/net/wireless/ath/ath10k/hw.c +++ b/drivers/net/wireless/ath/ath10k/hw.c @@ -243,7 +243,6 @@ static void ath10k_hw_qca988x_set_coverage_class(struct ath10k *ar, u32 fw_dbglog_level; mutex_lock(&ar->conf_mutex); - spin_lock_bh(&ar->data_lock); /* Only modify registers if the core is started. */ if ((ar->state != ATH10K_STATE_ON) && @@ -356,12 +355,14 @@ static void ath10k_hw_qca988x_set_coverage_class(struct ath10k *ar, store_regs: /* After an error we will not retry setting the coverage class. */ + spin_lock_bh(&ar->data_lock); ar->fw_coverage.coverage_class = value; + spin_unlock_bh(&ar->data_lock); + ar->fw_coverage.reg_slottime_conf = slottime_reg; ar->fw_coverage.reg_ack_cts_timeout_conf = timeout_reg; unlock: - spin_unlock_bh(&ar->data_lock); mutex_unlock(&ar->conf_mutex); }