Skip to content

Commit af806a9

Browse files
rarindamwenlingz
authored andcommitted
HV: Fix missing brackets for MISRA C Violations
Patch 6 of 7. Added changes to make sure Misra C violations are fixed for rules 11S and 12S. Signed-off-by: Arindam Roy <arindam.roy@intel.com>
1 parent 4aa6cda commit af806a9

File tree

17 files changed

+200
-111
lines changed

17 files changed

+200
-111
lines changed

hypervisor/common/io_request.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ int32_t acrn_insert_request_wait(struct vcpu *vcpu, struct vhm_request *req)
6464
"vhm_request page broken!");
6565

6666

67-
if (vcpu == NULL || req == NULL || vcpu->vm->sw.io_shared_page == NULL)
67+
if (vcpu == NULL || req == NULL || vcpu->vm->sw.io_shared_page == NULL) {
6868
return -EINVAL;
69+
}
6970

7071
req_buf = (union vhm_request_buffer *)(vcpu->vm->sw.io_shared_page);
7172

@@ -108,20 +109,22 @@ static void _get_req_info_(struct vhm_request *req, int *id, char *type,
108109
switch (req->type) {
109110
case REQ_PORTIO:
110111
(void)strcpy_s(type, 16, "PORTIO");
111-
if (req->reqs.pio_request.direction == REQUEST_READ)
112+
if (req->reqs.pio_request.direction == REQUEST_READ) {
112113
(void)strcpy_s(dir, 16, "READ");
113-
else
114+
} else {
114115
(void)strcpy_s(dir, 16, "WRITE");
116+
}
115117
*addr = req->reqs.pio_request.address;
116118
*val = req->reqs.pio_request.value;
117119
break;
118120
case REQ_MMIO:
119121
case REQ_WP:
120122
(void)strcpy_s(type, 16, "MMIO/WP");
121-
if (req->reqs.mmio_request.direction == REQUEST_READ)
123+
if (req->reqs.mmio_request.direction == REQUEST_READ) {
122124
(void)strcpy_s(dir, 16, "READ");
123-
else
125+
} else {
124126
(void)strcpy_s(dir, 16, "WRITE");
127+
}
125128
*addr = req->reqs.mmio_request.address;
126129
*val = req->reqs.mmio_request.value;
127130
break;

hypervisor/common/schedule.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ uint16_t allocate_pcpu(void)
3737
uint16_t i;
3838

3939
for (i = 0U; i < phys_cpu_num; i++) {
40-
if (bitmap_test_and_set(i, &pcpu_used_bitmap) == 0)
40+
if (bitmap_test_and_set(i, &pcpu_used_bitmap) == 0) {
4141
return i;
42+
}
4243
}
4344

4445
return INVALID_CPU_ID;
@@ -59,9 +60,10 @@ void add_vcpu_to_runqueue(struct vcpu *vcpu)
5960
int pcpu_id = vcpu->pcpu_id;
6061

6162
spinlock_obtain(&per_cpu(sched_ctx, pcpu_id).runqueue_lock);
62-
if (list_empty(&vcpu->run_list))
63+
if (list_empty(&vcpu->run_list)) {
6364
list_add_tail(&vcpu->run_list,
6465
&per_cpu(sched_ctx, pcpu_id).runqueue);
66+
}
6567
spinlock_release(&per_cpu(sched_ctx, pcpu_id).runqueue_lock);
6668
}
6769

@@ -104,8 +106,9 @@ int need_reschedule(uint16_t pcpu_id)
104106
static void context_switch_out(struct vcpu *vcpu)
105107
{
106108
/* if it's idle thread, no action for switch out */
107-
if (vcpu == NULL)
109+
if (vcpu == NULL) {
108110
return;
111+
}
109112

110113
/* cancel event(int, gp, nmi and exception) injection */
111114
cancel_event_injection(vcpu);
@@ -124,8 +127,9 @@ static void context_switch_in(struct vcpu *vcpu)
124127
get_cpu_var(sched_ctx).curr_vcpu = vcpu;
125128

126129
/* if it's idle thread, no action for switch out */
127-
if (vcpu == NULL)
130+
if (vcpu == NULL) {
128131
return;
132+
}
129133

130134
atomic_store(&vcpu->running, 1);
131135
/* FIXME:
@@ -154,12 +158,13 @@ void default_idle(void)
154158
uint16_t pcpu_id = get_cpu_id();
155159

156160
while (1) {
157-
if (need_reschedule(pcpu_id) != 0)
161+
if (need_reschedule(pcpu_id) != 0) {
158162
schedule();
159-
else if (need_offline(pcpu_id) != 0)
163+
} else if (need_offline(pcpu_id) != 0) {
160164
cpu_dead(pcpu_id);
161-
else
165+
} else {
162166
__asm __volatile("pause" ::: "memory");
167+
}
163168
}
164169
}
165170

hypervisor/common/trusty_hypercall.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ int64_t hcall_initialize_trusty(struct vcpu *vcpu, uint64_t param)
5555
return -EPERM;
5656
}
5757

58-
if (!initialize_trusty(vcpu, param))
58+
if (!initialize_trusty(vcpu, param)) {
5959
return -ENODEV;
60+
}
6061

6162
return 0;
6263
}

hypervisor/debug/console.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ static void print_char(char x)
2323
{
2424
serial_puts(serial_handle, &x, 1);
2525

26-
if (x == '\n')
26+
if (x == '\n') {
2727
serial_puts(serial_handle, "\r", 1);
28+
}
2829
}
2930

3031
int console_init(void)
@@ -154,10 +155,12 @@ void console_dump_bytes(const void *p, unsigned int len)
154155

155156
/* print one row as ASCII characters (if possible) */
156157
for (i = 0; i < 16; i++) {
157-
if ((x[i] < ' ') || (x[i] >= 127))
158+
if ((x[i] < ' ') || (x[i] >= 127)) {
158159
console_putc('.');
159-
else
160+
}
161+
else {
160162
console_putc(x[i]);
163+
}
161164
}
162165
/* continue with next row */
163166
console_putc('\n');
@@ -217,6 +220,7 @@ void console_setup_timer(void)
217220
fire_tsc, TICK_MODE_PERIODIC, period_in_cycle);
218221

219222
/* Start an periodic timer */
220-
if (add_timer(&console_timer) != 0)
223+
if (add_timer(&console_timer) != 0) {
221224
pr_err("Failed to add console kick timer");
225+
}
222226
}

