Return-Path: Received: from mail-bl2nam02on0137.outbound.protection.outlook.com ([104.47.38.137]:29088 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S935071AbeCSQES (ORCPT ); Mon, 19 Mar 2018 12:04:18 -0400 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Johannes Berg , Luca Coelho , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 205/281] iwlwifi: tt: move ucode_loaded check under mutex Date: Mon, 19 Mar 2018 16:01:56 +0000 Message-ID: <20180319155742.13731-205-alexander.levin@microsoft.com> References: <20180319155742.13731-1-alexander.levin@microsoft.com> In-Reply-To: <20180319155742.13731-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Johannes Berg [ Upstream commit d9954405758a0cbbe258d9b4d4dc12a06fa48a28 ] The ucode_loaded check should be under the mutex, since it can otherwise change state after we looked at it and before we got the mutex. Fix that. Fixes: 5c89e7bc557e ("iwlwifi: mvm: add registration to cooling device") Signed-off-by: Johannes Berg Signed-off-by: Luca Coelho Signed-off-by: Sasha Levin --- drivers/net/wireless/intel/iwlwifi/mvm/tt.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/tt.c b/drivers/net/wire= less/intel/iwlwifi/mvm/tt.c index bec7d9c46087..c5203568a47a 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/tt.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/tt.c @@ -790,11 +790,13 @@ static int iwl_mvm_tcool_set_cur_state(struct thermal= _cooling_device *cdev, struct iwl_mvm *mvm =3D (struct iwl_mvm *)(cdev->devdata); int ret; =20 - if (!mvm->ucode_loaded || !(mvm->cur_ucode =3D=3D IWL_UCODE_REGULAR)) - return -EIO; - mutex_lock(&mvm->mutex); =20 + if (!mvm->ucode_loaded || !(mvm->cur_ucode =3D=3D IWL_UCODE_REGULAR)) { + ret =3D -EIO; + goto unlock; + } + if (new_state >=3D ARRAY_SIZE(iwl_mvm_cdev_budgets)) { ret =3D -EINVAL; goto unlock; --=20 2.14.1