All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH][next] ALSA: usb-audio: Fix sum of uninitialized variable sample_accum
@ 2021-10-01 10:44 Colin King
  2021-10-01 10:48   ` Takashi Iwai
  0 siblings, 1 reply; 5+ messages in thread
From: Colin King @ 2021-10-01 10:44 UTC (permalink / raw)
  To: Jaroslav Kysela, Takashi Iwai, Alexander Tsoy, alsa-devel
  Cc: kernel-janitors, linux-kernel

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

Variable sample_accum is not being intialized and then has
ep->sample_rem added to it, leading to a bogus value. One solution
is to initialize it to zero at declaration time, but it is probably
best to just assign it to ep->sample_rem on first use.

Addresses-Coveriry: ("Uninitialized scalar variable")
Fixes: f0bd62b64016 ("ALSA: usb-audio: Improve frames size computation")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 sound/usb/endpoint.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c
index 42c0d2db8ba8..c6a33732db3f 100644
--- a/sound/usb/endpoint.c
+++ b/sound/usb/endpoint.c
@@ -182,7 +182,7 @@ static int next_packet_size(struct snd_usb_endpoint *ep, unsigned int avail)
 	if (ep->fill_max)
 		return ep->maxframesize;
 
-	sample_accum += ep->sample_rem;
+	sample_accum = ep->sample_rem;
 	if (sample_accum >= ep->pps) {
 		sample_accum -= ep->pps;
 		ret = ep->packsize[1];
-- 
2.32.0


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

* Re: [PATCH][next] ALSA: usb-audio: Fix sum of uninitialized variable sample_accum
  2021-10-01 10:44 [PATCH][next] ALSA: usb-audio: Fix sum of uninitialized variable sample_accum Colin King
@ 2021-10-01 10:48   ` Takashi Iwai
  0 siblings, 0 replies; 5+ messages in thread
From: Takashi Iwai @ 2021-10-01 10:48 UTC (permalink / raw)
  To: Colin King
  Cc: alsa-devel, kernel-janitors, linux-kernel, Takashi Iwai,
	Alexander Tsoy

On Fri, 01 Oct 2021 12:44:17 +0200,
Colin King wrote:
> 
> From: Colin Ian King <colin.king@canonical.com>
> 
> Variable sample_accum is not being intialized and then has
> ep->sample_rem added to it, leading to a bogus value. One solution
> is to initialize it to zero at declaration time, but it is probably
> best to just assign it to ep->sample_rem on first use.
> 
> Addresses-Coveriry: ("Uninitialized scalar variable")
> Fixes: f0bd62b64016 ("ALSA: usb-audio: Improve frames size computation")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Thanks for the patch, but it's no right fix.  The Fixes tag points to
a wrong commit, it was d215f63d49da9a8803af3e81acd6cad743686573
    ALSA: usb-audio: Check available frames for the next packet size
  
And sample_accum has to be initialized from ep->sample_accum instead.
I'll post the proper fix.


Takashi


> ---
>  sound/usb/endpoint.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c
> index 42c0d2db8ba8..c6a33732db3f 100644
> --- a/sound/usb/endpoint.c
> +++ b/sound/usb/endpoint.c
> @@ -182,7 +182,7 @@ static int next_packet_size(struct snd_usb_endpoint *ep, unsigned int avail)
>  	if (ep->fill_max)
>  		return ep->maxframesize;
>  
> -	sample_accum += ep->sample_rem;
> +	sample_accum = ep->sample_rem;
>  	if (sample_accum >= ep->pps) {
>  		sample_accum -= ep->pps;
>  		ret = ep->packsize[1];
> -- 
> 2.32.0
> 

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

* Re: [PATCH][next] ALSA: usb-audio: Fix sum of uninitialized variable sample_accum
@ 2021-10-01 10:48   ` Takashi Iwai
  0 siblings, 0 replies; 5+ messages in thread
From: Takashi Iwai @ 2021-10-01 10:48 UTC (permalink / raw)
  To: Colin King
  Cc: Jaroslav Kysela, Takashi Iwai, Alexander Tsoy, alsa-devel,
	kernel-janitors, linux-kernel

On Fri, 01 Oct 2021 12:44:17 +0200,
Colin King wrote:
> 
> From: Colin Ian King <colin.king@canonical.com>
> 
> Variable sample_accum is not being intialized and then has
> ep->sample_rem added to it, leading to a bogus value. One solution
> is to initialize it to zero at declaration time, but it is probably
> best to just assign it to ep->sample_rem on first use.
> 
> Addresses-Coveriry: ("Uninitialized scalar variable")
> Fixes: f0bd62b64016 ("ALSA: usb-audio: Improve frames size computation")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Thanks for the patch, but it's no right fix.  The Fixes tag points to
a wrong commit, it was d215f63d49da9a8803af3e81acd6cad743686573
    ALSA: usb-audio: Check available frames for the next packet size
  
And sample_accum has to be initialized from ep->sample_accum instead.
I'll post the proper fix.


Takashi


> ---
>  sound/usb/endpoint.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c
> index 42c0d2db8ba8..c6a33732db3f 100644
> --- a/sound/usb/endpoint.c
> +++ b/sound/usb/endpoint.c
> @@ -182,7 +182,7 @@ static int next_packet_size(struct snd_usb_endpoint *ep, unsigned int avail)
>  	if (ep->fill_max)
>  		return ep->maxframesize;
>  
> -	sample_accum += ep->sample_rem;
> +	sample_accum = ep->sample_rem;
>  	if (sample_accum >= ep->pps) {
>  		sample_accum -= ep->pps;
>  		ret = ep->packsize[1];
> -- 
> 2.32.0
> 

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

* Re: [PATCH][next] ALSA: usb-audio: Fix sum of uninitialized variable sample_accum
  2021-10-01 10:48   ` Takashi Iwai
@ 2021-10-01 11:07     ` Colin Ian King
  -1 siblings, 0 replies; 5+ messages in thread
From: Colin Ian King @ 2021-10-01 11:07 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: alsa-devel, kernel-janitors, linux-kernel, Takashi Iwai,
	Alexander Tsoy

On 01/10/2021 11:48, Takashi Iwai wrote:
> On Fri, 01 Oct 2021 12:44:17 +0200,
> Colin King wrote:
>>
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> Variable sample_accum is not being intialized and then has
>> ep->sample_rem added to it, leading to a bogus value. One solution
>> is to initialize it to zero at declaration time, but it is probably
>> best to just assign it to ep->sample_rem on first use.
>>
>> Addresses-Coveriry: ("Uninitialized scalar variable")
>> Fixes: f0bd62b64016 ("ALSA: usb-audio: Improve frames size computation")
>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> 
> Thanks for the patch, but it's no right fix.  The Fixes tag points to
> a wrong commit, it was d215f63d49da9a8803af3e81acd6cad743686573
>      ALSA: usb-audio: Check available frames for the next packet size
>    
> And sample_accum has to be initialized from ep->sample_accum instead.
> I'll post the proper fix.

Thanks Takshi.

Colin

> 
> 
> Takashi
> 
> 
>> ---
>>   sound/usb/endpoint.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c
>> index 42c0d2db8ba8..c6a33732db3f 100644
>> --- a/sound/usb/endpoint.c
>> +++ b/sound/usb/endpoint.c
>> @@ -182,7 +182,7 @@ static int next_packet_size(struct snd_usb_endpoint *ep, unsigned int avail)
>>   	if (ep->fill_max)
>>   		return ep->maxframesize;
>>   
>> -	sample_accum += ep->sample_rem;
>> +	sample_accum = ep->sample_rem;
>>   	if (sample_accum >= ep->pps) {
>>   		sample_accum -= ep->pps;
>>   		ret = ep->packsize[1];
>> -- 
>> 2.32.0
>>


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

* Re: [PATCH][next] ALSA: usb-audio: Fix sum of uninitialized variable sample_accum
@ 2021-10-01 11:07     ` Colin Ian King
  0 siblings, 0 replies; 5+ messages in thread
From: Colin Ian King @ 2021-10-01 11:07 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: Jaroslav Kysela, Takashi Iwai, Alexander Tsoy, alsa-devel,
	kernel-janitors, linux-kernel

On 01/10/2021 11:48, Takashi Iwai wrote:
> On Fri, 01 Oct 2021 12:44:17 +0200,
> Colin King wrote:
>>
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> Variable sample_accum is not being intialized and then has
>> ep->sample_rem added to it, leading to a bogus value. One solution
>> is to initialize it to zero at declaration time, but it is probably
>> best to just assign it to ep->sample_rem on first use.
>>
>> Addresses-Coveriry: ("Uninitialized scalar variable")
>> Fixes: f0bd62b64016 ("ALSA: usb-audio: Improve frames size computation")
>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> 
> Thanks for the patch, but it's no right fix.  The Fixes tag points to
> a wrong commit, it was d215f63d49da9a8803af3e81acd6cad743686573
>      ALSA: usb-audio: Check available frames for the next packet size
>    
> And sample_accum has to be initialized from ep->sample_accum instead.
> I'll post the proper fix.

Thanks Takshi.

Colin

> 
> 
> Takashi
> 
> 
>> ---
>>   sound/usb/endpoint.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c
>> index 42c0d2db8ba8..c6a33732db3f 100644
>> --- a/sound/usb/endpoint.c
>> +++ b/sound/usb/endpoint.c
>> @@ -182,7 +182,7 @@ static int next_packet_size(struct snd_usb_endpoint *ep, unsigned int avail)
>>   	if (ep->fill_max)
>>   		return ep->maxframesize;
>>   
>> -	sample_accum += ep->sample_rem;
>> +	sample_accum = ep->sample_rem;
>>   	if (sample_accum >= ep->pps) {
>>   		sample_accum -= ep->pps;
>>   		ret = ep->packsize[1];
>> -- 
>> 2.32.0
>>


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

end of thread, other threads:[~2021-10-01 11:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-01 10:44 [PATCH][next] ALSA: usb-audio: Fix sum of uninitialized variable sample_accum Colin King
2021-10-01 10:48 ` Takashi Iwai
2021-10-01 10:48   ` Takashi Iwai
2021-10-01 11:07   ` Colin Ian King
2021-10-01 11:07     ` Colin Ian King

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.