Linux kernel staging patches
 help / color / mirror / Atom feed
* [PATCH v2] staging: greybus: audio: check sscanf() result directly
@ 2026-06-14  6:08 abdelnasser hussein
  2026-06-14  6:15 ` Greg Kroah-Hartman
  2026-06-15  7:21 ` Dan Carpenter
  0 siblings, 2 replies; 5+ messages in thread
From: abdelnasser hussein @ 2026-06-14  6:08 UTC (permalink / raw)
  To: Vaibhav Agarwal, Mark Greer, Johan Hovold, Alex Elder,
	Greg Kroah-Hartman
  Cc: greybus-dev, linux-staging, linux-kernel, abdelnasser hussein,
	kernel test robot

Smatch warns:

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

sscanf() returns the number of successfully matched input items, not a
negative error code. Compare the return value directly with the expected
number of conversions instead of storing it in ret as an error code.

Also remove the redundant else-if check for snd_soc_dapm_aif_out. The
widget id is validated earlier in the function, so the remaining branch
can only handle snd_soc_dapm_aif_out. This avoids a compiler warning
about a potentially uninitialized variable.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202606140347.gGVWDnbi-lkp@intel.com/

Signed-off-by: abdelnasser hussein <abdelnasserhussein11@gmail.com>
---
 drivers/staging/greybus/audio_codec.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/greybus/audio_codec.c b/drivers/staging/greybus/audio_codec.c
index 720aa752e17e..6daa4e706792 100644
--- a/drivers/staging/greybus/audio_codec.c
+++ b/drivers/staging/greybus/audio_codec.c
@@ -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;
 	}
@@ -323,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
-- 
2.54.0


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

* Re: [PATCH v2] staging: greybus: audio: check sscanf() result directly
  2026-06-14  6:08 [PATCH v2] staging: greybus: audio: check sscanf() result directly abdelnasser hussein
@ 2026-06-14  6:15 ` Greg Kroah-Hartman
  2026-06-14  8:42   ` nasser
  2026-06-15  7:21 ` Dan Carpenter
  1 sibling, 1 reply; 5+ messages in thread
From: Greg Kroah-Hartman @ 2026-06-14  6:15 UTC (permalink / raw)
  To: abdelnasser hussein
  Cc: Vaibhav Agarwal, Mark Greer, Johan Hovold, Alex Elder,
	greybus-dev, linux-staging, linux-kernel, kernel test robot

On Sun, Jun 14, 2026 at 09:08:57AM +0300, abdelnasser hussein wrote:
> Smatch warns:
> 
>   drivers/staging/greybus/audio_codec.c:335 gbaudio_module_update()
>   warn: sscanf doesn't return error codes
> 
> sscanf() returns the number of successfully matched input items, not a
> negative error code. Compare the return value directly with the expected
> number of conversions instead of storing it in ret as an error code.
> 
> Also remove the redundant else-if check for snd_soc_dapm_aif_out. The
> widget id is validated earlier in the function, so the remaining branch
> can only handle snd_soc_dapm_aif_out. This avoids a compiler warning
> about a potentially uninitialized variable.

When you say "also" that implies it should be a separate patch.

> 
> Reported-by: kernel test robot <lkp@intel.com>

lkp didn't report the smatch warning :(

> Closes: https://lore.kernel.org/oe-kbuild-all/202606140347.gGVWDnbi-lkp@intel.com/
> 
> Signed-off-by: abdelnasser hussein <abdelnasserhussein11@gmail.com>
> ---
>  drivers/staging/greybus/audio_codec.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)

No list of what changed from previous versions?

thanks,

greg k-h

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

* Re: [PATCH v2] staging: greybus: audio: check sscanf() result directly
  2026-06-14  6:15 ` Greg Kroah-Hartman
