[Sound-open-firmware] [PATCH 1/2] ipc: add missing braces for multi-line macro in block
Detected with Coverity and fix with braces.
Details:
Code that is meant to be executed conditionally may be executed unconditionally
In do_notify: The indentation of this code suggests it is nested when it is not. (CWE-483)
multi_stmt_macro: The macro on this line expands into multiple statements, only the first of which is nested within the preceding parent while the rest are not.
http://cwe.mitre.org/data/definitions/483.html
Signed-off-by: Pierre-Louis Bossart pierre-louis.bossart@linux.intel.com --- src/ipc/byt-ipc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/ipc/byt-ipc.c b/src/ipc/byt-ipc.c index 8897bb9..b5da4b6 100644 --- a/src/ipc/byt-ipc.c +++ b/src/ipc/byt-ipc.c @@ -67,8 +67,9 @@ static void do_notify(void) goto out;
/* copy the data returned from DSP */ - if (msg->rx_size && msg->rx_size < SOF_IPC_MSG_MAX_SIZE) + if (msg->rx_size && msg->rx_size < SOF_IPC_MSG_MAX_SIZE) { mailbox_dspbox_read(msg->rx_data, 0, msg->rx_size); + }
/* any callback ? */ if (msg->cb)
Explicitly comment that the fall through in a switch case is not a typo to make Coverity warnings go away.
Signed-off-by: Pierre-Louis Bossart pierre-louis.bossart@linux.intel.com --- src/audio/dai.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/src/audio/dai.c b/src/audio/dai.c index b7ad1b4..1112ec9 100644 --- a/src/audio/dai.c +++ b/src/audio/dai.c @@ -559,6 +559,7 @@ static int dai_cmd(struct comp_dev *dev, int cmd, void *data) break; case COMP_CMD_XRUN: dd->xrun = 1; + /* fall through */ case COMP_CMD_PAUSE: case COMP_CMD_STOP: wait_init(&dd->complete);
On Thu, 2018-01-18 at 14:31 -0600, Pierre-Louis Bossart wrote:
Explicitly comment that the fall through in a switch case is not a typo to make Coverity warnings go away.
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel .com>
src/audio/dai.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/src/audio/dai.c b/src/audio/dai.c index b7ad1b4..1112ec9 100644 --- a/src/audio/dai.c +++ b/src/audio/dai.c @@ -559,6 +559,7 @@ static int dai_cmd(struct comp_dev *dev, int cmd, void *data) break; case COMP_CMD_XRUN: dd->xrun = 1;
case COMP_CMD_PAUSE: case COMP_CMD_STOP: wait_init(&dd->complete);/* fall through */
Applied patch 2/2, I think it's better to make 1/2 static inline.
Thanks
Liam --------------------------------------------------------------------- Intel Corporation (UK) Limited Registered No. 1134945 (England) Registered Office: Pipers Way, Swindon SN3 1RJ VAT No: 860 2173 47
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
-----Original Message----- From: sound-open-firmware-bounces@alsa-project.org [mailto:sound-open- firmware-bounces@alsa-project.org] On Behalf Of Pierre-Louis Bossart Sent: Friday, January 19, 2018 4:31 AM To: sound-open-firmware@alsa-project.org Cc: Pierre-Louis Bossart pierre-louis.bossart@linux.intel.com Subject: [Sound-open-firmware] [PATCH 1/2] ipc: add missing braces for multi- line macro in block
Detected with Coverity and fix with braces.
Details:
Code that is meant to be executed conditionally may be executed unconditionally
In do_notify: The indentation of this code suggests it is nested when it is not. (CWE-483)
multi_stmt_macro: The macro on this line expands into multiple statements, only the first of which is nested within the preceding parent while the rest are not.
http://cwe.mitre.org/data/definitions/483.html
Signed-off-by: Pierre-Louis Bossart pierre-louis.bossart@linux.intel.com
src/ipc/byt-ipc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/ipc/byt-ipc.c b/src/ipc/byt-ipc.c index 8897bb9..b5da4b6 100644 --- a/src/ipc/byt-ipc.c +++ b/src/ipc/byt-ipc.c @@ -67,8 +67,9 @@ static void do_notify(void) goto out;
/* copy the data returned from DSP */
- if (msg->rx_size && msg->rx_size < SOF_IPC_MSG_MAX_SIZE)
- if (msg->rx_size && msg->rx_size < SOF_IPC_MSG_MAX_SIZE) { mailbox_dspbox_read(msg->rx_data, 0, msg->rx_size);
- }
Isn't it better choice to change it in the macro definition then it is safe to call it in other places also?
diff --git a/src/include/reef/mailbox.h b/src/include/reef/mailbox.h index c0580a9..1179edf 100644 --- a/src/include/reef/mailbox.h +++ b/src/include/reef/mailbox.h @@ -63,19 +63,26 @@ MAILBOX_DEBUG_SIZE
#define mailbox_dspbox_write(dest, src, bytes) \ - rmemcpy((void*)(MAILBOX_DSPBOX_BASE + dest), src, bytes); \ - dcache_writeback_region((void*)(MAILBOX_DSPBOX_BASE + dest), bytes); - + do { \ + rmemcpy((void*)(MAILBOX_DSPBOX_BASE + dest), src, bytes); \ + dcache_writeback_region((void*)(MAILBOX_DSPBOX_BASE + dest), bytes); \ + } while (0) #define mailbox_dspbox_read(dest, src, bytes) \ - dcache_invalidate_region((void*)(MAILBOX_DSPBOX_BASE + src), bytes); \ - rmemcpy(dest, (void*)(MAILBOX_DSPBOX_BASE + src), bytes); + do { \ + dcache_invalidate_region((void*)(MAILBOX_DSPBOX_BASE + src), bytes); \ + rmemcpy(dest, (void*)(MAILBOX_DSPBOX_BASE + src), bytes); \ + } while (0)
#define mailbox_hostbox_write(dest, src, bytes) \ - rmemcpy((void*)(MAILBOX_HOSTBOX_BASE + dest), src, bytes); \ - dcache_writeback_region((void*)(MAILBOX_HOSTBOX_BASE + dest), bytes); + do { \ + rmemcpy((void*)(MAILBOX_HOSTBOX_BASE + dest), src, bytes); \ + dcache_writeback_region((void*)(MAILBOX_HOSTBOX_BASE + dest), bytes); \ + } while (0)
#define mailbox_hostbox_read(dest, src, bytes) \ - dcache_invalidate_region((void*)(MAILBOX_HOSTBOX_BASE + src), bytes); \ - rmemcpy(dest, (void*)(MAILBOX_HOSTBOX_BASE + src), bytes); + do { \ + dcache_invalidate_region((void*)(MAILBOX_HOSTBOX_BASE + src), bytes); \ + rmemcpy(dest, (void*)(MAILBOX_HOSTBOX_BASE + src), bytes); \ + } while (0)
#endif
Thanks, ~Keyon
/* any callback ? */ if (msg->cb) -- 2.14.1
Sound-open-firmware mailing list Sound-open-firmware@alsa-project.org http://mailman.alsa-project.org/mailman/listinfo/sound-open-firmware
On Fri, 2018-01-19 at 01:31 +0000, Jie, Yang wrote:
-----Original Message----- From: sound-open-firmware-bounces@alsa-project.org [mailto:sound-open- firmware-bounces@alsa-project.org] On Behalf Of Pierre-Louis Bossart Sent: Friday, January 19, 2018 4:31 AM To: sound-open-firmware@alsa-project.org Cc: Pierre-Louis Bossart pierre-louis.bossart@linux.intel.com Subject: [Sound-open-firmware] [PATCH 1/2] ipc: add missing braces for multi- line macro in block
Detected with Coverity and fix with braces.
Details:
Code that is meant to be executed conditionally may be executed unconditionally
In do_notify: The indentation of this code suggests it is nested when it is not. (CWE-483)
multi_stmt_macro: The macro on this line expands into multiple statements, only the first of which is nested within the preceding parent while the rest are not.
http://cwe.mitre.org/data/definitions/483.html
Signed-off-by: Pierre-Louis Bossart pierre-louis.bossart@linux.intel.com
src/ipc/byt-ipc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/ipc/byt-ipc.c b/src/ipc/byt-ipc.c index 8897bb9..b5da4b6 100644 --- a/src/ipc/byt-ipc.c +++ b/src/ipc/byt-ipc.c @@ -67,8 +67,9 @@ static void do_notify(void) goto out;
/* copy the data returned from DSP */
- if (msg->rx_size && msg->rx_size < SOF_IPC_MSG_MAX_SIZE)
- if (msg->rx_size && msg->rx_size < SOF_IPC_MSG_MAX_SIZE) { mailbox_dspbox_read(msg->rx_data, 0, msg->rx_size);
- }
Isn't it better choice to change it in the macro definition then it is safe to call it in other places also?
diff --git a/src/include/reef/mailbox.h b/src/include/reef/mailbox.h index c0580a9..1179edf 100644 --- a/src/include/reef/mailbox.h +++ b/src/include/reef/mailbox.h @@ -63,19 +63,26 @@ MAILBOX_DEBUG_SIZE
#define mailbox_dspbox_write(dest, src, bytes) \
rmemcpy((void*)(MAILBOX_DSPBOX_BASE + dest), src, bytes); \
dcache_writeback_region((void*)(MAILBOX_DSPBOX_BASE + dest), bytes);
do { \
rmemcpy((void*)(MAILBOX_DSPBOX_BASE + dest), src, bytes); \
dcache_writeback_region((void*)(MAILBOX_DSPBOX_BASE + dest), bytes); \
} while (0)
best to make these static inline.
Liam
participants (4)
-
Jie, Yang
-
Liam Girdwood
-
Liam Girdwood
-
Pierre-Louis Bossart