ASoC: Intel: Add NULL checks for the stream pointer
Subsystems (3)
PATCH 1/1 ASoC: Intel: Add NULL checks for the stream pointer
We should not send IPC stream commands to FW when the stream is NULL, dereference the NULL pointer may also occur without precheck. Here add NULL pointer checks for these stream APIs.
--- sound/soc/intel/sst-haswell-ipc.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
sound/soc/intel/sst-haswell-ipc.c +15 -0
@@ -1233,6 +1233,9 @@ int sst_hsw_stream_free(struct sst_hsw *hsw, struct sst_hsw_stream *stream)struct sst_dsp *sst = hsw->dsp;unsigned long flags; +if (!stream) +return 0 ; +/* dont free DSP streams that are not commited */ if (!stream->commited) goto out;
@@ -1420,6 +1423,9 @@ int sst_hsw_stream_commit(struct sst_hsw *hsw, struct sst_hsw_stream *stream)u32 header;int ret; +if (stream->commited) +return 0 ; +trace_ipc_request ("stream alloc" , stream->host_id); header =IPC_GLB_TYPE (IPC_GLB_ALLOCATE_STREAM );
@@ -1548,6 +1554,9 @@ int sst_hsw_stream_pause(struct sst_hsw *hsw, struct sst_hsw_stream *stream, {int ret; +if (!stream) +return 0 ; +trace_ipc_request ("stream pause" , stream->reply.stream_hw_id); ret = sst_hsw_stream_operations(hsw, IPC_STR_PAUSE,
@@ -1564,6 +1573,9 @@ int sst_hsw_stream_resume(struct sst_hsw *hsw, struct sst_hsw_stream *stream, {int ret; +if (!stream) +return 0 ; +trace_ipc_request ("stream resume" , stream->reply.stream_hw_id); ret = sst_hsw_stream_operations(hsw, IPC_STR_RESUME,
@@ -1579,6 +1591,9 @@ int sst_hsw_stream_reset(struct sst_hsw *hsw, struct sst_hsw_stream *stream) {int ret, tries =10 ; +if (!stream) +return 0 ; +/* dont reset streams that are not commited */ if (!stream->commited)return 0 ;
Signature · 1 line
1.9.1
Mark Brown
maintainerQuoted 5 lines · Jie Yang
We should not send IPC stream commands to FW when the stream is NULL, dereference the NULL pointer may also occur without precheck. Here add NULL pointer checks for these stream APIs.
sound/soc/intel/sst-haswell-ipc.c int sst_hsw_stream_commit(struct sst_hsw *hsw, struct sst_hsw_stream *stream) · line 1431
Quoted 9 lines
sound/soc/intel/sst-haswell-ipc.c +3
-0@@ -1420,6 +1423,9 @@ int sst_hsw_stream_commit(struct sst_hsw *hsw, struct sst_hsw_stream *stream)u32 header;int ret; +if (stream->commited) +return 0 ; +trace_ipc_request ("stream alloc" , stream->host_id); header =IPC_GLB_TYPE (IPC_GLB_ALLOCATE_STREAM );
This is a bit worrying, it means that we will silently ignore any attempts to pass in a NULL stream. Sometimes that's an OK thing to do (like in deallocation paths) but this seems to more generally silently ignore errors which means we're less likely to spot other coding issues. Race conditions worry me especially - trying to use something before we've quite allocated it for example.
I'd be much happier if this warned in cases where it wasn't totally obvious that attempting to use a NULL pointer is sensible.
Quoted 33 lines
-----Original Message-----
From: Mark Brown [mailto:[email protected]]
Sent: Wednesday, January 07, 2015 1:22 AM
To: Jie, Yang
Cc: [email protected]; Girdwood, Liam R
Subject: Re: [PATCH] ASoC: Intel: Add NULL checks for the stream pointerReview int sst_hsw_stream_commit(struct sst_hsw *hsw,
Quoted 5 lines · Jie Yang
We should not send IPC stream commands to FW when the stream is NULL, dereference the NULL pointer may also occur without precheck. Here add NULL pointer checks for these stream APIs.
(quoted diff) +0
-0@@ -1420,6 +1423,9 @@ int sst_hsw_stream_commit(struct sst_hsw *hsw,struct
sst_hsw_stream*stream)sound/soc/intel/sst-haswell-ipc.c int sst_hsw_stream_commit(struct sst_hsw *hsw, struct sst_hsw_stream *stream) · line 1431
Quoted 9 lines
sound/soc/intel/sst-haswell-ipc.c +3
-0u32 header;int ret; +if (stream->commited) +return 0 ; +trace_ipc_request ("stream alloc" , stream->host_id); header =IPC_GLB_TYPE (IPC_GLB_ALLOCATE_STREAM );This is a bit worrying, it means that we will silently ignore any attempts to pass in a NULL stream. Sometimes that's an OK thing to do (like in deallocation paths) but this seems to more generally silently ignore errors which means we're less likely to spot other coding issues.
Race conditions worry me especially - trying to use something before we've quite allocated it for example.
Quoted 2 lines
I'd be much happier if this warned in cases where it wasn't totally obvious that attempting to use a NULL pointer is sensible.
[Keyon] thanks for review, Mark. So you meant we should add some warning log here, right?
~Keyon
Mark Brown
maintainerQuoted 4 lines · Yang
Quoted 2 lines
I'd be much happier if this warned in cases where it wasn't totally obvious that attempting to use a NULL pointer is sensible.
[Keyon] thanks for review, Mark. So you meant we should add some warning log here, right?
Yes, I'd be a lot happier with that - if there's some cases which happen a lot and it makes sense that they happen a lot then the changelog and/or the code should make it clear that those cases are OK but as a default it seems better to at least say we ignored things.