linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] ASoC: rsnd: check for zero node count
@ 2021-06-02 10:37 Colin King
  2021-06-02 11:21 ` Dan Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: Colin King @ 2021-06-02 10:37 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Kuninori Morimoto, alsa-devel
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

The call to rsnd_node_count can potentially return a zero node count
so add a check for this corner case. (Note that the two other calls
to rsnd_node_count in the kernel perform this check, so I think it
justifies adding this). This avoids using a zero nr in a devm_kcalloc
call.

Addresses-Coverity: ("Unchecked return value")
Fixes: c413983eb66a ("ASoC: rsnd: adjust disabled module")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 sound/soc/sh/rcar/ssiu.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/sound/soc/sh/rcar/ssiu.c b/sound/soc/sh/rcar/ssiu.c
index 5682c74bb7ff..0d8f97633dd2 100644
--- a/sound/soc/sh/rcar/ssiu.c
+++ b/sound/soc/sh/rcar/ssiu.c
@@ -515,6 +515,9 @@ int rsnd_ssiu_probe(struct rsnd_priv *priv)
 	else
 		nr = priv->ssi_nr;
 
+	if (!nr)
+		return -EINVAL;
+
 	ssiu	= devm_kcalloc(dev, nr, sizeof(*ssiu), GFP_KERNEL);
 	if (!ssiu)
 		return -ENOMEM;
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH][next] ASoC: rsnd: check for zero node count
  2021-06-02 10:37 [PATCH][next] ASoC: rsnd: check for zero node count Colin King
@ 2021-06-02 11:21 ` Dan Carpenter
  2021-06-02 22:19   ` Kuninori Morimoto
  2021-06-03 10:44   ` Colin Ian King
  0 siblings, 2 replies; 4+ messages in thread
From: Dan Carpenter @ 2021-06-02 11:21 UTC (permalink / raw)
  To: Colin King
  Cc: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Kuninori Morimoto, alsa-devel, kernel-janitors, linux-kernel

On Wed, Jun 02, 2021 at 11:37:22AM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The call to rsnd_node_count can potentially return a zero node count
> so add a check for this corner case. (Note that the two other calls
> to rsnd_node_count in the kernel perform this check, so I think it
> justifies adding this). This avoids using a zero nr in a devm_kcalloc
> call.

I don't have a problem with the patch, but really the code works fine
as is.  A better commit message is:

  Most callers of_get_child_count() check that "nr" is non-zero so it
  causes a static checker warning when we don't do that here.  This
  doesn't cause a problem or a crash, but having zero SSUIes (What's
  plural of ssui?) doesn't make sense either so let's add a check.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH][next] ASoC: rsnd: check for zero node count
  2021-06-02 11:21 ` Dan Carpenter
@ 2021-06-02 22:19   ` Kuninori Morimoto
  2021-06-03 10:44   ` Colin Ian King
  1 sibling, 0 replies; 4+ messages in thread
From: Kuninori Morimoto @ 2021-06-02 22:19 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Colin King, Liam Girdwood, Mark Brown, Jaroslav Kysela,
	Takashi Iwai, alsa-devel, kernel-janitors, linux-kernel


Hi

> > From: Colin Ian King <colin.king@canonical.com>
> > 
> > The call to rsnd_node_count can potentially return a zero node count
> > so add a check for this corner case. (Note that the two other calls
> > to rsnd_node_count in the kernel perform this check, so I think it
> > justifies adding this). This avoids using a zero nr in a devm_kcalloc
> > call.
> 
> I don't have a problem with the patch, but really the code works fine
> as is.  A better commit message is:
> 
>   Most callers of_get_child_count() check that "nr" is non-zero so it
>   causes a static checker warning when we don't do that here.  This
>   doesn't cause a problem or a crash, but having zero SSUIes (What's
>   plural of ssui?) doesn't make sense either so let's add a check.

For the code

	Acked-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>


Thank you for your help !!

Best regards
---
Kuninori Morimoto

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH][next] ASoC: rsnd: check for zero node count
  2021-06-02 11:21 ` Dan Carpenter
  2021-06-02 22:19   ` Kuninori Morimoto
@ 2021-06-03 10:44   ` Colin Ian King
  1 sibling, 0 replies; 4+ messages in thread
From: Colin Ian King @ 2021-06-03 10:44 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Kuninori Morimoto, alsa-devel, kernel-janitors, linux-kernel

On 02/06/2021 12:21, Dan Carpenter wrote:
> On Wed, Jun 02, 2021 at 11:37:22AM +0100, Colin King wrote:
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> The call to rsnd_node_count can potentially return a zero node count
>> so add a check for this corner case. (Note that the two other calls
>> to rsnd_node_count in the kernel perform this check, so I think it
>> justifies adding this). This avoids using a zero nr in a devm_kcalloc
>> call.
> 
> I don't have a problem with the patch, but really the code works fine
> as is.  A better commit message is:
> 
>   Most callers of_get_child_count() check that "nr" is non-zero so it
>   causes a static checker warning when we don't do that here.  This
>   doesn't cause a problem or a crash, but having zero SSUIes (What's
>   plural of ssui?) doesn't make sense either so let's add a check.

Good idea. I'll send a V2. Thanks Dan.

> 
> regards,
> dan carpenter
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-06-03 10:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-02 10:37 [PATCH][next] ASoC: rsnd: check for zero node count Colin King
2021-06-02 11:21 ` Dan Carpenter
2021-06-02 22:19   ` Kuninori Morimoto
2021-06-03 10:44   ` Colin Ian King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).