Skip to contentSkip to conversation

ASoC: rsnd: check for zero node count

PATCH Superseded Colin King 3 participants 4 messages Jun 2, 2021 – Jun 3, 2021

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 ASoC: rsnd: check for zero node count

From: Colin Ian King <[email protected]>

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")
---
 sound/soc/sh/rcar/ssiu.c | 3 +++
 1 file changed, 3 insertions(+)
sound/soc/sh/rcar/ssiu.c +3 -0
index 5682c74bb7ff..0d8f97633dd2 100644
@@ -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;
Signature · 1 line
2.31.1
#1 lore raw
Quoted 7 lines · Colin King

From: Colin Ian King <[email protected]>

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

#2 lore raw

Hi

Quoted 8 lines
Quoted 7 lines

From: Colin Ian King <[email protected]>

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.

Quoted 7 lines

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

Thank you for your help !!

Best regards
---
Kuninori Morimoto

#3 lore raw
In reply to Dan Carpenter
Quoted 9 lines · Dan Carpenter
Quoted 7 lines · Colin King

From: Colin Ian King <[email protected]>

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.

Quoted 7 lines

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.

Quoted 4 lines

regards,
dan carpenter