linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ALSA: usb-audio: Fix missing return assignment
@ 2021-03-24 17:26 Muhammad Usama Anjum
  2021-03-24 18:50 ` Dan Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: Muhammad Usama Anjum @ 2021-03-24 17:26 UTC (permalink / raw)
  To: Jaroslav Kysela, Takashi Iwai, alsa-devel, linux-kernel,
	kernel-janitors, colin.king, dan.carpenter
  Cc: musamaanjum, linux-kernel

Return value of usb_driver_claim_interface should not be ignored.
Instead it should be stored in err variable and returned from
this function.

Signed-off-by: Muhammad Usama Anjum <musamaanjum@gmail.com>
---
 sound/usb/quirks.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
index 9e5e37eff10e..dd32ceaef18a 100644
--- a/sound/usb/quirks.c
+++ b/sound/usb/quirks.c
@@ -427,10 +427,10 @@ static int create_autodetect_quirks(struct snd_usb_audio *chip,
 
 		err = create_autodetect_quirk(chip, iface, driver);
 		if (err >= 0)
-			usb_driver_claim_interface(driver, iface, (void *)-1L);
+			err = usb_driver_claim_interface(driver, iface, (void *)-1L);
 	}
 
-	return 0;
+	return err;
 }
 
 /*
-- 
2.25.1


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

* Re: [PATCH] ALSA: usb-audio: Fix missing return assignment
  2021-03-24 17:26 [PATCH] ALSA: usb-audio: Fix missing return assignment Muhammad Usama Anjum
@ 2021-03-24 18:50 ` Dan Carpenter
  2021-03-24 20:24   ` Muhammad Usama Anjum
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2021-03-24 18:50 UTC (permalink / raw)
  To: Muhammad Usama Anjum
  Cc: Jaroslav Kysela, Takashi Iwai, alsa-devel, linux-kernel,
	kernel-janitors, colin.king

On Wed, Mar 24, 2021 at 10:26:04PM +0500, Muhammad Usama Anjum wrote:
> Return value of usb_driver_claim_interface should not be ignored.
> Instead it should be stored in err variable and returned from
> this function.
> 
> Signed-off-by: Muhammad Usama Anjum <musamaanjum@gmail.com>
> ---
>  sound/usb/quirks.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
> index 9e5e37eff10e..dd32ceaef18a 100644
> --- a/sound/usb/quirks.c
> +++ b/sound/usb/quirks.c
> @@ -427,10 +427,10 @@ static int create_autodetect_quirks(struct snd_usb_audio *chip,
>  
>  		err = create_autodetect_quirk(chip, iface, driver);
>  		if (err >= 0)

create_autodetect_quirk() never returns positive values.  Flip this
condition.  (Always do error handling, don't do success handling).

		if (err)
			continue;


> -			usb_driver_claim_interface(driver, iface, (void *)-1L);
> +			err = usb_driver_claim_interface(driver, iface, (void *)-1L);

This is in a loop so only the last return value is used.  Which seems
sort of weird and pointless that the last value would matter more than
the others.

>  	}
>  
> -	return 0;
> +	return err;

regards,
dan carpenter


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

* Re: [PATCH] ALSA: usb-audio: Fix missing return assignment
  2021-03-24 18:50 ` Dan Carpenter
@ 2021-03-24 20:24   ` Muhammad Usama Anjum
  2021-03-25  7:07     ` Dan Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: Muhammad Usama Anjum @ 2021-03-24 20:24 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Jaroslav Kysela, Takashi Iwai, alsa-devel, linux-kernel,
	kernel-janitors, colin.king

On Wed, 2021-03-24 at 21:50 +0300, Dan Carpenter wrote:
> On Wed, Mar 24, 2021 at 10:26:04PM +0500, Muhammad Usama Anjum wrote:
> > Return value of usb_driver_claim_interface should not be ignored.
> > Instead it should be stored in err variable and returned from
> > this function.
> > 
> > Signed-off-by: Muhammad Usama Anjum <musamaanjum@gmail.com>
> > ---
> >  sound/usb/quirks.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
> > index 9e5e37eff10e..dd32ceaef18a 100644
> > --- a/sound/usb/quirks.c
> > +++ b/sound/usb/quirks.c
> > @@ -427,10 +427,10 @@ static int create_autodetect_quirks(struct snd_usb_audio *chip,
> >  
> >  		err = create_autodetect_quirk(chip, iface, driver);
> >  		if (err >= 0)
> 
> create_autodetect_quirk() never returns positive values.  Flip this
> condition.  (Always do error handling, don't do success handling).
> 
> 		if (err)
> 			continue;

Got it. I'll send a patch.
> 
> 
> > -			usb_driver_claim_interface(driver, iface, (void *)-1L);
> > +			err = usb_driver_claim_interface(driver, iface, (void *)-1L);
> 
> This is in a loop so only the last return value is used.  Which seems
> sort of weird and pointless that the last value would matter more than
> the others.
> 
Correct. Lets not store the return value. To stop the static analyzers
to report the missing return assignment, can we add (void) in start of
this function call? I've not seen use of (void) this way in the
kernel. Is there any other way used in the kernel?

> >  	}
> >  
> > -	return 0;
> > +	return err;
> 
> regards,
> dan carpenter
> 


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

* Re: [PATCH] ALSA: usb-audio: Fix missing return assignment
  2021-03-24 20:24   ` Muhammad Usama Anjum
@ 2021-03-25  7:07     ` Dan Carpenter
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2021-03-25  7:07 UTC (permalink / raw)
  To: Muhammad Usama Anjum
  Cc: Jaroslav Kysela, Takashi Iwai, alsa-devel, linux-kernel,
	kernel-janitors, colin.king

On Thu, Mar 25, 2021 at 01:24:23AM +0500, Muhammad Usama Anjum wrote:
> On Wed, 2021-03-24 at 21:50 +0300, Dan Carpenter wrote:
> > > -			usb_driver_claim_interface(driver, iface, (void *)-1L);
> > > +			err = usb_driver_claim_interface(driver, iface, (void *)-1L);
> > 
> > This is in a loop so only the last return value is used.  Which seems
> > sort of weird and pointless that the last value would matter more than
> > the others.
> > 
> Correct. Lets not store the return value. To stop the static analyzers
> to report the missing return assignment, can we add (void) in start of
> this function call? I've not seen use of (void) this way in the
> kernel. Is there any other way used in the kernel?

Don't add (void).  Don't add any code just to help static checkers, only
do it if it helps humans.  The (void) stuff is ugly.  We have a
__must_check annotation for functions where it's a bug not to check the
return and the usb_driver_claim_interface() is not a __must_check
function.  Just ignore the static checker when it's wrong.

When I'm reviewing static checker warnings, I only look at the new ones.
Then after I've looked at them, I mark them as old.  I currently have
65k old ignored warnings.

regards,
dan carpenter


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

end of thread, other threads:[~2021-03-25  7:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-24 17:26 [PATCH] ALSA: usb-audio: Fix missing return assignment Muhammad Usama Anjum
2021-03-24 18:50 ` Dan Carpenter
2021-03-24 20:24   ` Muhammad Usama Anjum
2021-03-25  7:07     ` Dan Carpenter

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).