[Sound-open-firmware] [PATCH 00/10] MISRA rules - 1st pass
here are a set of patches that start a cleanup for MISRA compliance required for automotive. In general while the MISRA rules are debatable, they helped point at code that can be optimized or made more readable.
Additional information on remaining opens can be seen here: https://sonarcloud.io/project/issues?directories=src%2Farch%2Fxtensa%2Csrc%2...
Pierre-Louis Bossart (10): sof: define each identifier in a dedicated statement pipeline: add missing default case pipeline: simplify prepare loop SRC: replace switch by if for readability tone: replace switch by if for readability volume: replace switch by if for readability ssp: replace switch by if for readability ssp: remove unnecessary direction parameter in ssp_stop wait: reduce number of nested breaks ipc: remove unnecessary tests
src/arch/xtensa/timer.c | 9 ++++-- src/audio/dai.c | 17 ++++++---- src/audio/eq_fir.c | 22 ++++++++++--- src/audio/eq_iir.c | 21 +++++++++--- src/audio/host.c | 17 +++++++--- src/audio/iir.c | 6 ++-- src/audio/mixer.c | 15 ++++++--- src/audio/pipeline.c | 26 +++++++-------- src/audio/pipeline_static.c | 5 ++- src/audio/src.c | 38 ++++++++++++++-------- src/audio/src_core.c | 42 ++++++++++++++++++------ src/audio/tone.c | 24 +++++++------- src/audio/volume.c | 69 +++++++++++++++++++++++----------------- src/drivers/dw-dma.c | 15 ++++++--- src/drivers/ssp.c | 24 ++++++++------ src/include/reef/wait.h | 4 +-- src/ipc/byt-ipc.c | 5 +-- src/ipc/dma-copy.c | 14 +++++--- src/ipc/intel-ipc.c | 9 ++++-- src/ipc/ipc.c | 3 +- src/ipc/pmc-ipc.c | 6 ++-- src/lib/alloc.c | 24 ++++++++++---- src/lib/lib.c | 17 +++++++--- src/lib/schedule.c | 13 +++++--- src/lib/work.c | 18 ++++++++--- src/math/trig.c | 8 +++-- src/platform/baytrail/clk.c | 3 +- src/platform/baytrail/platform.c | 18 ++++++++--- src/platform/baytrail/timer.c | 8 +++-- 29 files changed, 334 insertions(+), 166 deletions(-)
MISRA C++:2008, 8.0.1 and CERT-DCL52-J require that one variable per declaration.
Change tree-wide, keeping variables in the initial order (except when it was obviously better to change).
No functional change. The Tensilica HAL remains as is as it should be modified separately
Signed-off-by: Pierre-Louis Bossart pierre-louis.bossart@linux.intel.com --- src/arch/xtensa/timer.c | 9 ++++-- src/audio/dai.c | 17 +++++++---- src/audio/eq_fir.c | 22 +++++++++++---- src/audio/eq_iir.c | 21 ++++++++++---- src/audio/host.c | 17 +++++++---- src/audio/iir.c | 6 ++-- src/audio/mixer.c | 15 +++++++--- src/audio/pipeline.c | 7 +++-- src/audio/pipeline_static.c | 5 +++- src/audio/src.c | 30 ++++++++++++++------ src/audio/src_core.c | 42 +++++++++++++++++++++------ src/audio/tone.c | 16 +++++++---- src/audio/volume.c | 61 +++++++++++++++++++++++++--------------- src/drivers/dw-dma.c | 15 +++++++--- src/drivers/ssp.c | 12 ++++++-- src/ipc/dma-copy.c | 14 ++++++--- src/ipc/intel-ipc.c | 9 ++++-- src/ipc/ipc.c | 3 +- src/ipc/pmc-ipc.c | 6 ++-- src/lib/alloc.c | 24 +++++++++++----- src/lib/lib.c | 17 +++++++---- src/lib/schedule.c | 13 ++++++--- src/lib/work.c | 18 ++++++++---- src/math/trig.c | 8 ++++-- src/platform/baytrail/clk.c | 3 +- src/platform/baytrail/platform.c | 18 +++++++++--- src/platform/baytrail/timer.c | 8 ++++-- 27 files changed, 313 insertions(+), 123 deletions(-)
diff --git a/src/arch/xtensa/timer.c b/src/arch/xtensa/timer.c index 82c2481..9408eb8 100644 --- a/src/arch/xtensa/timer.c +++ b/src/arch/xtensa/timer.c @@ -132,7 +132,10 @@ int timer64_register(struct timer *timer, void(*handler)(void *arg), void *arg) uint64_t arch_timer_get_system(struct timer *timer) { uint64_t time; - uint32_t flags, low, high, ccompare; + uint32_t flags; + uint32_t low; + uint32_t high; + uint32_t ccompare;
switch (timer->id) { case TIMER0: @@ -171,7 +174,9 @@ uint64_t arch_timer_get_system(struct timer *timer)
int arch_timer_set(struct timer *timer, uint64_t ticks) { - uint32_t time = 1, hitimeout = ticks >> 32, flags; + uint32_t time = 1; + uint32_t hitimeout = ticks >> 32; + uint32_t flags;
/* value of 1 represents rollover */ if ((ticks & 0xffffffff) == 0x1) diff --git a/src/audio/dai.c b/src/audio/dai.c index 84c8bba..4f9a082 100644 --- a/src/audio/dai.c +++ b/src/audio/dai.c @@ -1,4 +1,4 @@ -/* + /* * Copyright (c) 2016, Intel Corporation * All rights reserved. * @@ -216,8 +216,10 @@ static int dai_playback_params(struct comp_dev *dev) struct sof_ipc_comp_config *source_config; struct dma_sg_elem *elem; struct comp_buffer *dma_buffer; - struct list_item *elist, *tlist; - int i, err; + struct list_item *elist; + struct list_item *tlist; + int i; + int err; uint32_t buffer_size;
/* set up DMA configuration */ @@ -284,8 +286,10 @@ static int dai_capture_params(struct comp_dev *dev) struct sof_ipc_comp_config *sink_config; struct dma_sg_elem *elem; struct comp_buffer *dma_buffer; - struct list_item *elist, *tlist; - int i, err; + struct list_item *elist; + struct list_item *tlist; + int i; + int err; uint32_t buffer_size;
/* set up DMA configuration */ @@ -417,7 +421,8 @@ static int dai_reset(struct comp_dev *dev) { struct dai_data *dd = comp_get_drvdata(dev); struct dma_sg_config *config = &dd->config; - struct list_item *elist, *tlist; + struct list_item *elist; + struct list_item *tlist; struct dma_sg_elem *elem;
trace_dai("res"); diff --git a/src/audio/eq_fir.c b/src/audio/eq_fir.c index fc6ae03..323c702 100644 --- a/src/audio/eq_fir.c +++ b/src/audio/eq_fir.c @@ -75,7 +75,11 @@ static void eq_fir_s32_default(struct comp_dev *dev, struct comp_buffer *source, struct comp_buffer *sink, uint32_t frames) { struct comp_data *cd = comp_get_drvdata(dev); - int ch, n, n_wrap_src, n_wrap_snk, n_wrap_min; + int ch; + int n; + int n_wrap_src; + int n_wrap_snk; + int n_wrap_min; int32_t *src = (int32_t *) source->r_ptr; int32_t *snk = (int32_t *) sink->w_ptr; int nch = dev->params.channels; @@ -151,7 +155,11 @@ static void eq_fir_free_delaylines(struct fir_state_32x16 fir[]) static int eq_fir_setup(struct fir_state_32x16 fir[], struct sof_eq_fir_config *config, int nch) { - int i, j, idx, length, resp; + int i; + int j; + int idx; + int length; + int resp; int32_t *fir_data; int16_t *coef_data, *assign_response; int response_index[PLATFORM_MAX_CHANNELS]; @@ -219,7 +227,9 @@ static int eq_fir_switch_response(struct fir_state_32x16 fir[], struct sof_eq_fir_config *config, struct sof_ipc_ctrl_value_comp compv[], uint32_t num_elemens, int nch) { - int i, j, ret; + int i; + int j; + int ret;
/* Copy assign response from update and re-initilize EQ */ if (config == NULL) @@ -327,7 +337,8 @@ static int fir_cmd(struct comp_dev *dev, struct sof_ipc_ctrl_data *cdata) struct comp_data *cd = comp_get_drvdata(dev); struct sof_ipc_ctrl_value_comp *compv; size_t bs; - int i, ret = 0; + int i; + int ret = 0;
/* TODO: determine if data is DMAed or appended to cdata */
@@ -420,7 +431,8 @@ static int eq_fir_cmd(struct comp_dev *dev, int cmd, void *data) static int eq_fir_copy(struct comp_dev *dev) { struct comp_data *sd = comp_get_drvdata(dev); - struct comp_buffer *source, *sink; + struct comp_buffer *source; + struct comp_buffer *sink; uint32_t copy_bytes;
trace_comp("EqF"); diff --git a/src/audio/eq_iir.c b/src/audio/eq_iir.c index 86f879a..f8e3040 100644 --- a/src/audio/eq_iir.c +++ b/src/audio/eq_iir.c @@ -75,7 +75,11 @@ static void eq_iir_s32_default(struct comp_dev *dev, struct comp_buffer *source, struct comp_buffer *sink, uint32_t frames) { struct comp_data *cd = comp_get_drvdata(dev); - int ch, n, n_wrap_src, n_wrap_snk, n_wrap_min; + int ch; + int n; + int n_wrap_src; + int n_wrap_snk; + int n_wrap_min; int32_t *src = (int32_t *) source->r_ptr; int32_t *snk = (int32_t *) sink->w_ptr; int nch = dev->params.channels; @@ -153,7 +157,10 @@ static void eq_iir_free_delaylines(struct iir_state_df2t *iir) static int eq_iir_setup(struct iir_state_df2t iir[], struct sof_eq_iir_config *config, int nch) { - int i, j, idx, resp; + int i; + int j; + int idx; + int resp; size_t s; size_t size_sum = 0; int64_t *iir_delay; /* TODO should not need to know the type */ @@ -225,7 +232,9 @@ static int eq_iir_switch_response(struct iir_state_df2t iir[], struct sof_eq_iir_config *config, struct sof_ipc_ctrl_value_comp compv[], uint32_t num_elemens, int nch) { - int i, j, ret; + int i; + int j; + int ret;
/* Copy assign response from update and re-initilize EQ */ if (config == NULL) @@ -328,7 +337,8 @@ static int iir_cmd(struct comp_dev *dev, struct sof_ipc_ctrl_data *cdata) { struct comp_data *cd = comp_get_drvdata(dev); struct sof_ipc_ctrl_value_comp *compv; - int i, ret = 0; + int i; + int ret = 0; size_t bs;
switch (cdata->cmd) { @@ -416,7 +426,8 @@ static int eq_iir_cmd(struct comp_dev *dev, int cmd, void *data) static int eq_iir_copy(struct comp_dev *dev) { struct comp_data *cd = comp_get_drvdata(dev); - struct comp_buffer *source, *sink; + struct comp_buffer *source; + struct comp_buffer *sink; uint32_t copy_bytes;
trace_comp("EqI"); diff --git a/src/audio/host.c b/src/audio/host.c index 76124fc..4990f11 100644 --- a/src/audio/host.c +++ b/src/audio/host.c @@ -112,9 +112,12 @@ static void host_dma_cb(void *data, uint32_t type, struct dma_sg_elem *next) { struct comp_dev *dev = (struct comp_dev *)data; struct host_data *hd = comp_get_drvdata(dev); - struct dma_sg_elem *local_elem, *source_elem, *sink_elem; + struct dma_sg_elem *local_elem; + struct dma_sg_elem *source_elem; + struct dma_sg_elem *sink_elem; struct comp_buffer *dma_buffer; - uint32_t next_size, need_copy = 0; + uint32_t next_size; + uint32_t need_copy = 0; uint32_t period_bytes = hd->period_bytes;
local_elem = list_first_item(&hd->config.elem_list, @@ -308,7 +311,8 @@ static int create_local_elems(struct comp_dev *dev) { struct host_data *hd = comp_get_drvdata(dev); struct dma_sg_elem *e; - struct list_item *elist, *tlist; + struct list_item *elist; + struct list_item *tlist; int i;
for (i = 0; i < hd->period_count; i++) { @@ -344,7 +348,9 @@ unwind: static int host_elements_reset(struct comp_dev *dev) { struct host_data *hd = comp_get_drvdata(dev); - struct dma_sg_elem *source_elem, *sink_elem, *local_elem; + struct dma_sg_elem *source_elem; + struct dma_sg_elem *sink_elem; + struct dma_sg_elem *local_elem;
/* setup elem to point to first source elem */ source_elem = list_first_item(&hd->source->elem_list, @@ -588,7 +594,8 @@ static int host_reset(struct comp_dev *dev) { struct host_data *hd = comp_get_drvdata(dev); struct dma_sg_elem *e; - struct list_item *elist, *tlist; + struct list_item *elist; + struct list_item *tlist;
trace_host("res");
diff --git a/src/audio/iir.c b/src/audio/iir.c index 44c748b..b0d12f5 100644 --- a/src/audio/iir.c +++ b/src/audio/iir.c @@ -72,10 +72,12 @@
int32_t iir_df2t(struct iir_state_df2t *iir, int32_t x) { - int32_t in, tmp; + int32_t in; + int32_t tmp; int64_t acc; int32_t out = 0; - int i, j; + int i; + int j; int d = 0; /* Index to delays */ int c = 2; /* Index to coefficient a2 */
diff --git a/src/audio/mixer.c b/src/audio/mixer.c index 3861b7c..3321684 100644 --- a/src/audio/mixer.c +++ b/src/audio/mixer.c @@ -52,9 +52,12 @@ struct mixer_data { static void mix_n(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer **sources, uint32_t num_sources, uint32_t frames) { - int32_t *src, *dest = sink->w_ptr, count; + int32_t *src; + int32_t *dest = sink->w_ptr; + int32_t count; int64_t val[2]; - int i, j; + int i; + int j;
count = frames * dev->params.channels;
@@ -213,9 +216,13 @@ static int mixer_cmd(struct comp_dev *dev, int cmd, void *data) static int mixer_copy(struct comp_dev *dev) { struct mixer_data *md = comp_get_drvdata(dev); - struct comp_buffer *sink, *sources[PLATFORM_MAX_STREAMS], *source; + struct comp_buffer *sink; + struct comp_buffer *sources[PLATFORM_MAX_STREAMS]; + struct comp_buffer *source; struct list_item *blist; - int32_t i = 0, num_mix_sources = 0, xru = 0; + int32_t i = 0; + int32_t num_mix_sources = 0; + int32_t xru = 0;
tracev_mixer("cpy");
diff --git a/src/audio/pipeline.c b/src/audio/pipeline.c index 69dcce7..7531f41 100644 --- a/src/audio/pipeline.c +++ b/src/audio/pipeline.c @@ -482,7 +482,9 @@ static int preload_downstream(struct comp_dev *start, struct comp_dev *current) { struct sof_ipc_comp_config *config = COMP_GET_CONFIG(current); struct list_item *clist; - int i, total = 0, count = 0; + int i; + int total = 0; + int count = 0;
tracev_pipe("PR-"); tracev_value(current->comp.id); @@ -524,7 +526,8 @@ static int preload_downstream(struct comp_dev *start, struct comp_dev *current) int pipeline_prepare(struct pipeline *p, struct comp_dev *dev) { struct op_data op_data; - int ret, i; + int ret; + int i;
trace_pipe("pre");
diff --git a/src/audio/pipeline_static.c b/src/audio/pipeline_static.c index b6f17ae..88d52f2 100644 --- a/src/audio/pipeline_static.c +++ b/src/audio/pipeline_static.c @@ -359,7 +359,10 @@ int init_static_pipeline(struct ipc *ipc) { struct scomps *sc; struct sof_ipc_comp *c; - int i, j, k, ret; + int i; + int j; + int k; + int ret;
/* init system pipeline core */ ret = pipeline_init(); diff --git a/src/audio/src.c b/src/audio/src.c index 86f56de..2b94854 100644 --- a/src/audio/src.c +++ b/src/audio/src.c @@ -131,7 +131,8 @@ static void src_2s_s32_default(struct comp_dev *dev, struct comp_buffer *source, struct comp_buffer *sink, uint32_t source_frames, uint32_t sink_frames) { - int i, j; + int i; + int j; struct polyphase_src *s; struct comp_data *cd = comp_get_drvdata(dev); int blk_in = cd->src[0].blk_in; @@ -141,7 +142,8 @@ static void src_2s_s32_default(struct comp_dev *dev, int nch = dev->params.channels; int32_t *dest = (int32_t *) sink->w_ptr; int32_t *src = (int32_t *) source->r_ptr; - struct src_stage_prm s1, s2; + struct src_stage_prm s1; + struct src_stage_prm s2; int n_read = 0; int n_written = 0;
@@ -203,7 +205,8 @@ static void src_1s_s32_default(struct comp_dev *dev, struct comp_buffer *source, struct comp_buffer *sink, uint32_t source_frames, uint32_t sink_frames) { - int i, j; + int i; + int j; struct polyphase_src *s;
struct comp_data *cd = comp_get_drvdata(dev); @@ -317,12 +320,19 @@ static int src_params(struct comp_dev *dev) struct sof_ipc_comp_src *src = COMP_GET_IPC(dev, sof_ipc_comp_src); struct sof_ipc_comp_config *config = COMP_GET_CONFIG(dev); struct comp_data *cd = comp_get_drvdata(dev); - struct comp_buffer *sink, *source; + struct comp_buffer *sink; + struct comp_buffer *source; struct src_alloc need; size_t delay_lines_size; - uint32_t source_rate, sink_rate; + uint32_t source_rate; + uint32_t sink_rate; int32_t *buffer_start; - int n = 0, i, err, frames_is_for_source, nch, q; + int n = 0; + int i; + int err; + int frames_is_for_source; + int nch; + int q;
trace_src("par");
@@ -513,8 +523,12 @@ static int src_cmd(struct comp_dev *dev, int cmd, void *data) static int src_copy(struct comp_dev *dev) { struct comp_data *cd = comp_get_drvdata(dev); - struct comp_buffer *source, *sink; - int need_source, need_sink, blk_in, blk_out; + struct comp_buffer *source; + struct comp_buffer *sink; + int need_source; + int need_sink; + int blk_in; + int blk_out;
trace_comp("SRC");
diff --git a/src/audio/src_core.c b/src/audio/src_core.c index 1577e14..bce3586 100644 --- a/src/audio/src_core.c +++ b/src/audio/src_core.c @@ -80,7 +80,8 @@ int src_find_fs(int fs_list[], int list_length, int fs) /* Match SOF and defined SRC input rates into a bit mask */ int32_t src_input_rates(void) { - int n, b; + int n; + int b; int mask = 0;
for (n = SOF_RATES_LENGTH - 1; n >= 0; n--) { @@ -94,7 +95,8 @@ int32_t src_input_rates(void) /* Match SOF and defined SRC output rates into a bit mask */ int32_t src_output_rates(void) { - int n, b; + int n; + int b; int mask = 0;
for (n = SOF_RATES_LENGTH - 1; n >= 0; n--) { @@ -109,8 +111,13 @@ int32_t src_output_rates(void) int src_buffer_lengths(struct src_alloc *a, int fs_in, int fs_out, int nch, int max_frames, int max_frames_is_for_source) { - int blk_in, blk_out, k, s1_times, s2_times; - struct src_stage *stage1, *stage2; + int blk_in; + int blk_out; + int k; + int s1_times; + int s2_times; + struct src_stage *stage1; + struct src_stage *stage2;
a->idx_in = src_find_fs(src_in_fs, NUM_IN_FS, fs_in); a->idx_out = src_find_fs(src_out_fs, NUM_OUT_FS, fs_out); @@ -265,8 +272,10 @@ void src_polyphase_reset(struct polyphase_src *src) int src_polyphase_init(struct polyphase_src *src, int fs1, int fs2, struct src_alloc *res, int32_t *delay_lines_start) { - int n_stages, ret; - struct src_stage *stage1, *stage2; + int n_stages; + int ret; + struct src_stage *stage1; + struct src_stage *stage2;
if ((res->idx_in < 0) || (res->idx_out < 0)) { src->blk_in = res->blk_in; @@ -395,7 +404,14 @@ static inline int32_t fir_filter(
void src_polyphase_stage_cir(struct src_stage_prm *s) { - int n, m, f, c, r, n_wrap_fir, n_wrap_buf, n_wrap_min; + int n; + int m; + int f; + int c; + int r; + int n_wrap_fir; + int n_wrap_buf; + int n_wrap_min; int32_t z;
for (n = 0; n < s->times; n++) { @@ -499,8 +515,16 @@ void src_polyphase_stage_cir(struct src_stage_prm *s)
void src_polyphase_stage_cir_s24(struct src_stage_prm *s) { - int n, m, f, c, r, n_wrap_fir, n_wrap_buf, n_wrap_min; - int32_t se, z; + int n; + int m; + int f; + int c; + int r; + int n_wrap_fir; + int n_wrap_buf; + int n_wrap_min; + int32_t se; + int32_t z;
for (n = 0; n < s->times; n++) { /* Input data */ diff --git a/src/audio/tone.c b/src/audio/tone.c index 94d9aa7..51ceece 100644 --- a/src/audio/tone.c +++ b/src/audio/tone.c @@ -97,7 +97,9 @@ static void tone_s32_default(struct comp_dev *dev, struct comp_buffer *sink, struct comp_data *cd = comp_get_drvdata(dev); int32_t sine_sample; int32_t *dest = (int32_t*) sink->w_ptr; - int i, n, n_wrap_dest; + int i; + int n; + int n_wrap_dest; int nch = cd->channels;
n = frames * nch; @@ -142,7 +144,8 @@ static void tone_s32_default(struct comp_dev *dev, struct comp_buffer *sink,
static int32_t tonegen(struct tone_state *sg) { - int64_t sine, w; + int64_t sine; + int64_t w;
/* sg->w is angle in Q4.28 radians format, sin() returns Q1.31 */ /* sg->a is amplitude as Q1.31 */ @@ -161,7 +164,8 @@ static int32_t tonegen(struct tone_state *sg)
static void tonegen_control(struct tone_state *sg) { - int64_t a, p; + int64_t a; + int64_t p;
/* Count samples, 125 us blocks */ sg->sample_count++; @@ -329,7 +333,8 @@ static void tonegen_reset(struct tone_state *sg)
static int tonegen_init(struct tone_state *sg, int32_t fs, int32_t f, int32_t a) { - int idx, i; + int idx; + int i;
sg->a_target = a; sg->a = (sg->ramp_step > sg->a_target) ? sg->a_target : sg->ramp_step; @@ -516,7 +521,8 @@ static int tone_copy(struct comp_dev *dev)
static int tone_prepare(struct comp_dev *dev) { - int32_t f, a; + int32_t f; + int32_t a; struct comp_data *cd = comp_get_drvdata(dev);
trace_tone("TPp"); diff --git a/src/audio/volume.c b/src/audio/volume.c index b7e8e39..96d1974 100644 --- a/src/audio/volume.c +++ b/src/audio/volume.c @@ -95,8 +95,10 @@ static void vol_s16_to_s32(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source, uint32_t frames) { struct comp_data *cd = comp_get_drvdata(dev); - int16_t *src = (int16_t*) source->r_ptr; - int32_t i, *dest = (int32_t*) sink->w_ptr; + int16_t *src = (int16_t *) source->r_ptr; + int32_t *dest = (int32_t *) sink->w_ptr; + int32_t i; +
/* buffer sizes are always divisible by period frames */ for (i = 0; i < frames * 2; i += 2) { @@ -110,8 +112,9 @@ static void vol_s32_to_s16(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source, uint32_t frames) { struct comp_data *cd = comp_get_drvdata(dev); - int32_t i, *src = (int32_t*) source->r_ptr; - int16_t *dest = (int16_t*) sink->w_ptr; + int32_t *src = (int32_t *) source->r_ptr; + int16_t *dest = (int16_t *) sink->w_ptr; + int32_t i;
/* buffer sizes are always divisible by period frames */ for (i = 0; i < frames * 2; i += 2) { @@ -125,8 +128,9 @@ static void vol_s32_to_s32(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source, uint32_t frames) { struct comp_data *cd = comp_get_drvdata(dev); - int32_t *src = (int32_t*) source->r_ptr; - int32_t i, *dest = (int32_t*) sink->w_ptr; + int32_t *src = (int32_t *) source->r_ptr; + int32_t *dest = (int32_t *) sink->w_ptr; + int32_t i;
/* buffer sizes are always divisible by period frames */ for (i = 0; i < frames * 2; i += 2) { @@ -140,8 +144,8 @@ static void vol_s16_to_s16(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source, uint32_t frames) { struct comp_data *cd = comp_get_drvdata(dev); - int16_t *src = (int16_t*) source->r_ptr; - int16_t *dest = (int16_t*) sink->w_ptr; + int16_t *src = (int16_t *) source->r_ptr; + int16_t *dest = (int16_t *) sink->w_ptr; int32_t i;
/* buffer sizes are always divisible by period frames */ @@ -156,8 +160,9 @@ static void vol_s16_to_s24(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source, uint32_t frames) { struct comp_data *cd = comp_get_drvdata(dev); - int16_t *src = (int16_t*) source->r_ptr; - int32_t i, *dest = (int32_t*) sink->w_ptr; + int16_t *src = (int16_t *) source->r_ptr; + int32_t *dest = (int32_t *) sink->w_ptr; + int32_t i;
/* buffer sizes are always divisible by period frames */ for (i = 0; i < frames * 2; i += 2) { @@ -171,8 +176,9 @@ static void vol_s24_to_s16(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source, uint32_t frames) { struct comp_data *cd = comp_get_drvdata(dev); - int32_t i, *src = (int32_t*) source->r_ptr; - int16_t *dest = (int16_t*) sink->w_ptr; + int32_t *src = (int32_t *) source->r_ptr; + int16_t *dest = (int16_t *) sink->w_ptr; + int32_t i;
/* buffer sizes are always divisible by period frames */ for (i = 0; i < frames * 2; i += 2) { @@ -188,8 +194,9 @@ static void vol_s32_to_s24(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source, uint32_t frames) { struct comp_data *cd = comp_get_drvdata(dev); - int32_t *src = (int32_t*) source->r_ptr; - int32_t i, *dest = (int32_t*) sink->w_ptr; + int32_t *src = (int32_t *) source->r_ptr; + int32_t *dest = (int32_t *) sink->w_ptr; + int32_t i;
/* buffer sizes are always divisible by period frames */ for (i = 0; i < frames * 2; i += 2) { @@ -203,8 +210,9 @@ static void vol_s24_to_s32(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source, uint32_t frames) { struct comp_data *cd = comp_get_drvdata(dev); - int32_t i, *src = (int32_t*) source->r_ptr; - int32_t *dest = (int32_t*) sink->w_ptr; + int32_t *src = (int32_t *) source->r_ptr; + int32_t *dest = (int32_t *) sink->w_ptr; + int32_t i;
/* buffer sizes are always divisible by period frames */ for (i = 0; i < frames * 2; i += 2) { @@ -274,7 +282,8 @@ static uint32_t vol_work(void *data, uint32_t delay) struct comp_dev *dev = (struct comp_dev *)data; struct comp_data *cd = comp_get_drvdata(dev); uint32_t vol; - int i, again = 0; + int again = 0; + int i;
/* inc/dec each volume if it's not at target */ for (i = 0; i < PLATFORM_MAX_CHANNELS; i++) { @@ -406,7 +415,8 @@ static inline void volume_set_chan_unmute(struct comp_dev *dev, int chan) static int volume_ctrl_set_cmd(struct comp_dev *dev, struct sof_ipc_ctrl_data *cdata) { struct comp_data *cd = comp_get_drvdata(dev); - int i, j; + int i; + int j;
/* validate */ if (cdata->num_elems == 0 || cdata->num_elems >= SOF_IPC_MAX_CHANNELS) { @@ -457,7 +467,8 @@ static int volume_ctrl_set_cmd(struct comp_dev *dev, struct sof_ipc_ctrl_data *c static int volume_ctrl_get_cmd(struct comp_dev *dev, struct sof_ipc_ctrl_data *cdata) { struct comp_data *cd = comp_get_drvdata(dev); - int i, j; + int i; + int j;
/* validate */ if (cdata->num_elems == 0 || cdata->num_elems >= SOF_IPC_MAX_CHANNELS) { @@ -510,7 +521,8 @@ static int volume_cmd(struct comp_dev *dev, int cmd, void *data) static int volume_copy(struct comp_dev *dev) { struct comp_data *cd = comp_get_drvdata(dev); - struct comp_buffer *sink, *source; + struct comp_buffer *sink; + struct comp_buffer *source; uint32_t copy_bytes;
tracev_volume("cpy"); @@ -549,9 +561,12 @@ static int volume_copy(struct comp_dev *dev) static int volume_prepare(struct comp_dev *dev) { struct comp_data *cd = comp_get_drvdata(dev); - struct comp_buffer *sinkb, *sourceb; - struct sof_ipc_comp_config *sconfig, *config = COMP_GET_CONFIG(dev); - int i, ret; + struct comp_buffer *sinkb; + struct comp_buffer *sourceb; + struct sof_ipc_comp_config *sconfig; + struct sof_ipc_comp_config *config = COMP_GET_CONFIG(dev); + int i; + int ret;
trace_volume("pre");
diff --git a/src/drivers/dw-dma.c b/src/drivers/dw-dma.c index 7c6cd86..007bf3f 100644 --- a/src/drivers/dw-dma.c +++ b/src/drivers/dw-dma.c @@ -434,8 +434,11 @@ static int dw_dma_set_config(struct dma *dma, int channel, struct dma_pdata *p = dma_get_drvdata(dma); struct list_item *plist; struct dma_sg_elem *sg_elem; - struct dw_lli2 *lli_desc, *lli_desc_head, *lli_desc_tail; - uint32_t desc_count = 0, flags; + struct dw_lli2 *lli_desc; + struct dw_lli2 *lli_desc_head; + struct dw_lli2 *lli_desc_tail; + uint32_t desc_count = 0; + uint32_t flags;
spin_lock_irq(&dma->lock, flags);
@@ -680,8 +683,12 @@ static void dw_dma_irq_handler(void *data) struct dma *dma = (struct dma *)data; struct dma_pdata *p = dma_get_drvdata(dma); struct dma_sg_elem next; - uint32_t status_tfr = 0, status_block = 0, status_err = 0, status_intr; - uint32_t mask, pmask; + uint32_t status_tfr = 0; + uint32_t status_block = 0; + uint32_t status_err = 0; + uint32_t status_intr; + uint32_t mask; + uint32_t pmask; int i;
status_intr = dw_read(dma, DW_INTR_STATUS); diff --git a/src/drivers/ssp.c b/src/drivers/ssp.c index 3e709d0..885a78e 100644 --- a/src/drivers/ssp.c +++ b/src/drivers/ssp.c @@ -69,8 +69,16 @@ static inline int ssp_set_config(struct dai *dai, struct sof_ipc_dai_config *config) { struct ssp_pdata *ssp = dai_get_drvdata(dai); - uint32_t sscr0, sscr1, sscr2, sscr3, sspsp, sfifott, mdiv, bdiv; - uint32_t data_size, frame_len = 0; + uint32_t sscr0; + uint32_t sscr1; + uint32_t sscr2; + uint32_t sscr3; + uint32_t sspsp; + uint32_t sfifott; + uint32_t mdiv; + uint32_t bdiv; + uint32_t data_size; + uint32_t frame_len = 0; int ret = 0;
spin_lock(&ssp->lock); diff --git a/src/ipc/dma-copy.c b/src/ipc/dma-copy.c index d295089..b345ac9 100644 --- a/src/ipc/dma-copy.c +++ b/src/ipc/dma-copy.c @@ -76,10 +76,13 @@ int dma_copy_to_host(struct dma_sg_config *host_sg, int32_t host_offset, void *local_ptr, int32_t size) { struct dma_sg_config config; - struct dma_sg_elem *host_sg_elem, local_sg_elem; + struct dma_sg_elem *host_sg_elem; + struct dma_sg_elem local_sg_elem; struct dma *dma = dma_get(DMA_ID_DMAC0); completion_t complete; - int32_t err, offset = host_offset, chan; + int32_t err; + int32_t offset = host_offset; + int32_t chan;
if (dma == NULL) return -ENODEV; @@ -155,10 +158,13 @@ int dma_copy_from_host(struct dma_sg_config *host_sg, int32_t host_offset, void *local_ptr, int32_t size) { struct dma_sg_config config; - struct dma_sg_elem *host_sg_elem, local_sg_elem; + struct dma_sg_elem *host_sg_elem; + struct dma_sg_elem local_sg_elem; struct dma *dma = dma_get(DMA_ID_DMAC0); completion_t complete; - int32_t err, offset = host_offset, chan; + int32_t err; + int32_t offset = host_offset; + int32_t chan;
if (dma == NULL) return -ENODEV; diff --git a/src/ipc/intel-ipc.c b/src/ipc/intel-ipc.c index 8a4fafd..2a31772 100644 --- a/src/ipc/intel-ipc.c +++ b/src/ipc/intel-ipc.c @@ -99,7 +99,8 @@ static int get_page_descriptors(struct intel_ipc_data *iipc, struct dma_sg_config config; struct dma_sg_elem elem; struct dma *dma; - int chan, ret = 0; + int chan; + int ret = 0;
/* get DMA channel from DMAC0 */ chan = dma_channel_get(iipc->dmac0); @@ -161,8 +162,10 @@ static int parse_page_descriptors(struct intel_ipc_data *iipc, struct sof_ipc_comp_host *host = NULL; struct dma_trace_data *d = NULL; struct dma_sg_elem elem; - int i, err; - uint32_t idx, phy_addr; + int i; + int err; + uint32_t idx; + uint32_t phy_addr;
elem.size = HOST_PAGE_SIZE; if (is_trace) diff --git a/src/ipc/ipc.c b/src/ipc/ipc.c index 966fafd..6c40d10 100644 --- a/src/ipc/ipc.c +++ b/src/ipc/ipc.c @@ -185,7 +185,8 @@ int ipc_buffer_free(struct ipc *ipc, uint32_t buffer_id) int ipc_comp_connect(struct ipc *ipc, struct sof_ipc_pipe_comp_connect *connect) { - struct ipc_comp_dev *icd_source, *icd_sink; + struct ipc_comp_dev *icd_source; + struct ipc_comp_dev *icd_sink;
/* check whether the components already exist */ icd_source = ipc_get_comp(ipc, connect->source_id); diff --git a/src/ipc/pmc-ipc.c b/src/ipc/pmc-ipc.c index a5aecdd..b8183c0 100644 --- a/src/ipc/pmc-ipc.c +++ b/src/ipc/pmc-ipc.c @@ -53,7 +53,8 @@ static struct intel_ipc_pmc_data *_pmc;
static void do_cmd(void) { - uint32_t ipcsc, status = 0; + uint32_t ipcsc; + uint32_t status = 0; trace_ipc("SCm"); trace_value(_pmc->msg_l); @@ -123,7 +124,8 @@ static void irq_handler(void *arg)
int ipc_pmc_send_msg(uint32_t message) { - uint32_t ipclpesch, irq_mask; + uint32_t ipclpesch; + uint32_t irq_mask;
trace_ipc("SMs");
diff --git a/src/lib/alloc.c b/src/lib/alloc.c index 1b43d12..0d9b07c 100644 --- a/src/lib/alloc.c +++ b/src/lib/alloc.c @@ -266,8 +266,12 @@ static void *alloc_cont_blocks(struct mm_heap *heap, int level, int bflags, struct block_map *map = &heap->map[level]; struct block_hdr *hdr = &map->block[map->first_free]; void *ptr; - unsigned int start, current, count = bytes / map->block_size; - unsigned int i, remaining = map->count - count, end; + unsigned int start; + unsigned int current; + unsigned int count = bytes / map->block_size; + unsigned int i; + unsigned int remaining = map->count - count; + unsigned int end;
if (bytes % map->block_size) count++; @@ -337,7 +341,9 @@ static void free_block(struct mm_heap *heap, void *ptr) struct mm_heap * mm_heap; struct block_map * block_map; struct block_hdr *hdr; - int i, block, array_size; + int i; + int block; + int array_size;
/* sanity check */ if (ptr == NULL) @@ -465,7 +471,8 @@ void *rballoc(int zone, int bflags, size_t bytes) { struct block_map * block_map = buf_heap_map; struct mm_heap * mm_heap = &memmap.buffer; - int i, array_size = ARRAY_SIZE(buf_heap_map); + int i; + int array_size = ARRAY_SIZE(buf_heap_map); uint32_t flags; void *ptr = NULL;
@@ -569,7 +576,8 @@ uint32_t mm_pm_context_size(void) int mm_pm_context_save(struct dma_sg_config *sg) { uint32_t used; - int32_t offset = 0, ret; + int32_t offset = 0; + int32_t ret;
/* first make sure SG buffer has enough space on host for DSP context */ used = mm_pm_context_size(); @@ -605,7 +613,8 @@ int mm_pm_context_save(struct dma_sg_config *sg) */ int mm_pm_context_restore(struct dma_sg_config *sg) { - int32_t offset = 0, ret; + int32_t offset = 0; + int32_t ret;
/* copy memory maps from SG */ ret = dma_copy_from_host(sg, offset, @@ -633,7 +642,8 @@ int mm_pm_context_restore(struct dma_sg_config *sg) /* initialise map */ void init_heap(struct reef *reef) { - struct block_map *next_map, *current_map; + struct block_map *next_map; + struct block_map *current_map; int i;
spinlock_init(&memmap.lock); diff --git a/src/lib/lib.c b/src/lib/lib.c index 764e53b..e1b1d9a 100644 --- a/src/lib/lib.c +++ b/src/lib/lib.c @@ -36,9 +36,13 @@
void cmemcpy(void *dest, void *src, size_t size) { - uint32_t *d32, *s32; - uint8_t *d8, *s8; - int i, d = size / 4, r = size % 4; + uint32_t *d32; + uint32_t *s32; + uint8_t *d8; + uint8_t *s8; + int i; + int d = size / 4; + int r = size % 4;
/* copy word at a time */ d32 = dest; @@ -66,7 +70,9 @@ void bzero(void *s, size_t n) { uint32_t *d32 = s; uint8_t *d8; - int i, d = n >> 2, r = n % 4; + int i; + int d = n >> 2; + int r = n % 4;
/* zero word at a time */ for (i = 0; i < d; i++) @@ -81,7 +87,8 @@ void bzero(void *s, size_t n) /* generic memset - TODO: can be optimsed for ARCH ? */ void *memset(void *s, int c, size_t n) { - uint8_t *d8 = s, v = c; + uint8_t *d8 = s; + uint8_t v = c; int i;
for (i = 0; i < n; i++) diff --git a/src/lib/schedule.c b/src/lib/schedule.c index dbf278b..142a2fb 100644 --- a/src/lib/schedule.c +++ b/src/lib/schedule.c @@ -94,9 +94,13 @@ static inline void edf_reschedule(struct task *task, uint64_t current) static inline struct task *edf_get_next(uint64_t current, struct task *ignore) { - struct task *task, *next_task = NULL; - struct list_item *clist, *tlist; - uint64_t next_delta = UINT64_MAX, delta, deadline; + struct task *task; + struct task *next_task = NULL; + struct list_item *clist; + struct list_item *tlist; + uint64_t next_delta = UINT64_MAX; + uint64_t delta; + uint64_t deadline; int reschedule = 0;
/* any tasks in the scheduler ? */ @@ -157,7 +161,8 @@ static uint32_t sch_work(void *data, uint32_t delay) */ struct task *schedule_edf(void) { - struct task *task, *next_plus1_task = NULL; + struct task *task; + struct task *next_plus1_task = NULL; uint64_t current; uint32_t flags;
diff --git a/src/lib/work.c b/src/lib/work.c index c53f029..a267b80 100644 --- a/src/lib/work.c +++ b/src/lib/work.c @@ -98,7 +98,8 @@ static int is_work_pending(struct work_queue *queue) { struct list_item *wlist; struct work *work; - uint32_t win_end, win_start; + uint32_t win_end; + uint32_t win_start; int pending_count = 0;
/* get the current valid window of work */ @@ -158,9 +159,11 @@ static inline void work_next_timeout(struct work_queue *queue, /* run all pending work */ static void run_work(struct work_queue *queue, uint32_t *flags) { - struct list_item *wlist, *tlist; + struct list_item *wlist; + struct list_item *tlist; struct work *work; - uint32_t reschedule_usecs, udelay; + uint32_t reschedule_usecs; + uint32_t udelay;
/* check each work item in queue for pending */ list_for_item_safe(wlist, tlist, &queue->work) { @@ -207,7 +210,10 @@ static void queue_get_next_timeout(struct work_queue *queue) { struct list_item *wlist; struct work *work; - uint32_t delta = MAX_INT, current, d, ticks; + uint32_t delta = MAX_INT; + uint32_t current; + uint32_t d; + uint32_t ticks;
/* only recalc if work list not empty */ if (list_is_empty(&queue->work)) { @@ -240,7 +246,9 @@ static void queue_recalc_timers(struct work_queue *queue, { struct list_item *wlist; struct work *work; - uint32_t delta_ticks, delta_usecs, current; + uint32_t delta_ticks; + uint32_t delta_usecs; + uint32_t current;
/* get current time */ current = work_get_timer(queue); diff --git a/src/math/trig.c b/src/math/trig.c index 416c355..8101980 100644 --- a/src/math/trig.c +++ b/src/math/trig.c @@ -575,8 +575,12 @@ static inline int32_t sine_lookup(int idx) { /* Compute fixed point sine with table lookup and interpolation */ int32_t sin_fixed(int32_t w) { int idx; - int32_t frac, s0, s1, delta; - int64_t sine, idx_tmp; + int32_t frac; + int32_t s0; + int32_t s1; + int32_t delta; + int64_t sine; + int64_t idx_tmp;
/* Q4.28 x Q12.20 -> Q16.48 */ idx_tmp = (int64_t) w * SINE_C_Q20; diff --git a/src/platform/baytrail/clk.c b/src/platform/baytrail/clk.c index 1b1504e..f2362ec 100644 --- a/src/platform/baytrail/clk.c +++ b/src/platform/baytrail/clk.c @@ -151,7 +151,8 @@ void clock_disable(int clock) uint32_t clock_set_freq(int clock, uint32_t hz) { struct clock_notify_data notify_data; - uint32_t idx, flags; + uint32_t idx; + uint32_t flags; int err = 0;
notify_data.old_freq = clk_pdata->clk[clock].freq; diff --git a/src/platform/baytrail/platform.c b/src/platform/baytrail/platform.c index 26a775e..e3daf48 100644 --- a/src/platform/baytrail/platform.c +++ b/src/platform/baytrail/platform.c @@ -234,11 +234,21 @@ void platform_interrupt_unmask(uint32_t irq, uint32_t mask) int platform_init(struct reef *reef) { #if defined CONFIG_BAYTRAIL - struct dma *dmac0, *dmac1; - struct dai *ssp0, *ssp1, *ssp2; + struct dma *dmac0; + struct dma *dmac1; + struct dai *ssp0; + struct dai *ssp1; + struct dai *ssp2; #elif defined CONFIG_CHERRYTRAIL - struct dma *dmac0, *dmac1, *dmac2; - struct dai *ssp0, *ssp1, *ssp2, *ssp3, *ssp4, *ssp5; + struct dma *dmac0; + struct dma *dmac1; + struct dma *dmac2; + struct dai *ssp0; + struct dai *ssp1; + struct dai *ssp2; + struct dai *ssp3; + struct dai *ssp4; + struct dai *ssp5; #else #error Undefined platform #endif diff --git a/src/platform/baytrail/timer.c b/src/platform/baytrail/timer.c index ce58fc5..513ede1 100644 --- a/src/platform/baytrail/timer.c +++ b/src/platform/baytrail/timer.c @@ -96,7 +96,9 @@ void platform_timer_stop(struct timer *timer)
int platform_timer_set(struct timer *timer, uint64_t ticks) { - uint32_t time = 1, hitimeout = ticks >> 32, flags; + uint32_t time = 1; + uint32_t hitimeout = ticks >> 32; + uint32_t flags;
/* a tick value of 0 will not generate an IRQ */ /* value of 1 represents rollover */ @@ -139,7 +141,9 @@ void platform_timer_clear(struct timer *timer) uint64_t platform_timer_get(struct timer *timer) { uint64_t time; - uint32_t flags, low, high; + uint32_t flags; + uint32_t low; + uint32_t high;
flags = arch_interrupt_global_disable();
Make static analysis warnings go away and comply with MISRA rules: the final clause of a switch statement shall be the default case
Signed-off-by: Pierre-Louis Bossart pierre-louis.bossart@linux.intel.com --- src/audio/pipeline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/audio/pipeline.c b/src/audio/pipeline.c index 7531f41..a5f7a5d 100644 --- a/src/audio/pipeline.c +++ b/src/audio/pipeline.c @@ -205,8 +205,8 @@ static void pipeline_cmd_update(struct pipeline *p, struct comp_dev *comp,
break; case COMP_CMD_SUSPEND: - break; case COMP_CMD_RESUME: + default: break; } }
MISRA-C:2012, 15.4 - There should be no more than one break or goto statement used to terminate any iteration statement
reshuffle the code to use a single break with no additional tests.
Signed-off-by: Pierre-Louis Bossart pierre-louis.bossart@linux.intel.com --- src/audio/pipeline.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)
diff --git a/src/audio/pipeline.c b/src/audio/pipeline.c index a5f7a5d..636a42b 100644 --- a/src/audio/pipeline.c +++ b/src/audio/pipeline.c @@ -526,7 +526,7 @@ static int preload_downstream(struct comp_dev *start, struct comp_dev *current) int pipeline_prepare(struct pipeline *p, struct comp_dev *dev) { struct op_data op_data; - int ret; + int ret = -1; int i;
trace_pipe("pre"); @@ -551,18 +551,15 @@ int pipeline_prepare(struct pipeline *p, struct comp_dev *dev)
ret = preload_downstream(dev, dev);
- /* errors ? */ - if (ret < 0) + /* errors or complete ? */ + if (ret <= 0) break; - /* complete ? */ - else if (ret == 0) - goto out; } - - /* failed to preload */ - trace_pipe_error("epl"); - ret = -EIO; - + if (ret < 0) { + /* failed to preload */ + trace_pipe_error("epl"); + ret = -EIO; + } } else { ret = component_op_upstream(&op_data, dev, dev, NULL); }
MISRA C:2012, 16.5: Every switch statement shall have at least two switch-clauses
Signed-off-by: Pierre-Louis Bossart pierre-louis.bossart@linux.intel.com --- src/audio/src.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/src/audio/src.c b/src/audio/src.c index 2b94854..3fd9614 100644 --- a/src/audio/src.c +++ b/src/audio/src.c @@ -509,12 +509,8 @@ static int src_cmd(struct comp_dev *dev, int cmd, void *data) if (ret < 0) return ret;
- switch (cmd) { - case COMP_CMD_SET_VALUE: - return src_ctrl_cmd(dev, cdata); - default: - break; - } + if (cmd == COMP_CMD_SET_VALUE) + ret = src_ctrl_cmd(dev, cdata);
return ret; }
MISRA C:2012, 16.5: Every switch statement shall have at least two switch-clauses
Signed-off-by: Pierre-Louis Bossart pierre-louis.bossart@linux.intel.com --- src/audio/tone.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/src/audio/tone.c b/src/audio/tone.c index 51ceece..0a91f09 100644 --- a/src/audio/tone.c +++ b/src/audio/tone.c @@ -484,12 +484,8 @@ static int tone_cmd(struct comp_dev *dev, int cmd, void *data) if (ret < 0) return ret;
- switch (cmd) { - case COMP_CMD_SET_VALUE: - return tone_ctrl_cmd(dev, cdata); - default: - break; - } + if (cmd == COMP_CMD_SET_VALUE) + ret = tone_ctrl_cmd(dev, cdata);
return ret; }
MISRA C:2012, 16.5: Every switch statement shall have at least two switch-clauses
Signed-off-by: Pierre-Louis Bossart pierre-louis.bossart@linux.intel.com --- src/audio/volume.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/src/audio/volume.c b/src/audio/volume.c index 96d1974..68c8453 100644 --- a/src/audio/volume.c +++ b/src/audio/volume.c @@ -476,18 +476,14 @@ static int volume_ctrl_get_cmd(struct comp_dev *dev, struct sof_ipc_ctrl_data *c return -EINVAL; }
- switch (cdata->cmd) { - case SOF_CTRL_CMD_VOLUME: - + if (cdata->cmd == SOF_CTRL_CMD_VOLUME) { for (i = 0; i < cdata->num_elems; i++) { for (j = 0; j < cdata->num_elems; j++) { if (cdata->chanv[j].value == cd->chan[i]) cdata->chanv[j].value = cd->tvolume[i]; } } - - break; - default: + } else { trace_volume_error("ec2"); return -EINVAL; }
MISRA C:2012, 16.5: Every switch statement shall have at least two switch-clauses
Signed-off-by: Pierre-Louis Bossart pierre-louis.bossart@linux.intel.com --- src/drivers/ssp.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/src/drivers/ssp.c b/src/drivers/ssp.c index 885a78e..c12c7f1 100644 --- a/src/drivers/ssp.c +++ b/src/drivers/ssp.c @@ -244,13 +244,11 @@ static inline int ssp_set_config(struct dai *dai, ssp_write(dai, SSRSA, config->rx_slot_mask);
/* sample data size on SSP FIFO */ - switch (config->sample_valid_bits) { - case 16: /* 2 * 16bit packed into 32bit FIFO */ + if (config->sample_valid_bits == 16) + /* 2 * 16bit packed into 32bit FIFO */ data_size = 32; - break; - default: + else data_size = config->sample_container_bits; - }
if (data_size > 16) sscr0 |= (SSCR0_EDSS | SSCR0_DSIZE(data_size - 16));
No longer needed since we do the same thing for playback and capture
Signed-off-by: Pierre-Louis Bossart pierre-louis.bossart@linux.intel.com --- src/drivers/ssp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/drivers/ssp.c b/src/drivers/ssp.c index c12c7f1..a472974 100644 --- a/src/drivers/ssp.c +++ b/src/drivers/ssp.c @@ -313,7 +313,7 @@ static void ssp_start(struct dai *dai, int direction) }
/* stop the SSP for either playback or capture */ -static void ssp_stop(struct dai *dai, int direction) +static void ssp_stop(struct dai *dai) { struct ssp_pdata *ssp = dai_get_drvdata(dai);
@@ -362,7 +362,7 @@ static int ssp_trigger(struct dai *dai, int cmd, int direction) case COMP_CMD_STOP: case COMP_CMD_PAUSE: ssp->state[direction] = COMP_STATE_PAUSED; - ssp_stop(dai, direction); + ssp_stop(dai); break; case COMP_CMD_RESUME: ssp_context_restore(dai);
MISRA-C:2012, 15.4 - There should be no more than one break or goto statement used to terminate any iteration statement
reshuffle the code to use a single break
Signed-off-by: Pierre-Louis Bossart pierre-louis.bossart@linux.intel.com --- src/include/reef/wait.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/src/include/reef/wait.h b/src/include/reef/wait.h index 5523de7..c830a75 100644 --- a/src/include/reef/wait.h +++ b/src/include/reef/wait.h @@ -114,9 +114,7 @@ static inline int wait_for_completion_timeout(completion_t *comp) /* check for completion after every wake from IRQ */ while (1) {
- if (c->complete) - break; - if (c->timeout) + if (c->complete || c->timeout) break;
wait_for_interrupt(0);
Last test would always evaluate as true, refactor to fold equal and less than case as one
Signed-off-by: Pierre-Louis Bossart pierre-louis.bossart@linux.intel.com --- src/ipc/byt-ipc.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/src/ipc/byt-ipc.c b/src/ipc/byt-ipc.c index 077fdde..fd1ad1e 100644 --- a/src/ipc/byt-ipc.c +++ b/src/ipc/byt-ipc.c @@ -132,12 +132,9 @@ void ipc_platform_do_cmd(struct ipc *ipc) err = ipc_cmd(); if (err > 0) { goto done; /* reply created and copied by cmd() */ - } else if (err < 0) { + } else { /* send std error reply */ reply.error = err; - } else if (err == 0) { - /* send std reply */ - reply.error = 0; }
/* send std error/ok reply */
On Mon, 2017-09-25 at 14:52 -0500, Pierre-Louis Bossart wrote:
here are a set of patches that start a cleanup for MISRA compliance required for automotive. In general while the MISRA rules are debatable, they helped point at code that can be optimized or made more readable.
All applied.
Thanks
Liam
participants (2)
-
Liam Girdwood
-
Pierre-Louis Bossart