diff mbox series

[06/18] ALSA: compress_offload: dereference after checking for NULL pointer

Message ID 20200902212133.30964-7-pierre-louis.bossart@linux.intel.com
State Accepted
Commit cd91fd9f0af5453e66bda9984916ca67686689cf
Headers show
Series ALSA: cleanups for sparse/cppcheck warnings | expand

Commit Message

Pierre-Louis Bossart Sept. 2, 2020, 9:21 p.m. UTC
Fix cppcheck warning and only dereference once the initial checks are
done:

sound/core/compress_offload.c:516:38: warning: Either the condition
'!stream' is redundant or there is possible null pointer dereference:
stream. [nullPointerRedundantCheck]
 struct snd_compr_runtime *runtime = stream->runtime;
                                     ^
sound/core/compress_offload.c:518:17: note: Assuming that condition
'!stream' is not redundant
if (snd_BUG_ON(!(stream) || !(stream)->runtime))
                ^
sound/core/compress_offload.c:516:38: note: Null pointer dereference
 struct snd_compr_runtime *runtime = stream->runtime;
                                     ^

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
---
 sound/core/compress_offload.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Vinod Koul Sept. 3, 2020, 4:47 a.m. UTC | #1
On 02-09-20, 16:21, Pierre-Louis Bossart wrote:
> Fix cppcheck warning and only dereference once the initial checks are
> done:
> 
> sound/core/compress_offload.c:516:38: warning: Either the condition
> '!stream' is redundant or there is possible null pointer dereference:
> stream. [nullPointerRedundantCheck]
>  struct snd_compr_runtime *runtime = stream->runtime;
>                                      ^
> sound/core/compress_offload.c:518:17: note: Assuming that condition
> '!stream' is not redundant
> if (snd_BUG_ON(!(stream) || !(stream)->runtime))
>                 ^
> sound/core/compress_offload.c:516:38: note: Null pointer dereference
>  struct snd_compr_runtime *runtime = stream->runtime;
>                                      ^

Acked-By: Vinod Koul <vkoul@kernel.org>

> 
> Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
> ---
>  sound/core/compress_offload.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c
> index 0e53f6f31916..e3eb314acb10 100644
> --- a/sound/core/compress_offload.c
> +++ b/sound/core/compress_offload.c
> @@ -513,10 +513,11 @@ EXPORT_SYMBOL(snd_compr_malloc_pages);
>  
>  int snd_compr_free_pages(struct snd_compr_stream *stream)
>  {
> -	struct snd_compr_runtime *runtime = stream->runtime;
> +	struct snd_compr_runtime *runtime;
>  
>  	if (snd_BUG_ON(!(stream) || !(stream)->runtime))
>  		return -EINVAL;
> +	runtime = stream->runtime;
>  	if (runtime->dma_area == NULL)
>  		return 0;
>  	if (runtime->dma_buffer_p != &stream->dma_buffer) {
> -- 
> 2.25.1
diff mbox series

Patch

diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c
index 0e53f6f31916..e3eb314acb10 100644
--- a/sound/core/compress_offload.c
+++ b/sound/core/compress_offload.c
@@ -513,10 +513,11 @@  EXPORT_SYMBOL(snd_compr_malloc_pages);
 
 int snd_compr_free_pages(struct snd_compr_stream *stream)
 {
-	struct snd_compr_runtime *runtime = stream->runtime;
+	struct snd_compr_runtime *runtime;
 
 	if (snd_BUG_ON(!(stream) || !(stream)->runtime))
 		return -EINVAL;
+	runtime = stream->runtime;
 	if (runtime->dma_area == NULL)
 		return 0;
 	if (runtime->dma_buffer_p != &stream->dma_buffer) {