All of lore.kernel.org
 help / color / mirror / Atom feed
From: Krzysztof Kozlowski <krzk@kernel.org>
To: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Cc: tiwai@suse.de, alsa-devel@alsa-project.org, broonie@kernel.org
Subject: Re: [PATCH 5/6] ASoC: samsung: tm2_wm5110: check of_parse return value
Date: Sun, 21 Feb 2021 12:10:55 +0100	[thread overview]
Message-ID: <20210221111055.nfzr5nzvskdc3jyq@kozik-lap> (raw)
In-Reply-To: <20210219230918.5058-6-pierre-louis.bossart@linux.intel.com>

On Fri, Feb 19, 2021 at 05:09:17PM -0600, Pierre-Louis Bossart wrote:
> cppcheck warning:
> 
> sound/soc/samsung/tm2_wm5110.c:605:6: style: Variable 'ret' is
> reassigned a value before the old one has been
> used. [redundantAssignment]
>  ret = devm_snd_soc_register_component(dev, &tm2_component,
>      ^
> sound/soc/samsung/tm2_wm5110.c:554:7: note: ret is assigned
>   ret = of_parse_phandle_with_args(dev->of_node, "i2s-controller",
>       ^
> sound/soc/samsung/tm2_wm5110.c:605:6: note: ret is overwritten
>  ret = devm_snd_soc_register_component(dev, &tm2_component,
>      ^
> 
> it seems wise to first test the return value before checking if the
> returned argument is not null?

Actually this is real bug. The args is a stack variable, so it could
have junk (uninitialized) therefore args.np could have a non-NULL and
random value even though property was missing. Later could trigger
invalid pointer dereference.

  Fixes: 8d1513cef51a ("ASoC: samsung: Add support for HDMI audio on TM2 board")
  Cc: <stable@vger.kernel.org>

> 
> Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
> ---
>  sound/soc/samsung/tm2_wm5110.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/sound/soc/samsung/tm2_wm5110.c b/sound/soc/samsung/tm2_wm5110.c
> index 9300fef9bf26..da6204248f82 100644
> --- a/sound/soc/samsung/tm2_wm5110.c
> +++ b/sound/soc/samsung/tm2_wm5110.c
> @@ -553,7 +553,7 @@ static int tm2_probe(struct platform_device *pdev)
>  
>  		ret = of_parse_phandle_with_args(dev->of_node, "i2s-controller",
>  						 cells_name, i, &args);
> -		if (!args.np) {
> +		if (ret || !args.np) {

Only "if (ret)" because args.np won't be initialized on errors.

Best regards,
Krzysztof

  reply	other threads:[~2021-02-21 11:12 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-19 23:09 [PATCH 0/6] ASoC: samsung: remove cppcheck warnings Pierre-Louis Bossart
2021-02-19 23:09 ` [PATCH 1/6] ASoC: samsung: i2s: remove unassigned variable Pierre-Louis Bossart
2021-02-21 10:53   ` Krzysztof Kozlowski
2021-02-19 23:09 ` [PATCH 2/6] ASoC: samsung: s3c24xx_simtec: add missing error check Pierre-Louis Bossart
2021-02-21 10:55   ` Krzysztof Kozlowski
2021-02-19 23:09 ` [PATCH 3/6] ASoC: samsung: smdk_wm8994: add missing return Pierre-Louis Bossart
2021-02-21 10:59   ` Krzysztof Kozlowski
2021-02-19 23:09 ` [PATCH 4/6] ASoC: samsung: snow: remove useless test Pierre-Louis Bossart
2021-02-21 11:04   ` Krzysztof Kozlowski
2021-02-19 23:09 ` [PATCH 5/6] ASoC: samsung: tm2_wm5110: check of_parse return value Pierre-Louis Bossart
2021-02-21 11:10   ` Krzysztof Kozlowski [this message]
2021-02-22 15:35     ` Pierre-Louis Bossart
2021-02-22 17:28       ` Krzysztof Kozlowski
2021-02-19 23:09 ` [PATCH 6/6] ASoC: samsung: tm2_wm5510: remove shadowing variable Pierre-Louis Bossart
2021-02-21 11:12   ` Krzysztof Kozlowski
2021-02-22 15:36     ` Pierre-Louis Bossart
2021-02-23 11:30   ` Sylwester Nawrocki
2021-02-22 16:07 ` (subset) [PATCH 0/6] ASoC: samsung: remove cppcheck warnings Mark Brown
2021-02-22 17:31   ` Krzysztof Kozlowski
2021-02-22 20:19     ` Mark Brown
2021-02-22 20:39       ` Pierre-Louis Bossart
2021-03-01 23:34 ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210221111055.nfzr5nzvskdc3jyq@kozik-lap \
    --to=krzk@kernel.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.