Skip to content

Commit 1157733

Browse files
TomRita999broonie
authored andcommitted
ASoC: codecs: Fix atomicity violation in snd_soc_component_get_drvdata()
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: 6d817c0 ("ASoC: codecs: Add da7219 codec driver") Cc: [email protected] Signed-off-by: Qiu-ji Chen <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 1590988 commit 1157733

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

sound/soc/codecs/da7219.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,17 +1167,20 @@ static int da7219_set_dai_sysclk(struct snd_soc_dai *codec_dai,
11671167
struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component);
11681168
int ret = 0;
11691169

1170-
if ((da7219->clk_src == clk_id) && (da7219->mclk_rate == freq))
1170+
mutex_lock(&da7219->pll_lock);
1171+
1172+
if ((da7219->clk_src == clk_id) && (da7219->mclk_rate == freq)) {
1173+
mutex_unlock(&da7219->pll_lock);
11711174
return 0;
1175+
}
11721176

11731177
if ((freq < 2000000) || (freq > 54000000)) {
1178+
mutex_unlock(&da7219->pll_lock);
11741179
dev_err(codec_dai->dev, "Unsupported MCLK value %d\n",
11751180
freq);
11761181
return -EINVAL;
11771182
}
11781183

1179-
mutex_lock(&da7219->pll_lock);
1180-
11811184
switch (clk_id) {
11821185
case DA7219_CLKSRC_MCLK_SQR:
11831186
snd_soc_component_update_bits(component, DA7219_PLL_CTRL,

0 commit comments

Comments
 (0)