@ 2026-06-14  8:42   ` nasser
  0 siblings, 0 replies; 5+ messages in thread
From: nasser @ 2026-06-14  8:42 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Vaibhav Agarwal, Mark Greer, Johan Hovold, Alex Elder,
	greybus-dev, linux-staging, linux-kernel, kernel test robot

Hi Greg,

Thanks for the review and the feedback.

On Sun, Jun 14, 2026 at 06:15:00AM +0000, Greg Kroah-Hartman wrote:
> When you say "also" that implies it should be a separate patch.

Understood. I will split these changes into a two-patch series in v3.

> lkp didn't report the smatch warning :(

My mistake. I will fix the Reported-by and Closes tags in the next
version to correctly reflect the source of the warning.

> No list of what changed from previous versions?

I apologize for missing that. I will make sure to include a proper
changelog below the '---' line for v3.

I will send the v3 patch series shortly.

Thanks,
Abdelnasser


On Sun, Jun 14, 2026 at 9:17 AM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
>
> On Sun, Jun 14, 2026 at 09:08:57AM +0300, abdelnasser hussein wrote:
> > Smatch warns:
> >
> >   drivers/staging/greybus/audio_codec.c:335 gbaudio_module_update()
> >   warn: sscanf doesn't return error codes
> >
> > sscanf() returns the number of successfully matched input items, not a
> > negative error code. Compare the return value directly with the expected
> > number of conversions instead of storing it in ret as an error code.
> >
> > Also remove the redundant else-if check for snd_soc_dapm_aif_out. The
> > widget id is validated earlier in the function, so the remaining branch
> > can only handle snd_soc_dapm_aif_out. This avoids a compiler warning
> > about a potentially uninitialized variable.
>
> When you say "also" that implies it should be a separate patch.
>
> >
> > Reported-by: kernel test robot <lkp@intel.com>
>
> lkp didn't report the smatch warning :(
>
> > Closes: https://lore.kernel.org/oe-kbuild-all/202606140347.gGVWDnbi-lkp@intel.com/
> >
> > Signed-off-by: abdelnasser hussein <abdelnasserhussein11@gmail.com>
> > ---
> >  drivers/staging/greybus/audio_codec.c | 5 ++---
> >  1 file changed, 2 insertions(+), 3 deletions(-)
>
> No list of what changed from previous versions?
>
> thanks,
>
> greg k-h

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

* Re: [PATCH v2] staging: greybus: audio: check sscanf() result directly
  2026-06-14  6:08 [PATCH v2] staging: greybus: audio: check sscanf() result directly abdelnasser hussein
  2026-06-14  6:15 ` Greg Kroah-Hartman
@ 2026-06-15  7:21 ` Dan Carpenter
  2026-06-15  7:40   ` nasser
  1 sibling, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2026-06-15  7:21 UTC (permalink / raw)
  To: abdelnasser hussein
  Cc: Vaibhav Agarwal, Mark Greer, Johan Hovold, Alex Elder,
	Greg Kroah-Hartman, greybus-dev, linux-staging, linux-kernel,
	kernel test robot

On Sun, Jun 14, 2026 at 09:08:57AM +0300, abdelnasser hussein wrote:
> Smatch warns:
> 
>   drivers/staging/greybus/audio_codec.c:335 gbaudio_module_update()
>   warn: sscanf doesn't return error codes
> 
> sscanf() returns the number of successfully matched input items, not a
> negative error code. Compare the return value directly with the expected
> number of conversions instead of storing it in ret as an error code.
> 
> Also remove the redundant else-if check for snd_soc_dapm_aif_out. The
> widget id is validated earlier in the function, so the remaining branch
> can only handle snd_soc_dapm_aif_out. This avoids a compiler warning
> about a potentially uninitialized variable.
> 
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202606140347.gGVWDnbi-lkp@intel.com/
> 
> Signed-off-by: abdelnasser hussein <abdelnasserhussein11@gmail.com>
> ---

This static checker warning is triggered when we propagate the return
from sscanf().

>  drivers/staging/greybus/audio_codec.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/staging/greybus/audio_codec.c b/drivers/staging/greybus/audio_codec.c
> index 720aa752e17e..6daa4e706792 100644
> --- a/drivers/staging/greybus/audio_codec.c
> +++ b/drivers/staging/greybus/audio_codec.c
> @@ -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;

So this code is fine as-is since it's returning -EINVAL.

