From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7251F1FCCFB; Fri, 6 Dec 2024 15:14:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733498056; cv=none; b=MkTzz3XjfZWTjfs0fE6iZyV1phbxezrTgSvEiJ4T+ggAstVjXsjBGwtkQ6vs3KgLmHGu9Hh7qR8C1dLkXBYNw1Hl4ONjWkdVOOiEKdWzfvkROg8EwTxxWJndZPBa8Ql2RvWmPhy9aAqJ09nESeO+LbWNMDQg0xX1UHg4Yy2AMos= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733498056; c=relaxed/simple; bh=uLDP5L8g7FDdOrTdqeraFwoCdsL5fpBKhXxw76/3Qkc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O9UWQLhIx3JQRz8EwFQoC4qe/i8G2ryt8Soij2rHclRo+4J81eyTUyVI5VRU/rLSbQw6h6Pmqp6Mij8HBNkfN2nGW30q7a7b5hW4RSZZ6u1iCKRpsWBL2bnlZeP+5iuzanmf6TtsCFrfxpk+cDOPT9HV7e41ucG6+fdANTc5Gnw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=fDn+05sH; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="fDn+05sH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D310CC4CED1; Fri, 6 Dec 2024 15:14:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1733498056; bh=uLDP5L8g7FDdOrTdqeraFwoCdsL5fpBKhXxw76/3Qkc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fDn+05sH7sKc8E8U7HUdHnmjj2diXvXhmMmvtVl/M7kFRazebys7JrqOEsxDElrGz Xbb5glig5wi6v2HOaCQB2E64Z7G4A19foeuyClkXlUP9Dygs2JcpMSzShMZilR7AMo 6fHtQd2fbEJ3qwQhsDDt4AlPNit0EJsW7d/skIXs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Qiu-ji Chen , Mark Brown Subject: [PATCH 6.6 473/676] ASoC: codecs: Fix atomicity violation in snd_soc_component_get_drvdata() Date: Fri, 6 Dec 2024 15:34:52 +0100 Message-ID: <20241206143711.842274639@linuxfoundation.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241206143653.344873888@linuxfoundation.org> References: <20241206143653.344873888@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Qiu-ji Chen commit 1157733344651ca505e259d6554591ff156922fa upstream. An atomicity violation occurs when the validity of the variables da7219->clk_src and da7219->mclk_rate is being assessed. Since the entire assessment is not protected by a lock, the da7219 variable might still be in flux during the assessment, rendering this check invalid. To fix this issue, we recommend adding a lock before the block if ((da7219->clk_src == clk_id) && (da7219->mclk_rate == freq)) so that the legitimacy check for da7219->clk_src and da7219->mclk_rate is protected by the lock, ensuring the validity of the check. This possible bug is found by an experimental static analysis tool developed by our team. This tool analyzes the locking APIs to extract function pairs that can be concurrently executed, and then analyzes the instructions in the paired functions to identify possible concurrency bugs including data races and atomicity violations. Fixes: 6d817c0e9fd7 ("ASoC: codecs: Add da7219 codec driver") Cc: stable@vger.kernel.org Signed-off-by: Qiu-ji Chen Link: https://patch.msgid.link/20240930101216.23723-1-chenqiuji666@gmail.com Signed-off-by: Mark Brown Signed-off-by: Greg Kroah-Hartman --- sound/soc/codecs/da7219.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) --- a/sound/soc/codecs/da7219.c +++ b/sound/soc/codecs/da7219.c @@ -1167,17 +1167,20 @@ static int da7219_set_dai_sysclk(struct struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); int ret = 0; - if ((da7219->clk_src == clk_id) && (da7219->mclk_rate == freq)) + mutex_lock(&da7219->pll_lock); + + if ((da7219->clk_src == clk_id) && (da7219->mclk_rate == freq)) { + mutex_unlock(&da7219->pll_lock); return 0; + } if ((freq < 2000000) || (freq > 54000000)) { + mutex_unlock(&da7219->pll_lock); dev_err(codec_dai->dev, "Unsupported MCLK value %d\n", freq); return -EINVAL; } - mutex_lock(&da7219->pll_lock); - switch (clk_id) { case DA7219_CLKSRC_MCLK_SQR: snd_soc_component_update_bits(component, DA7219_PLL_CTRL,