Skip to content

Commit 19293fa

Browse files
committed
misc trivial changes to please static analyzers
No functional changes. Signed-off-by: Alberto Escolar Piedras <[email protected]>
1 parent 2a41263 commit 19293fa

File tree

9 files changed

+38
-40
lines changed

9 files changed

+38
-40
lines changed

common/src/main.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ int main(int argc, char *argv[])
121121
nsi_hws_one_event();
122122
}
123123

124-
/* This line should be unreachable */
125-
return 1; /* LCOV_EXCL_LINE */
124+
NSI_CODE_UNREACHABLE; /* LCOV_EXCL_LINE */
126125
}
127126

128127
#endif /* NSI_NO_MAIN */

common/src/nce.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ NSI_INLINE int nce_sem_rewait(sem_t *semaphore)
5353
int ret;
5454

5555
while ((ret = sem_wait(semaphore)) == EINTR) {
56-
;
56+
/* Restart wait if we were interrupted */
5757
}
5858
return ret;
5959
}

common/src/nct.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,18 @@ NSI_INLINE int nct_sem_rewait(sem_t *semaphore)
147147
int ret;
148148

149149
while ((ret = sem_wait(semaphore)) == EINTR) {
150-
;
150+
/* Restart wait if we were interrupted */
151151
}
152152
return ret;
153153
}
154154

155155
/**
156156
* Helper function, run by a thread which is being aborted
157157
*/
158-
static void abort_tail(struct threads_table_el *tt_el, int this_th_nbr)
158+
static void abort_tail(struct threads_table_el *tt_el)
159159
{
160160
NCT_DEBUG("Thread [%i] %i: %s: Aborting (exiting) (rel mut)\n",
161-
tt_el->thead_cnt, this_th_nbr, __func__);
161+
tt_el->thead_cnt, tt_el->thread_idx, __func__);
162162

163163
tt_el->running = false;
164164
tt_el->state = ABORTED;
@@ -183,7 +183,7 @@ static void nct_wait_until_allowed(struct threads_table_el *tt_el, int this_th_n
183183
}
184184

185185
if (tt_el->state == ABORTING) {
186-
abort_tail(tt_el, this_th_nbr);
186+
abort_tail(tt_el);
187187
}
188188

189189
tt_el->running = true;
@@ -236,7 +236,7 @@ void nct_swap_threads(void *this_arg, int next_allowed_thread_nbr)
236236
if (tt_el->state == ABORTING) { /* We had set ourself as aborted => let's exit now */
237237
NCT_DEBUG("Thread [%i] %i: %s: Aborting curr.\n",
238238
tt_el->thead_cnt, this_th_nbr, __func__);
239-
abort_tail(tt_el, this_th_nbr);
239+
abort_tail(tt_el);
240240
} else {
241241
nct_wait_until_allowed(tt_el, this_th_nbr);
242242
}
@@ -269,7 +269,7 @@ void nct_first_thread_start(void *this_arg, int next_allowed_thread_nbr)
269269
static void *nct_thread_starter(void *arg_el)
270270
{
271271
struct threads_table_el *tt_el = (struct threads_table_el *)arg_el;
272-
struct nct_status_t *this = tt_el->nct_status;
272+
const struct nct_status_t *this = tt_el->nct_status;
273273

274274
int thread_idx = tt_el->thread_idx;
275275

common/src/nsi_hw_scheduler.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,5 @@ void nsi_hws_init(void)
163163
*/
164164
void nsi_hws_cleanup(void)
165165
{
166+
/* Nothing to be done so far */
166167
}

native/src/irq_ctrl.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ int hw_irq_ctrl_get_highest_prio_irq(void)
9090
return -1;
9191
}
9292

93-
uint64_t irq_status = hw_irq_ctrl_get_irq_status();
93+
uint64_t irq_status_temp = hw_irq_ctrl_get_irq_status();
9494
int winner = -1;
9595
int winner_prio = 256;
9696

97-
while (irq_status != 0U) {
98-
int irq_nbr = nsi_find_lsb_set64(irq_status) - 1;
97+
while (irq_status_temp != 0U) {
98+
int irq_nbr = nsi_find_lsb_set64(irq_status_temp) - 1;
9999

100-
irq_status &= ~((uint64_t) 1 << irq_nbr);
100+
irq_status_temp &= ~((uint64_t) 1 << irq_nbr);
101101
if ((winner_prio > (int)irq_prio[irq_nbr])
102102
&& (currently_running_prio > (int)irq_prio[irq_nbr])) {
103103
winner = irq_nbr;
@@ -124,10 +124,8 @@ uint32_t hw_irq_ctrl_change_lock(uint32_t new_lock)
124124

125125
irqs_locked = new_lock;
126126

127-
if ((previous_lock == true) && (new_lock == false)) {
128-
if (irq_status != 0U) {
129-
nsif_cpu0_irq_raised_from_sw();
130-
}
127+
if ((previous_lock == true) && (new_lock == false) && (irq_status != 0U)) {
128+
nsif_cpu0_irq_raised_from_sw();
131129
}
132130
return previous_lock;
133131
}
@@ -206,6 +204,8 @@ static inline void hw_irq_ctrl_irq_raise_prefix(unsigned int irq)
206204
}
207205
} else if (irq == PHONY_HARD_IRQ) {
208206
lock_ignore = true;
207+
} else {
208+
/* PHONY_WEAK_IRQ does not require any action */
209209
}
210210
}
211211