hypervisor/debug/logmsg.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@ static inline void alloc_earlylog_sbuf(uint16_t pcpu_id)
2727
- SBUF_HEAD_SIZE) / ele_size;
2828

2929
per_cpu(earlylog_sbuf, pcpu_id) = sbuf_allocate(ele_num, ele_size);
30-
if (per_cpu(earlylog_sbuf, pcpu_id) == NULL)
30+
if (per_cpu(earlylog_sbuf, pcpu_id) == NULL) {
3131
printf("failed to allcate sbuf for hvlog - %hu\n", pcpu_id);
32+
}
3233
}
3334

3435
static inline void free_earlylog_sbuf(uint16_t pcpu_id)
3536
{
36-
if (per_cpu(earlylog_sbuf, pcpu_id) == NULL)
37+
if (per_cpu(earlylog_sbuf, pcpu_id) == NULL) {
3738
return;
39+
}
3840

3941
free(per_cpu(earlylog_sbuf, pcpu_id));
4042
per_cpu(earlylog_sbuf, pcpu_id) = NULL;
@@ -61,9 +63,10 @@ static int do_copy_earlylog(struct shared_buf *dst_sbuf,
6163

6264
(void)memcpy_s((void *)dst_sbuf, buf_size,
6365
(void *)src_sbuf, valid_size);
64-
if (dst_sbuf->tail != cur_tail)
66+
if (dst_sbuf->tail != cur_tail) {
6567
/* there is chance to lose new log from certain pcpu */
6668
dst_sbuf->tail = cur_tail;
69+
}
6770

6871
return 0;
6972
}
@@ -96,8 +99,9 @@ void do_logmsg(uint32_t severity, const char *fmt, ...)
9699
do_mem_log = ((logmsg.flags & LOG_FLAG_MEMORY) != 0U &&
97100
(severity <= mem_loglevel));
98101

99-
if (!do_console_log && !do_mem_log)
102+
if (!do_console_log && !do_mem_log) {
100103
return;
104+
}
101105

102106
/* Get time-stamp value */
103107
timestamp = rdtsc();
@@ -170,34 +174,39 @@ void print_logmsg_buffer(uint16_t pcpu_id)
170174
struct shared_buf **sbuf;
171175
int is_earlylog = 0;
172176

173-
if (pcpu_id >= phys_cpu_num)
177+
if (pcpu_id >= phys_cpu_num) {
174178
return;
179+
}
175180

176181
if (per_cpu(earlylog_sbuf, pcpu_id) != NULL) {
177182
sbuf = &per_cpu(earlylog_sbuf, pcpu_id);
178183
is_earlylog = 1;
179-
} else
184+
} else {
180185
sbuf = (struct shared_buf **)
181186
&per_cpu(sbuf, pcpu_id)[ACRN_HVLOG];
187+
}
182188

