Skip to contentSkip to conversation

staging: greybus: audio: cleanups for gbaudio_module_update

PATCH In review Abdelnasser Hussein 2 participants 4 messages Jun 14 – Jun 15

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v3 cover staging: greybus: audio: cleanups for gbaudio_module_update

This patch series addresses two separate issues in gbaudio_module_update() that were previously combined in v2:

1. Fixes an improper check of the sscanf() return value (smatch warning).
2. Removes a redundant else-if check that could lead to an uninitialized variable warning for 'ret' (reported by kernel test robot).

Changes in v3:
- Split the changes into a 2-patch series based on feedback from Greg Kroah-Hartman.
- Assigned correct Reported-by and Closes tags to both patches.

abdelnasser hussein (2):
staging: greybus: audio_codec: fix sscanf return value check
staging: greybus: audio_codec: remove redundant else-if check

 drivers/staging/greybus/audio_codec.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
Signature · 1 line
2.54.0
#1 lore raw

PATCH v3 1/2 staging: greybus: audio_codec: fix sscanf return value check

Smatch static checker warns:
drivers/staging/greybus/audio_codec.c:335 gbaudio_module_update()
warn: sscanf doesn't return error codes

The sscanf() function returns the number of successfully matched input items, not a negative error code. Compare the return value directly with the expected number of conversions (3) instead of storing it in 'ret' and returning it as an error code, which leads to returning a positive value on failure.

---
Changes in v3:
- Split from the previous v2 patch into a separate patch.
- Updated tags to properly credit Dan Carpenter for the smatch warning.

 drivers/staging/greybus/audio_codec.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/greybus/audio_codec.c +1 -2
index 720aa752e17e..295222ec0f1a 100644
@@ -311,8 +311,7 @@ int gbaudio_module_update(struct gbaudio_codec_info *codec,
 	}
 
 	/* parse dai_id from AIF widget's stream_name */
-	ret = sscanf(w->sname, "%s %d %s", intf_name, &dai_id, dir);
-	if (ret < 3) {
+	if (sscanf(w->sname, "%s %d %s", intf_name, &dai_id, dir) != 3) {
 		dev_err(codec->dev, "Error while parsing dai_id for %s\n", w->name);
 		return -EINVAL;
 	}
Signature · 1 line
2.54.0
#2 lore raw

Re: [PATCH v3 1/2] staging: greybus: audio_codec: fix sscanf return value check

Quoted 10 lines · Abdelnasser Hussein

Smatch static checker warns:
drivers/staging/greybus/audio_codec.c:335 gbaudio_module_update()
warn: sscanf doesn't return error codes

The sscanf() function returns the number of successfully matched input items, not a negative error code. Compare the return value directly with the expected number of conversions (3) instead of storing it in 'ret' and returning it as an error code, which leads to returning a positive value on failure.

Quoted 4 lines

There shouldn't be a blank line in the middle of the tags block.

The closes tag isn't right...
https://lore.kernel.org/all/[email protected]/
Sorry, this stuff is a bit confusing to everyone who is not involved with the zero day bot. What happens is that for some warnings, they first send the warning to me and I look it over and decide whether or not it's valid. In this case, I decided it wasn't valid. Sure, I can understand why the static checker thinks we're propagating the return from sscanf() but actually the second else if is always true.

(I haven't actually checked that btw, I'm just assuming that the second else if is always true. Static analysis is always a best effort type of thing).

regards,
dan carpenter

#3 lore raw

PATCH v3 2/2 staging: greybus: audio_codec: remove redundant else-if check

In reply to Abdelnasser Hussein

In gbaudio_module_update(), the widget id is validated earlier in the function to ensure it is either snd_soc_dapm_aif_in or snd_soc_dapm_aif_out.

Remove the redundant else-if check for snd_soc_dapm_aif_out. The remaining branch can only handle snd_soc_dapm_aif_out, which avoids a compiler warning about a potentially uninitialized variable.

---
Changes in v3:
- Split from the previous v2 patch to address the uninitialized variable warning separately.

 drivers/staging/greybus/audio_codec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/greybus/audio_codec.c +1 -1
index 295222ec0f1a..6daa4e706792 100644
@@ -322,7 +322,7 @@ int gbaudio_module_update(struct gbaudio_codec_info *codec,
 			ret = gbaudio_module_enable_tx(codec, module, dai_id);
 		else
 			ret = gbaudio_module_disable_tx(module, dai_id);
-	} else if (w->id == snd_soc_dapm_aif_out) {
+	} else {
 		if (enable)
 			ret = gbaudio_module_enable_rx(codec, module, dai_id);
 		else
Signature · 1 line
2.54.0