@@ -218,7 +218,7 @@ static inline void hw_irq_ctrl_irq_raise_prefix(unsigned int irq)
218218
void hw_irq_ctrl_set_irq(unsigned int irq)
219219
{
220220
hw_irq_ctrl_irq_raise_prefix(irq);
221-
if ((irqs_locked == false) || (lock_ignore)) {
221+
if ((irqs_locked == false) || lock_ignore) {
222222
/*
223223
* Awake CPU in 1 delta
224224
* Note that we awake the CPU even if the IRQ is disabled
@@ -239,7 +239,7 @@ static void irq_raising_from_hw_now(void)
239239
* but not if irqs are locked unless this is due to a
240240
* PHONY_HARD_IRQ
241241
*/
242-
if ((irqs_locked == false) || (lock_ignore)) {
242+
if ((irqs_locked == false) || lock_ignore) {
243243
lock_ignore = false;
244244
nsif_cpu0_irq_raised();
245245
}

native/src/native_rtc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ uint64_t native_rtc_gettime_us(int clock_type)
2727

2828
hwtimer_get_pseudohost_rtc_time(&nsec, &sec);
2929
return sec * 1000000UL + nsec / 1000U;
30+
} else {
31+
nsi_print_error_and_exit("Unknown clock source %i\n",
32+
clock_type);
33+
return 0;
3034
}
31-
32-
nsi_print_error_and_exit("Unknown clock source %i\n",
33-
clock_type);
34-
return 0;
3535
}
3636

3737
/**

native/src/nsi_cmdline.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ static void print_invalid_opt_error(char *argv)
114114
*/
115115
void nsi_handle_cmd_line(int argc, char *argv[])
116116
{
117-
int i;
118-
119117
nsi_add_testargs_option();
120118

121119
s_argv = argv;
@@ -130,9 +128,9 @@ void nsi_handle_cmd_line(int argc, char *argv[])
130128
}
131129
}
132130

133-
for (i = 1; i < argc; i++) {
131+
for (int i = 1; i < argc; i++) {
134132

135-
if ((nsi_cmd_is_option(argv[i], "testargs", 0))) {
133+
if (nsi_cmd_is_option(argv[i], "testargs", 0)) {
136134
test_argc = argc - i - 1;
137135
test_argv = &argv[i+1];
138136
break;

native/src/nsi_cmdline_common.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,44 +123,44 @@ void nsi_cmd_read_option_value(const char *str, void *dest, const char type,
123123
const char *option)
124124
{
125125
int error = 0;
126-
char *endptr = NULL;
126+
const char *endptr = NULL;
127127

128128
switch (type) {
129129
case 'b':
130130
if (strcasecmp(str, "false") == 0) {
131131
*(bool *)dest = false;
132-
endptr = (char *)str + 5;
132+
endptr = (const char *)str + 5;
133133
} else if (strcmp(str, "0") == 0) {
134134
*(bool *)dest = false;
135-
endptr = (char *)str + 1;
135+
endptr = (const char *)str + 1;
136136
} else if (strcasecmp(str, "true") == 0) {
137137
*(bool *)dest = true;
138-
endptr = (char *)str + 4;
138+
endptr = (const char *)str + 4;
139139
} else if (strcmp(str, "1") == 0) {
140140
*(bool *)dest = true;
141-
endptr = (char *)str + 1;
141+
endptr = (const char *)str + 1;
142142
} else {
143143
error = 1;
144144
}
145145
break;
146146
case 's':
147-
*(char **)dest = (char *)str;
148-
endptr = (char *)str + strlen(str);
147+
*(const char **)dest = (const char *)str;
148+
endptr = (const char *)str + strlen(str);
149149
break;
150150
case 'u':
151-
*(uint32_t *)dest = strtoul(str, &endptr, 0);
151+
*(uint32_t *)dest = strtoul(str, (char **)&endptr, 0);
152152
break;
153153
case 'U':
154-
*(uint64_t *)dest = strtoull(str, &endptr, 0);
154+
*(uint64_t *)dest = strtoull(str, (char **)&endptr, 0);
155155
break;
156156
case 'i':
157-
*(int32_t *)dest = strtol(str, &endptr, 0);
157+
*(int32_t *)dest = strtol(str, (char **)&endptr, 0);
158158
break;
159159
case 'I':
160-
*(int64_t *)dest = strtoll(str, &endptr, 0);
160+
*(int64_t *)dest = strtoll(str, (char **)&endptr, 0);
161161
break;
162162
case 'd':
163-
*(double *)dest = strtod(str, &endptr);
163+
*(double *)dest = strtod(str, (char **)&endptr);
164164
break;
165165
default:
166166
nsi_print_error_and_exit(CMD_TYPE_ERROR, type);

native/src/timer_model.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ static void cmd_rt_ratio_found(char *argv, int offset)
455455
{
456456
NSI_ARG_UNUSED(argv);
457457
NSI_ARG_UNUSED(offset);
458-
if ((args.rt_ratio <= 0)) {
458+
if (args.rt_ratio <= 0) {
459459
nsi_print_error_and_exit("The ratio needs to be > 0. "
460460
"Please use --help for more info\n");
461461
}

0 commit comments

Comments
 (0)