soundwire: stream: fix an invalid free
PATCH 1/1 soundwire: stream: fix an invalid free
From: Tom Rix <[email protected]>
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.
--- drivers/soundwire/stream.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soundwire/stream.c +1 -1
@@ -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 ; }
Signature · 1 line
2.18.1
Vinod Koul
maintainerHello Tom,
Quoted 34 lines · On 05-09-20, 12:26, [email protected] wrote:
From: Tom Rix <[email protected]>
clang static analyzer reports this problem
stream.c:872:2: warning: Argument to
kfree()is a constant
address (18446744073709551092), which is not memory allocated bymalloc()kfree(stream); ^~~~~~~~~~~~~In
sdw_shutdown_stream()the stream to free is set by a call tosnd_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 <[email protected]>--- drivers/soundwire/stream.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/soundwire/stream.c +0
-0
drivers/soundwire/stream.c void sdw_shutdown_stream(void *sdw_substream) · line 1916
Quoted 5 lines
drivers/soundwire/stream.c +1
-1@@ -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.
Signature · 1 line
~Vinod
Quoted 40 lines · Vinod Koul
Hello Tom,
Quoted 37 lines · On 05-09-20, 12:26, [email protected] wrote:
From: Tom Rix <[email protected]>
clang static analyzer reports this problem
stream.c:872:2: warning: Argument to
kfree()is a constant
address (18446744073709551092), which is not memory allocated bymalloc()kfree(stream); ^~~~~~~~~~~~~In
sdw_shutdown_stream()the stream to free is set by a call tosnd_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 <[email protected]>--- drivers/soundwire/stream.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/soundwire/stream.c +0
-0@@ -1913,7 +1913,7 @@ void sdw_shutdown_stream(void *sdw_substream) sdw_stream =snd_soc_dai_get_sdw_stream (dai, substream->stream);
Quoted 8 lines
drivers/soundwire/stream.c void sdw_shutdown_stream(void *sdw_substream) · line 1916
Quoted 2 lines
drivers/soundwire/stream.c +1
-1-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 toIS_ERR()and Bard has already sent patches forsnd_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
Quoted 1 line
Vinod Koul
maintainerQuoted 49 lines · Tom Rix
Quoted 47 lines · Vinod Koul
Hello Tom,
Quoted 34 lines · On 05-09-20, 12:26, [email protected] wrote:
From: Tom Rix <[email protected]>
clang static analyzer reports this problem
stream.c:872:2: warning: Argument to
kfree()is a constant
address (18446744073709551092), which is not memory allocated bymalloc()kfree(stream); ^~~~~~~~~~~~~In
sdw_shutdown_stream()the stream to free is set by a call tosnd_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 <[email protected]>--- drivers/soundwire/stream.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/soundwire/stream.c +0
-0drivers/soundwire/stream.c void sdw_shutdown_stream(void *sdw_substream) · line 1916
Quoted 5 lines
drivers/soundwire/stream.c +1
-1@@ -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 toIS_ERR()and Bard has already sent patches forsnd_soc_dai_get_sdw_stream()to return proper values.
Quoted 3 lines
Quoted 1 line
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
Quoted 2 lines
Sorry for not working on soundwire-next, but since i am fixing everywhere linux-next is easiest.
Agree, timing this time around!
Signature · 1 line
~Vinod