Skip to content

Commit c8618d6

Browse files
Xiaomeng Tongbroonie
authored andcommitted
ASoC: rt5682: fix an incorrect NULL check on list iterator
The bug is here: if (!dai) { The list iterator value 'dai' will *always* be set and non-NULL by for_each_component_dais(), so it is incorrect to assume that the iterator value will be NULL if the list is empty or no element is found (In fact, it will be a bogus pointer to an invalid struct object containing the HEAD). Otherwise it will bypass the check 'if (!dai) {' (never call dev_err() and never return -ENODEV;) and lead to invalid memory access lately when calling 'rt5682_set_bclk1_ratio(dai, factor);'. To fix the bug, just return rt5682_set_bclk1_ratio(dai, factor); when found the 'dai', otherwise dev_err() and return -ENODEV; Cc: [email protected] Fixes: ebbfabc ("ASoC: rt5682: Add CCF usage for providing I2S clks") Signed-off-by: Xiaomeng Tong <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent f730a46 commit c8618d6

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

sound/soc/codecs/rt5682.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2822,14 +2822,11 @@ static int rt5682_bclk_set_rate(struct clk_hw *hw, unsigned long rate,
28222822

28232823
for_each_component_dais(component, dai)
28242824
if (dai->id == RT5682_AIF1)
2825-
break;
2826-
if (!dai) {
2827-
dev_err(rt5682->i2c_dev, "dai %d not found in component\n",
2828-
RT5682_AIF1);
2829-
return -ENODEV;
2830-
}
2825+
return rt5682_set_bclk1_ratio(dai, factor);
28312826

2832-
return rt5682_set_bclk1_ratio(dai, factor);
2827+
dev_err(rt5682->i2c_dev, "dai %d not found in component\n",
2828+
RT5682_AIF1);
2829+
return -ENODEV;
28332830
}
28342831

28352832
static const struct clk_ops rt5682_dai_clk_ops[RT5682_DAI_NUM_CLKS] = {

0 commit comments

Comments
 (0)