>  	}
> @@ -323,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 {

Yes, this is what the static checker is complaining about.  It thinks
that the if statement might be false.  But to a human reader, the
else if or the plain else are equivalent.  It's just a style choice
which way to write it.

I would just leave this as-is since the original code is fine.  To be
honest, most old static checker warnings are stuff that someone
already decided to leave as is.

It's better to write new checks.  Just look for simple fixes in git
log and then you can vibe code a check.  Better to work against the
devel branch of smatch.

regards,
dan carpenter

>  		if (enable)
>  			ret = gbaudio_module_enable_rx(codec, module, dai_id);
>  		else



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

* Re: [PATCH v2] staging: greybus: audio: check sscanf() result directly
  2026-06-15  7:21 ` Dan Carpenter
@ 2026-06-15  7:40   ` nasser
  0 siblings, 0 replies; 5+ messages in thread
From: nasser @ 2026-06-15  7:40 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Vaibhav Agarwal, Mark Greer, Johan Hovold, Alex Elder,
	Greg Kroah-Hartman, greybus-dev, linux-staging, linux-kernel,
	kernel test robot

Hi Dan,

Thanks a lot for the explanation and the valuable information. I will
definitely take your advice, learn from this, and focus on tackling
more important issues going forward.

Best regards,
Abdelnasser


On Mon, Jun 15, 2026 at 10:21 AM Dan Carpenter <error27@gmail.com> wrote:
>
> On Sun, Jun 14, 2026 at 09:08:57AM +0300, abdelnasser hussein wrote:
> > Smatch warns:
> >
> >   drivers/staging/greybus/audio_codec.c:335 gbaudio_module_update()
> >   warn: sscanf doesn't return error codes
> >
> > sscanf() returns the number of successfully matched input items, not a
> > negative error code. Compare the return value directly with the expected
> > number of conversions instead of storing it in ret as an error code.
> >
> > Also remove the redundant else-if check for snd_soc_dapm_aif_out. The
> > widget id is validated earlier in the function, so the remaining branch
> > can only handle snd_soc_dapm_aif_out. This avoids a compiler warning
> > about a potentially uninitialized variable.
> >
> > Reported-by: kernel test robot <lkp@intel.com>
> > Closes: https://lore.kernel.org/oe-kbuild-all/202606140347.gGVWDnbi-lkp@intel.com/
> >
> > Signed-off-by: abdelnasser hussein <abdelnasserhussein11@gmail.com>
> > ---
>
> This static checker warning is triggered when we propagate the return
> from sscanf().
>
> >  drivers/staging/greybus/audio_codec.c | 5 ++---
> >  1 file changed, 2 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/staging/greybus/audio_codec.c b/drivers/staging/greybus/audio_codec.c
> > index 720aa752e17e..6daa4e706792 100644
> > --- a/drivers/staging/greybus/audio_codec.c
> > +++ b/drivers/staging/greybus/audio_codec.c
> > @@ -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;
>
> So this code is fine as-is since it's returning -EINVAL.
>
> >       }
> > @@ -323,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 {
>
> Yes, this is what the static checker is complaining about.  It thinks
> that the if statement might be false.  But to a human reader, the
> else if or the plain else are equivalent.  It's just a style choice
> which way to write it.
>
> I would just leave this as-is since the original code is fine.  To be
> honest, most old static checker warnings are stuff that someone
> already decided to leave as is.
>
> It's better to write new checks.  Just look for simple fixes in git
> log and then you can vibe code a check.  Better to work against the
> devel branch of smatch.
>
> regards,
> dan carpenter
>
> >               if (enable)
> >                       ret = gbaudio_module_enable_rx(codec, module, dai_id);
> >               else
>
>

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

end of thread, other threads:[~2026-06-15  7:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-14  6:08 [PATCH v2] staging: greybus: audio: check sscanf() result directly abdelnasser hussein
2026-06-14  6:15 ` Greg Kroah-Hartman
2026-06-14  8:42   ` nasser
2026-06-15  7:21 ` Dan Carpenter
2026-06-15  7:40   ` nasser

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox