2022-01-11 01:32:47

by Jiasheng Jiang

[permalink] [raw]
Subject: [PATCH] ASoC: codecs: Check for error pointer after calling devm_regmap_init_mmio

The devm_regmap_init_mmio() may return error pointer under certain
circumstances, for example the possible failure of the kzalloc() in
regmap_mmio_gen_context(), which is called by devm_regmap_init_mmio().
Then the error pointer will be dereferenced.
For example rx->regmap will be used in rx_macro_mclk_enable().
Therefore, it should be better to check it.

Fixes: af3d54b99764 ("ASoC: codecs: lpass-rx-macro: add support for lpass rx macro")
Fixes: c39667ddcfc5 ("ASoC: codecs: lpass-tx-macro: add support for lpass tx macro")
Fixes: 809bcbcecebf ("ASoC: codecs: lpass-wsa-macro: Add support to WSA Macro")
Signed-off-by: Jiasheng Jiang <[email protected]>
---
sound/soc/codecs/lpass-rx-macro.c | 2 ++
sound/soc/codecs/lpass-tx-macro.c | 2 ++
sound/soc/codecs/lpass-wsa-macro.c | 2 ++
3 files changed, 6 insertions(+)

diff --git a/sound/soc/codecs/lpass-rx-macro.c b/sound/soc/codecs/lpass-rx-macro.c
index 07894ec5e7a6..2adbf2e2697f 100644
--- a/sound/soc/codecs/lpass-rx-macro.c
+++ b/sound/soc/codecs/lpass-rx-macro.c
@@ -3542,6 +3542,8 @@ static int rx_macro_probe(struct platform_device *pdev)
return PTR_ERR(base);

rx->regmap = devm_regmap_init_mmio(dev, base, &rx_regmap_config);
+ if (IS_ERR(rx->regmap))
+ return PTR_ERR(rx->regmap);

dev_set_drvdata(dev, rx);

diff --git a/sound/soc/codecs/lpass-tx-macro.c b/sound/soc/codecs/lpass-tx-macro.c
index 27a0d5defd27..e4bbc6bd4925 100644
--- a/sound/soc/codecs/lpass-tx-macro.c
+++ b/sound/soc/codecs/lpass-tx-macro.c
@@ -1803,6 +1803,8 @@ static int tx_macro_probe(struct platform_device *pdev)
return PTR_ERR(base);

tx->regmap = devm_regmap_init_mmio(dev, base, &tx_regmap_config);
+ if (IS_ERR(tx->regmap))
+ return PTR_ERR(tx->regmap);

dev_set_drvdata(dev, tx);

diff --git a/sound/soc/codecs/lpass-wsa-macro.c b/sound/soc/codecs/lpass-wsa-macro.c
index d3ac318fd6b6..dd1a8b7bc794 100644
--- a/sound/soc/codecs/lpass-wsa-macro.c
+++ b/sound/soc/codecs/lpass-wsa-macro.c
@@ -2405,6 +2405,8 @@ static int wsa_macro_probe(struct platform_device *pdev)
return PTR_ERR(base);

wsa->regmap = devm_regmap_init_mmio(dev, base, &wsa_regmap_config);
+ if (IS_ERR(wsa->regmap))
+ return PTR_ERR(wsa->regmap);

dev_set_drvdata(dev, wsa);

--
2.25.1



2022-01-12 09:48:18

by Srinivas Kandagatla

[permalink] [raw]
Subject: Re: [PATCH] ASoC: codecs: Check for error pointer after calling devm_regmap_init_mmio



On 11/01/2022 01:32, Jiasheng Jiang wrote:
> The devm_regmap_init_mmio() may return error pointer under certain
> circumstances, for example the possible failure of the kzalloc() in
> regmap_mmio_gen_context(), which is called by devm_regmap_init_mmio().
> Then the error pointer will be dereferenced.
> For example rx->regmap will be used in rx_macro_mclk_enable().
> Therefore, it should be better to check it.
>
> Fixes: af3d54b99764 ("ASoC: codecs: lpass-rx-macro: add support for lpass rx macro")
> Fixes: c39667ddcfc5 ("ASoC: codecs: lpass-tx-macro: add support for lpass tx macro")
> Fixes: 809bcbcecebf ("ASoC: codecs: lpass-wsa-macro: Add support to WSA Macro")
> Signed-off-by: Jiasheng Jiang <[email protected]>
Thanks for the patch,

LGTM,

Reviewed-by: Srinivas Kandagatla <[email protected]>

> ---
> sound/soc/codecs/lpass-rx-macro.c | 2 ++
> sound/soc/codecs/lpass-tx-macro.c | 2 ++
> sound/soc/codecs/lpass-wsa-macro.c | 2 ++
> 3 files changed, 6 insertions(+)
>
> diff --git a/sound/soc/codecs/lpass-rx-macro.c b/sound/soc/codecs/lpass-rx-macro.c
> index 07894ec5e7a6..2adbf2e2697f 100644
> --- a/sound/soc/codecs/lpass-rx-macro.c
> +++ b/sound/soc/codecs/lpass-rx-macro.c
> @@ -3542,6 +3542,8 @@ static int rx_macro_probe(struct platform_device *pdev)
> return PTR_ERR(base);
>
> rx->regmap = devm_regmap_init_mmio(dev, base, &rx_regmap_config);
> + if (IS_ERR(rx->regmap))
> + return PTR_ERR(rx->regmap);
>
> dev_set_drvdata(dev, rx);
>
> diff --git a/sound/soc/codecs/lpass-tx-macro.c b/sound/soc/codecs/lpass-tx-macro.c
> index 27a0d5defd27..e4bbc6bd4925 100644
> --- a/sound/soc/codecs/lpass-tx-macro.c
> +++ b/sound/soc/codecs/lpass-tx-macro.c
> @@ -1803,6 +1803,8 @@ static int tx_macro_probe(struct platform_device *pdev)
> return PTR_ERR(base);
>
> tx->regmap = devm_regmap_init_mmio(dev, base, &tx_regmap_config);
> + if (IS_ERR(tx->regmap))
> + return PTR_ERR(tx->regmap);
>
> dev_set_drvdata(dev, tx);
>
> diff --git a/sound/soc/codecs/lpass-wsa-macro.c b/sound/soc/codecs/lpass-wsa-macro.c
> index d3ac318fd6b6..dd1a8b7bc794 100644
> --- a/sound/soc/codecs/lpass-wsa-macro.c
> +++ b/sound/soc/codecs/lpass-wsa-macro.c
> @@ -2405,6 +2405,8 @@ static int wsa_macro_probe(struct platform_device *pdev)
> return PTR_ERR(base);
>
> wsa->regmap = devm_regmap_init_mmio(dev, base, &wsa_regmap_config);
> + if (IS_ERR(wsa->regmap))
> + return PTR_ERR(wsa->regmap);
>
> dev_set_drvdata(dev, wsa);
>
>

2022-01-12 14:20:45

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH] ASoC: codecs: Check for error pointer after calling devm_regmap_init_mmio

On Tue, Jan 11, 2022 at 09:32:15AM +0800, Jiasheng Jiang wrote:
> The devm_regmap_init_mmio() may return error pointer under certain
> circumstances, for example the possible failure of the kzalloc() in
> regmap_mmio_gen_context(), which is called by devm_regmap_init_mmio().

This doesn't apply against current code, please check and resend.


Attachments:
(No filename) (343.00 B)
signature.asc (488.00 B)
Download all attachments

2022-01-13 01:57:00

by Jiasheng Jiang

[permalink] [raw]
Subject: Re: Re: [PATCH] ASoC: codecs: Check for error pointer after calling devm_regmap_init_mmio

On Wed, Jan 12, 2022 at 10:20:34PM +0800, Mark Brown wrote:
>> The devm_regmap_init_mmio() may return error pointer under certain
>> circumstances, for example the possible failure of the kzalloc() in
>> regmap_mmio_gen_context(), which is called by devm_regmap_init_mmio().
>
> This doesn't apply against current code, please check and resend.

I checked linux-5.16, and don't think what I said is not against the
latest code.
The devm_regmap_init_mmio() is defined as devm_regmap_init_mmio_clk()
in `include/linux/regmap.h`.
And in the same file, the devm_regmap_init_mmio_clk() is defined as
__devm_regmap_init_mmio_clk().
Then, __devm_regmap_init_mmio_clk() -> regmap_mmio_gen_context() ->
kzalloc().
So I have no idea what's wrong.
Maybe I didn't write the commit message clear.
Please give me more detail.

Sincerely thanks,
Jiang


2022-01-13 13:12:09

by Mark Brown

[permalink] [raw]
Subject: Re: Re: [PATCH] ASoC: codecs: Check for error pointer after calling devm_regmap_init_mmio

On Thu, Jan 13, 2022 at 09:56:07AM +0800, Jiasheng Jiang wrote:
> On Wed, Jan 12, 2022 at 10:20:34PM +0800, Mark Brown wrote:

> > This doesn't apply against current code, please check and resend.

> I checked linux-5.16, and don't think what I said is not against the
> latest code.

No, that's several months out of date - you should be submitting against
the current development version. At this point v5.16 is released and
the bulk of the changes for v5.17 have already been sent.


Attachments:
(No filename) (486.00 B)
signature.asc (488.00 B)
Download all attachments

2022-01-25 14:47:40

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH] ASoC: codecs: Check for error pointer after calling devm_regmap_init_mmio

On Tue, 11 Jan 2022 09:32:15 +0800, Jiasheng Jiang wrote:
> The devm_regmap_init_mmio() may return error pointer under certain
> circumstances, for example the possible failure of the kzalloc() in
> regmap_mmio_gen_context(), which is called by devm_regmap_init_mmio().
> Then the error pointer will be dereferenced.
> For example rx->regmap will be used in rx_macro_mclk_enable().
> Therefore, it should be better to check it.
>
> [...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/1] ASoC: codecs: Check for error pointer after calling devm_regmap_init_mmio
commit: aa505ecccf2ae7546e0e262d574e18a9241f3005

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark