linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] soundwire: stream: fix an invalid free
@ 2020-09-05 19:26 trix
  2020-09-07 14:14 ` Vinod Koul
  0 siblings, 1 reply; 4+ messages in thread
From: trix @ 2020-09-05 19:26 UTC (permalink / raw)
  To: vkoul, yung-chuan.liao, pierre-louis.bossart, sanyog.r.kale,
	natechancellor, ndesaulniers, guennadi.liakhovetski,
	kai.vehmanen
  Cc: alsa-devel, linux-kernel, clang-built-linux, Tom Rix

From: Tom Rix <trix@redhat.com>

clang static analyzer reports this problem

stream.c:872:2: warning: Argument to kfree() is a constant
  address (18446744073709551092), which is not memory
  allocated by malloc()
        kfree(stream);
        ^~~~~~~~~~~~~

In sdw_shutdown_stream() the stream to free is set by
a call to snd_soc_dai_get_sdw_stream().  The problem block
is the check if the call was successful.

	if (!sdw_stream) {
		dev_err(rtd->dev, "no stream found...
		return;
	}

When snd_soc_dai_get_sdw_stream() fails, it does not
always return null, sometimes it returns -ENOTSUPP.

So also check for error codes.

Fixes: 4550569bd779 ("soundwire: stream: add helper to startup/shutdown streams")
Signed-off-by: Tom Rix <trix@redhat.com>
---
 drivers/soundwire/stream.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c
index 6e36deb505b1..950231d593c2 100644
--- a/drivers/soundwire/stream.c
+++ b/drivers/soundwire/stream.c
@@ -1913,7 +1913,7 @@ void sdw_shutdown_stream(void *sdw_substream)
 
 	sdw_stream = snd_soc_dai_get_sdw_stream(dai, substream->stream);
 
-	if (!sdw_stream) {
+	if (IS_ERR_OR_NULL(sdw_stream)) {
 		dev_err(rtd->dev, "no stream found for DAI %s", dai->name);
 		return;
 	}
-- 
2.18.1


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

* Re: [PATCH] soundwire: stream: fix an invalid free
  2020-09-05 19:26 [PATCH] soundwire: stream: fix an invalid free trix
@ 2020-09-07 14:14 ` Vinod Koul
  2020-09-07 14:25   ` Tom Rix
  0 siblings, 1 reply; 4+ messages in thread
From: Vinod Koul @ 2020-09-07 14:14 UTC (permalink / raw)
  To: trix
  Cc: yung-chuan.liao, pierre-louis.bossart, sanyog.r.kale,
	natechancellor, ndesaulniers, guennadi.liakhovetski,
	kai.vehmanen, alsa-devel, linux-kernel, clang-built-linux

Hello Tom,

On 05-09-20, 12:26, trix@redhat.com wrote:
> From: Tom Rix <trix@redhat.com>
> 
> clang static analyzer reports this problem
> 
> stream.c:872:2: warning: Argument to kfree() is a constant
>   address (18446744073709551092), which is not memory
>   allocated by malloc()
>         kfree(stream);
>         ^~~~~~~~~~~~~
> 
> In sdw_shutdown_stream() the stream to free is set by
> a call to snd_soc_dai_get_sdw_stream().  The problem block
> is the check if the call was successful.
> 
> 	if (!sdw_stream) {
> 		dev_err(rtd->dev, "no stream found...
> 		return;
> 	}
> 
> When snd_soc_dai_get_sdw_stream() fails, it does not
> always return null, sometimes it returns -ENOTSUPP.
> 
> So also check for error codes.
> Fixes: 4550569bd779 ("soundwire: stream: add helper to startup/shutdown streams")
> Signed-off-by: Tom Rix <trix@redhat.com>
> ---
>  drivers/soundwire/stream.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c
> index 6e36deb505b1..950231d593c2 100644
> --- a/drivers/soundwire/stream.c
> +++ b/drivers/soundwire/stream.c
> @@ -1913,7 +1913,7 @@ void sdw_shutdown_stream(void *sdw_substream)
>  
>  	sdw_stream = snd_soc_dai_get_sdw_stream(dai, substream->stream);
>  
> -	if (!sdw_stream) {
> +	if (IS_ERR_OR_NULL(sdw_stream)) {

Thanks for the patch. Please see commit 3471d2a192ba ("soundwire:
stream: fix NULL/IS_ERR confusion") in soundwire-next. This has already
been updated to IS_ERR() and Bard has already sent patches for
snd_soc_dai_get_sdw_stream() to return proper values.

So I you can rerun this on next, you should see this fixed.

-- 
~Vinod

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

* Re: [PATCH] soundwire: stream: fix an invalid free
  2020-09-07 14:14 ` Vinod Koul
@ 2020-09-07 14:25   ` Tom Rix
  2020-09-07 16:55     ` Vinod Koul
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Rix @ 2020-09-07 14:25 UTC (permalink / raw)
  To: Vinod Koul
  Cc: yung-chuan.liao, pierre-louis.bossart, sanyog.r.kale,
	natechancellor, ndesaulniers, guennadi.liakhovetski,
	kai.vehmanen, alsa-devel, linux-kernel, clang-built-linux


On 9/7/20 7:14 AM, Vinod Koul wrote:
> Hello Tom,
>
> On 05-09-20, 12:26, trix@redhat.com wrote:
>> From: Tom Rix <trix@redhat.com>
>>
>> clang static analyzer reports this problem
>>
>> stream.c:872:2: warning: Argument to kfree() is a constant
>>   address (18446744073709551092), which is not memory
>>   allocated by malloc()
>>         kfree(stream);
>>         ^~~~~~~~~~~~~
>>
>> In sdw_shutdown_stream() the stream to free is set by
>> a call to snd_soc_dai_get_sdw_stream().  The problem block
>> is the check if the call was successful.
>>
>> 	if (!sdw_stream) {
>> 		dev_err(rtd->dev, "no stream found...
>> 		return;
>> 	}
>>
>> When snd_soc_dai_get_sdw_stream() fails, it does not
>> always return null, sometimes it returns -ENOTSUPP.
>>
>> So also check for error codes.
>> Fixes: 4550569bd779 ("soundwire: stream: add helper to startup/shutdown streams")
>> Signed-off-by: Tom Rix <trix@redhat.com>
>> ---
>>  drivers/soundwire/stream.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c
>> index 6e36deb505b1..950231d593c2 100644
>> --- a/drivers/soundwire/stream.c
>> +++ b/drivers/soundwire/stream.c
>> @@ -1913,7 +1913,7 @@ void sdw_shutdown_stream(void *sdw_substream)
>>  
>>  	sdw_stream = snd_soc_dai_get_sdw_stream(dai, substream->stream);
>>  
>> -	if (!sdw_stream) {
>> +	if (IS_ERR_OR_NULL(sdw_stream)) {
> Thanks for the patch. Please see commit 3471d2a192ba ("soundwire:
> stream: fix NULL/IS_ERR confusion") in soundwire-next. This has already
> been updated to IS_ERR() and Bard has already sent patches for
> snd_soc_dai_get_sdw_stream() to return proper values.
>
> So I you can rerun this on next, you should see this fixed.

I am working on linux-next, so I will see Bard's patch when it lands there.

Sorry for not working on soundwire-next, but since i am fixing everywhere linux-next is easiest. 

Thank you for the update.

Tom

>


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

* Re: [PATCH] soundwire: stream: fix an invalid free
  2020-09-07 14:25   ` Tom Rix
@ 2020-09-07 16:55     ` Vinod Koul
  0 siblings, 0 replies; 4+ messages in thread
From: Vinod Koul @ 2020-09-07 16:55 UTC (permalink / raw)
  To: Tom Rix
  Cc: yung-chuan.liao, pierre-louis.bossart, sanyog.r.kale,
	natechancellor, ndesaulniers, guennadi.liakhovetski,
	kai.vehmanen, alsa-devel, linux-kernel, clang-built-linux

On 07-09-20, 07:25, Tom Rix wrote:
> 
> On 9/7/20 7:14 AM, Vinod Koul wrote:
> > Hello Tom,
> >
> > On 05-09-20, 12:26, trix@redhat.com wrote:
> >> From: Tom Rix <trix@redhat.com>
> >>
> >> clang static analyzer reports this problem
> >>
> >> stream.c:872:2: warning: Argument to kfree() is a constant
> >>   address (18446744073709551092), which is not memory
> >>   allocated by malloc()
> >>         kfree(stream);
> >>         ^~~~~~~~~~~~~
> >>
> >> In sdw_shutdown_stream() the stream to free is set by
> >> a call to snd_soc_dai_get_sdw_stream().  The problem block
> >> is the check if the call was successful.
> >>
> >> 	if (!sdw_stream) {
> >> 		dev_err(rtd->dev, "no stream found...
> >> 		return;
> >> 	}
> >>
> >> When snd_soc_dai_get_sdw_stream() fails, it does not
> >> always return null, sometimes it returns -ENOTSUPP.
> >>
> >> So also check for error codes.
> >> Fixes: 4550569bd779 ("soundwire: stream: add helper to startup/shutdown streams")
> >> Signed-off-by: Tom Rix <trix@redhat.com>
> >> ---
> >>  drivers/soundwire/stream.c | 2 +-
> >>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c
> >> index 6e36deb505b1..950231d593c2 100644
> >> --- a/drivers/soundwire/stream.c
> >> +++ b/drivers/soundwire/stream.c
> >> @@ -1913,7 +1913,7 @@ void sdw_shutdown_stream(void *sdw_substream)
> >>  
> >>  	sdw_stream = snd_soc_dai_get_sdw_stream(dai, substream->stream);
> >>  
> >> -	if (!sdw_stream) {
> >> +	if (IS_ERR_OR_NULL(sdw_stream)) {
> > Thanks for the patch. Please see commit 3471d2a192ba ("soundwire:
> > stream: fix NULL/IS_ERR confusion") in soundwire-next. This has already
> > been updated to IS_ERR() and Bard has already sent patches for
> > snd_soc_dai_get_sdw_stream() to return proper values.
> >
> > So I you can rerun this on next, you should see this fixed.
> 
> I am working on linux-next, so I will see Bard's patch when it lands there.

It should be already there... And I checked, looks like there was no
linux-next for last few days and it should be back tomorrow so should be
there

> 
> Sorry for not working on soundwire-next, but since i am fixing everywhere linux-next is easiest. 

Agree, timing this time around!

-- 
~Vinod

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

end of thread, other threads:[~2020-09-07 17:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-05 19:26 [PATCH] soundwire: stream: fix an invalid free trix
2020-09-07 14:14 ` Vinod Koul
2020-09-07 14:25   ` Tom Rix
2020-09-07 16:55     ` Vinod Koul

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