183189
spinlock_irqsave_obtain(&(logmsg.lock));
184-
if ((*sbuf) != NULL)
190+
if ((*sbuf) != NULL) {
185191
printf("CPU%hu: head: 0x%x, tail: 0x%x %s\n\r",
186192
pcpu_id, (*sbuf)->head, (*sbuf)->tail,
187193
(is_earlylog != 0) ? "[earlylog]" : "");
194+
}
188195
spinlock_irqrestore_release(&(logmsg.lock));
189196

190197
do {
191198
uint32_t idx;
192199
(void)memset(buffer, 0, LOG_ENTRY_SIZE + 1);
193200

194-
if (*sbuf == NULL)
201+
if (*sbuf == NULL) {
195202
return;
203+
}
196204

197205
read_cnt = sbuf_get(*sbuf, (uint8_t *)buffer);
198206

199-
if (read_cnt <= 0)
207+
if (read_cnt <= 0) {
200208
return;
209+
}
201210

202211
idx = (read_cnt < LOG_ENTRY_SIZE) ? read_cnt : LOG_ENTRY_SIZE;
203212
buffer[idx] = '\0';

hypervisor/debug/printf.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,16 @@ static int charout(int cmd, const char *s, int sz, void *hnd)
1616
/* copy mode ? */
1717
if (cmd == PRINT_CMD_COPY) {
1818
/* copy all characters until NUL is found */
19-
if (sz < 0)
19+
if (sz < 0) {
2020
s += console_puts(s);
21-
22-
/* copy 'sz' characters */
23-
else
21+
} else { /* copy 'sz' characters */
2422
s += console_write(s, sz);
23+
}
2524

2625
*nchars += (s - p);
2726
return *nchars;
28-
}
27+
} else {
2928
/* fill mode */
30-
else {
3129
*nchars += sz;
3230
while (sz != 0) {
3331
console_putc(*s);

hypervisor/debug/sbuf.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ struct shared_buf *sbuf_allocate(uint32_t ele_num, uint32_t ele_size)
5151
}
5252

5353
sbuf_allocate_size = sbuf_calculate_allocate_size(ele_num, ele_size);
54-
if (sbuf_allocate_size == 0U)
54+
if (sbuf_allocate_size == 0U) {
5555
return NULL;
56+
}
5657

5758
sbuf = calloc(1, sbuf_allocate_size);
5859
if (sbuf == NULL) {
@@ -84,8 +85,9 @@ int sbuf_get(struct shared_buf *sbuf, uint8_t *data)
8485
{
8586
const void *from;
8687

87-
if ((sbuf == NULL) || (data == NULL))
88+
if ((sbuf == NULL) || (data == NULL)) {
8889
return -EINVAL;
90+
}
8991

9092
if (sbuf_is_empty(sbuf)) {
9193
/* no data available */
@@ -125,8 +127,9 @@ int sbuf_put(struct shared_buf *sbuf, uint8_t *data)
125127
uint32_t next_tail;
126128
bool trigger_overwrite = false;
127129

128-
if ((sbuf == NULL) || (data == NULL))
130+
if ((sbuf == NULL) || (data == NULL)) {
129131
return -EINVAL;
132+
}
130133

131134
next_tail = sbuf_next_ptr(sbuf->tail, sbuf->ele_size, sbuf->size);
132135
/* if this write would trigger overrun */
@@ -156,8 +159,9 @@ int sbuf_put(struct shared_buf *sbuf, uint8_t *data)
156159
int sbuf_share_setup(uint16_t pcpu_id, uint32_t sbuf_id, uint64_t *hva)
157160
{
158161
if (pcpu_id >= phys_cpu_num ||
159-
sbuf_id >= ACRN_SBUF_ID_MAX)
162+
sbuf_id >= ACRN_SBUF_ID_MAX) {
160163
return -EINVAL;
164+
}
161165

162166
per_cpu(sbuf, pcpu_id)[sbuf_id] = hva;
163167
pr_info("%s share sbuf for pCPU[%u] with sbuf_id[%u] setup successfully",

0 commit comments

Comments
 (0)