From af806a93bd125a4e560170aef5454a65debbad4f Mon Sep 17 00:00:00 2001 From: Arindam Roy Date: Thu, 12 Jul 2018 15:02:55 -0700 Subject: [PATCH] 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 --- hypervisor/common/io_request.c | 13 +++--- hypervisor/common/schedule.c | 19 +++++---- hypervisor/common/trusty_hypercall.c | 3 +- hypervisor/debug/console.c | 12 ++++-- hypervisor/debug/logmsg.c | 27 ++++++++----- hypervisor/debug/printf.c | 10 ++--- hypervisor/debug/sbuf.c | 12 ++++-- hypervisor/debug/serial.c | 60 ++++++++++++++++++---------- hypervisor/debug/shell_internal.c | 39 ++++++++++++------ hypervisor/debug/shell_public.c | 6 ++- hypervisor/debug/uart16550.c | 18 ++++++--- hypervisor/debug/vuart.c | 38 +++++++++++------- hypervisor/include/arch/x86/io.h | 13 +++--- hypervisor/include/debug/trace.h | 18 ++++++--- hypervisor/include/lib/bits.h | 17 ++++---- hypervisor/include/lib/list.h | 3 +- hypervisor/lib/div.c | 3 +- 17 files changed, 200 insertions(+), 111 deletions(-) diff --git a/hypervisor/common/io_request.c b/hypervisor/common/io_request.c index 23eeb3b58..74c584ace 100644 --- a/hypervisor/common/io_request.c +++ b/hypervisor/common/io_request.c @@ -64,8 +64,9 @@ int32_t acrn_insert_request_wait(struct vcpu *vcpu, struct vhm_request *req) "vhm_request page broken!"); - if (vcpu == NULL || req == NULL || vcpu->vm->sw.io_shared_page == NULL) + if (vcpu == NULL || req == NULL || vcpu->vm->sw.io_shared_page == NULL) { return -EINVAL; + } req_buf = (union vhm_request_buffer *)(vcpu->vm->sw.io_shared_page); @@ -108,20 +109,22 @@ static void _get_req_info_(struct vhm_request *req, int *id, char *type, switch (req->type) { case REQ_PORTIO: (void)strcpy_s(type, 16, "PORTIO"); - if (req->reqs.pio_request.direction == REQUEST_READ) + if (req->reqs.pio_request.direction == REQUEST_READ) { (void)strcpy_s(dir, 16, "READ"); - else + } else { (void)strcpy_s(dir, 16, "WRITE"); + } *addr = req->reqs.pio_request.address; *val = req->reqs.pio_request.value; break; case REQ_MMIO: case REQ_WP: (void)strcpy_s(type, 16, "MMIO/WP"); - if (req->reqs.mmio_request.direction == REQUEST_READ) + if (req->reqs.mmio_request.direction == REQUEST_READ) { (void)strcpy_s(dir, 16, "READ"); - else + } else { (void)strcpy_s(dir, 16, "WRITE"); + } *addr = req->reqs.mmio_request.address; *val = req->reqs.mmio_request.value; break; diff --git a/hypervisor/common/schedule.c b/hypervisor/common/schedule.c index 59e46223f..b4c5d584d 100644 --- a/hypervisor/common/schedule.c +++ b/hypervisor/common/schedule.c @@ -37,8 +37,9 @@ uint16_t allocate_pcpu(void) uint16_t i; for (i = 0U; i < phys_cpu_num; i++) { - if (bitmap_test_and_set(i, &pcpu_used_bitmap) == 0) + if (bitmap_test_and_set(i, &pcpu_used_bitmap) == 0) { return i; + } } return INVALID_CPU_ID; @@ -59,9 +60,10 @@ void add_vcpu_to_runqueue(struct vcpu *vcpu) int pcpu_id = vcpu->pcpu_id; spinlock_obtain(&per_cpu(sched_ctx, pcpu_id).runqueue_lock); - if (list_empty(&vcpu->run_list)) + if (list_empty(&vcpu->run_list)) { list_add_tail(&vcpu->run_list, &per_cpu(sched_ctx, pcpu_id).runqueue); + } spinlock_release(&per_cpu(sched_ctx, pcpu_id).runqueue_lock); } @@ -104,8 +106,9 @@ int need_reschedule(uint16_t pcpu_id) static void context_switch_out(struct vcpu *vcpu) { /* if it's idle thread, no action for switch out */ - if (vcpu == NULL) + if (vcpu == NULL) { return; + } /* cancel event(int, gp, nmi and exception) injection */ cancel_event_injection(vcpu); @@ -124,8 +127,9 @@ static void context_switch_in(struct vcpu *vcpu) get_cpu_var(sched_ctx).curr_vcpu = vcpu; /* if it's idle thread, no action for switch out */ - if (vcpu == NULL) + if (vcpu == NULL) { return; + } atomic_store(&vcpu->running, 1); /* FIXME: @@ -154,12 +158,13 @@ void default_idle(void) uint16_t pcpu_id = get_cpu_id(); while (1) { - if (need_reschedule(pcpu_id) != 0) + if (need_reschedule(pcpu_id) != 0) { schedule(); - else if (need_offline(pcpu_id) != 0) + } else if (need_offline(pcpu_id) != 0) { cpu_dead(pcpu_id); - else + } else { __asm __volatile("pause" ::: "memory"); + } } } diff --git a/hypervisor/common/trusty_hypercall.c b/hypervisor/common/trusty_hypercall.c index cae5cb536..c36d56104 100644 --- a/hypervisor/common/trusty_hypercall.c +++ b/hypervisor/common/trusty_hypercall.c @@ -55,8 +55,9 @@ int64_t hcall_initialize_trusty(struct vcpu *vcpu, uint64_t param) return -EPERM; } - if (!initialize_trusty(vcpu, param)) + if (!initialize_trusty(vcpu, param)) { return -ENODEV; + } return 0; } diff --git a/hypervisor/debug/console.c b/hypervisor/debug/console.c index 81689276a..1ae22a0d6 100644 --- a/hypervisor/debug/console.c +++ b/hypervisor/debug/console.c @@ -23,8 +23,9 @@ static void print_char(char x) { serial_puts(serial_handle, &x, 1); - if (x == '\n') + if (x == '\n') { serial_puts(serial_handle, "\r", 1); + } } int console_init(void) @@ -154,10 +155,12 @@ void console_dump_bytes(const void *p, unsigned int len) /* print one row as ASCII characters (if possible) */ for (i = 0; i < 16; i++) { - if ((x[i] < ' ') || (x[i] >= 127)) + if ((x[i] < ' ') || (x[i] >= 127)) { console_putc('.'); - else + } + else { console_putc(x[i]); + } } /* continue with next row */ console_putc('\n'); @@ -217,6 +220,7 @@ void console_setup_timer(void) fire_tsc, TICK_MODE_PERIODIC, period_in_cycle); /* Start an periodic timer */ - if (add_timer(&console_timer) != 0) + if (add_timer(&console_timer) != 0) { pr_err("Failed to add console kick timer"); + } } diff --git a/hypervisor/debug/logmsg.c b/hypervisor/debug/logmsg.c index 79ebbb9cb..142029015 100644 --- a/hypervisor/debug/logmsg.c +++ b/hypervisor/debug/logmsg.c @@ -27,14 +27,16 @@ static inline void alloc_earlylog_sbuf(uint16_t pcpu_id) - SBUF_HEAD_SIZE) / ele_size; per_cpu(earlylog_sbuf, pcpu_id) = sbuf_allocate(ele_num, ele_size); - if (per_cpu(earlylog_sbuf, pcpu_id) == NULL) + if (per_cpu(earlylog_sbuf, pcpu_id) == NULL) { printf("failed to allcate sbuf for hvlog - %hu\n", pcpu_id); + } } static inline void free_earlylog_sbuf(uint16_t pcpu_id) { - if (per_cpu(earlylog_sbuf, pcpu_id) == NULL) + if (per_cpu(earlylog_sbuf, pcpu_id) == NULL) { return; + } free(per_cpu(earlylog_sbuf, pcpu_id)); per_cpu(earlylog_sbuf, pcpu_id) = NULL; @@ -61,9 +63,10 @@ static int do_copy_earlylog(struct shared_buf *dst_sbuf, (void)memcpy_s((void *)dst_sbuf, buf_size, (void *)src_sbuf, valid_size); - if (dst_sbuf->tail != cur_tail) + if (dst_sbuf->tail != cur_tail) { /* there is chance to lose new log from certain pcpu */ dst_sbuf->tail = cur_tail; + } return 0; } @@ -96,8 +99,9 @@ void do_logmsg(uint32_t severity, const char *fmt, ...) do_mem_log = ((logmsg.flags & LOG_FLAG_MEMORY) != 0U && (severity <= mem_loglevel)); - if (!do_console_log && !do_mem_log) + if (!do_console_log && !do_mem_log) { return; + } /* Get time-stamp value */ timestamp = rdtsc(); @@ -170,34 +174,39 @@ void print_logmsg_buffer(uint16_t pcpu_id) struct shared_buf **sbuf; int is_earlylog = 0; - if (pcpu_id >= phys_cpu_num) + if (pcpu_id >= phys_cpu_num) { return; + } if (per_cpu(earlylog_sbuf, pcpu_id) != NULL) { sbuf = &per_cpu(earlylog_sbuf, pcpu_id); is_earlylog = 1; - } else + } else { sbuf = (struct shared_buf **) &per_cpu(sbuf, pcpu_id)[ACRN_HVLOG]; + } spinlock_irqsave_obtain(&(logmsg.lock)); - if ((*sbuf) != NULL) + if ((*sbuf) != NULL) { printf("CPU%hu: head: 0x%x, tail: 0x%x %s\n\r", pcpu_id, (*sbuf)->head, (*sbuf)->tail, (is_earlylog != 0) ? "[earlylog]" : ""); + } spinlock_irqrestore_release(&(logmsg.lock)); do { uint32_t idx; (void)memset(buffer, 0, LOG_ENTRY_SIZE + 1); - if (*sbuf == NULL) + if (*sbuf == NULL) { return; + } read_cnt = sbuf_get(*sbuf, (uint8_t *)buffer); - if (read_cnt <= 0) + if (read_cnt <= 0) { return; + } idx = (read_cnt < LOG_ENTRY_SIZE) ? read_cnt : LOG_ENTRY_SIZE; buffer[idx] = '\0'; diff --git a/hypervisor/debug/printf.c b/hypervisor/debug/printf.c index 84f3c3af3..3d7fd5c33 100644 --- a/hypervisor/debug/printf.c +++ b/hypervisor/debug/printf.c @@ -16,18 +16,16 @@ static int charout(int cmd, const char *s, int sz, void *hnd) /* copy mode ? */ if (cmd == PRINT_CMD_COPY) { /* copy all characters until NUL is found */ - if (sz < 0) + if (sz < 0) { s += console_puts(s); - - /* copy 'sz' characters */ - else + } else { /* copy 'sz' characters */ s += console_write(s, sz); + } *nchars += (s - p); return *nchars; - } + } else { /* fill mode */ - else { *nchars += sz; while (sz != 0) { console_putc(*s); diff --git a/hypervisor/debug/sbuf.c b/hypervisor/debug/sbuf.c index 2f57b245f..2b165230b 100644 --- a/hypervisor/debug/sbuf.c +++ b/hypervisor/debug/sbuf.c @@ -51,8 +51,9 @@ struct shared_buf *sbuf_allocate(uint32_t ele_num, uint32_t ele_size) } sbuf_allocate_size = sbuf_calculate_allocate_size(ele_num, ele_size); - if (sbuf_allocate_size == 0U) + if (sbuf_allocate_size == 0U) { return NULL; + } sbuf = calloc(1, sbuf_allocate_size); if (sbuf == NULL) { @@ -84,8 +85,9 @@ int sbuf_get(struct shared_buf *sbuf, uint8_t *data) { const void *from; - if ((sbuf == NULL) || (data == NULL)) + if ((sbuf == NULL) || (data == NULL)) { return -EINVAL; + } if (sbuf_is_empty(sbuf)) { /* no data available */ @@ -125,8 +127,9 @@ int sbuf_put(struct shared_buf *sbuf, uint8_t *data) uint32_t next_tail; bool trigger_overwrite = false; - if ((sbuf == NULL) || (data == NULL)) + if ((sbuf == NULL) || (data == NULL)) { return -EINVAL; + } next_tail = sbuf_next_ptr(sbuf->tail, sbuf->ele_size, sbuf->size); /* if this write would trigger overrun */ @@ -156,8 +159,9 @@ int sbuf_put(struct shared_buf *sbuf, uint8_t *data) int sbuf_share_setup(uint16_t pcpu_id, uint32_t sbuf_id, uint64_t *hva) { if (pcpu_id >= phys_cpu_num || - sbuf_id >= ACRN_SBUF_ID_MAX) + sbuf_id >= ACRN_SBUF_ID_MAX) { return -EINVAL; + } per_cpu(sbuf, pcpu_id)[sbuf_id] = hva; pr_info("%s share sbuf for pCPU[%u] with sbuf_id[%u] setup successfully", diff --git a/hypervisor/debug/serial.c b/hypervisor/debug/serial.c index 3b0c30d2d..91d80309b 100644 --- a/hypervisor/debug/serial.c +++ b/hypervisor/debug/serial.c @@ -18,13 +18,15 @@ static struct uart *get_uart_by_id(const char *uart_id, uint32_t *index) while (sio_ports[*index] != NULL) { if (strncmp(sio_ports[*index]->tgt_uart->uart_id, uart_id, strnlen_s(sio_ports[*index]->tgt_uart->uart_id, - SERIAL_ID_MAX_LENGTH)) == 0) + SERIAL_ID_MAX_LENGTH)) == 0) { break; + } /* No device is found if index reaches end of array. */ (*index)++; - if (*index == SERIAL_MAX_DEVS) + if (*index == SERIAL_MAX_DEVS) { return NULL; + } } return sio_ports[*index]; @@ -66,8 +68,9 @@ int serial_init(void) status = sio_ports[index]->tgt_uart-> init(sio_ports[index]->tgt_uart); - if (status == 0) + if (status == 0) { sio_initialized[index] = true; + } } else { status = -ENOMEM; break; @@ -105,8 +108,9 @@ uint32_t serial_open(const char *uart_id) /* Open the UART hardware with default configuration. */ status = uart->tgt_uart->open(uart->tgt_uart, &(uart->config)); - if (status == 0) + if (status == 0) { uart->open_flag = true; + } } /* Already open serial device */ @@ -135,12 +139,14 @@ uint32_t serial_get_rx_data(uint32_t uart_handle) return 0U; index = SERIAL_DECODE_INDEX(uart_handle); - if (index >= SERIAL_MAX_DEVS) + if (index >= SERIAL_MAX_DEVS) { return 0U; + } uart = sio_ports[index]; - if (uart == NULL) + if (uart == NULL) { return 0U; + } /* Place all the data available in RX FIFO, in circular buffer */ data_avail = uart->tgt_uart->rx_data_is_avail( @@ -192,18 +198,21 @@ int serial_getc(uint32_t uart_handle) uint32_t index; int status = SERIAL_DEV_NOT_FOUND; - if (!SERIAL_VALIDATE_HANDLE(uart_handle)) + if (!SERIAL_VALIDATE_HANDLE(uart_handle)) { goto exit; + } index = SERIAL_DECODE_INDEX(uart_handle); - if (index >= SERIAL_MAX_DEVS) + if (index >= SERIAL_MAX_DEVS) { goto exit; + } port = sio_ports[index]; - if (port == NULL) + if (port == NULL) { goto exit; + } /* First read a character from the circular buffer regardless of the * read mode of UART port. If status is not CBUFFER_EMPTY, character @@ -235,15 +244,18 @@ int serial_gets(uint32_t uart_handle, char *buffer, uint32_t length) uint32_t index; int status = 0; - if ((buffer == NULL) || (length == 0U)) + if ((buffer == NULL) || (length == 0U)) { return 0; + } - if (!SERIAL_VALIDATE_HANDLE(uart_handle)) + if (!SERIAL_VALIDATE_HANDLE(uart_handle)) { return 0; + } index = SERIAL_DECODE_INDEX(uart_handle); - if (index >= SERIAL_MAX_DEVS) + if (index >= SERIAL_MAX_DEVS) { return 0; + } port = sio_ports[index]; if ((port != NULL) && (port->open_flag == true)) { @@ -256,8 +268,9 @@ int serial_gets(uint32_t uart_handle, char *buffer, uint32_t length) /* Restore interrupts to original level. */ spinlock_release(&port->buffer_lock); - if (status <= 0) + if (status <= 0) { break; + } /* Save character in buffer */ *data_read = (char) c; @@ -274,18 +287,21 @@ static int serial_putc(uint32_t uart_handle, int c) struct uart *uart; int busy; - if (!SERIAL_VALIDATE_HANDLE(uart_handle)) + if (!SERIAL_VALIDATE_HANDLE(uart_handle)) { return SERIAL_EOF; + } index = SERIAL_DECODE_INDEX(uart_handle); - if (index >= SERIAL_MAX_DEVS) + if (index >= SERIAL_MAX_DEVS) { return SERIAL_EOF; + } uart = sio_ports[index]; - if (uart == NULL) + if (uart == NULL) { return SERIAL_EOF; + } /* Wait for TX hardware to be ready */ do { @@ -306,21 +322,25 @@ int serial_puts(uint32_t uart_handle, const char *s, uint32_t length) struct uart *port; int retval = 0; - if ((s == NULL) || (length == 0U)) + if ((s == NULL) || (length == 0U)) { return 0; + } - if (!SERIAL_VALIDATE_HANDLE(uart_handle)) + if (!SERIAL_VALIDATE_HANDLE(uart_handle)) { return 0; + } index = SERIAL_DECODE_INDEX(uart_handle); - if (index >= SERIAL_MAX_DEVS) + if (index >= SERIAL_MAX_DEVS) { return 0; + } port = sio_ports[index]; - if (port == NULL) + if (port == NULL) { return 0; + } /* * Grab the semaphore so that strings between threads do not diff --git a/hypervisor/debug/shell_internal.c b/hypervisor/debug/shell_internal.c index 765e72b2d..78caa58e7 100644 --- a/hypervisor/debug/shell_internal.c +++ b/hypervisor/debug/shell_internal.c @@ -240,13 +240,15 @@ struct shell_cmd *shell_find_cmd(struct shell *p_shell, const char *cmd_str) uint32_t i; struct shell_cmd *p_cmd = NULL; - if (p_shell->cmd_count <= 0U) + if (p_shell->cmd_count <= 0U) { return NULL; + } for (i = 0U; i < p_shell->cmd_count; i++) { p_cmd = &p_shell->shell_cmd[i]; - if (strcmp(p_cmd->str, cmd_str) == 0) + if (strcmp(p_cmd->str, cmd_str) == 0) { break; + } } if (i == p_shell->cmd_count) { @@ -274,9 +276,10 @@ void kick_shell(struct shell *p_shell) if (vuart_console_active() == NULL) { /* Prompt the user for a selection. */ if ((is_cmd_cmplt != 0U) && - (p_shell->session_io.io_puts != NULL)) + (p_shell->session_io.io_puts != NULL)) { p_shell->session_io.io_puts(p_shell, SHELL_PROMPT_STR); + } /* Get user's input */ is_cmd_cmplt = shell_input_line(p_shell); @@ -284,9 +287,10 @@ void kick_shell(struct shell *p_shell) /* If user has pressed the ENTER then process * the command */ - if (is_cmd_cmplt != 0U) + if (is_cmd_cmplt != 0U) { /* Process current input line. */ status = shell_process(p_shell); + } } } else { /* Serial port handle couldn't be obtained. Stop the shell @@ -795,8 +799,9 @@ int shell_vcpu_dumpmem(struct shell *p_shell, gva = strtoul_hex(argv[3]); - if (argc == 5) + if (argc == 5) { length = atoi(argv[4]); + } if (length > MAX_MEMDUMP_LEN) { shell_puts(p_shell, "over max length, round back\r\n"); @@ -884,8 +889,9 @@ int shell_show_cpu_int(struct shell *p_shell, { char *temp_str = alloc_page(); - if (temp_str == NULL) + if (temp_str == NULL) { return -ENOMEM; + } get_cpu_interrupt_info(temp_str, CPU_PAGE_SIZE); shell_puts(p_shell, temp_str); @@ -900,8 +906,9 @@ int shell_show_ptdev_info(struct shell *p_shell, { char *temp_str = alloc_page(); - if (temp_str == NULL) + if (temp_str == NULL) { return -ENOMEM; + } get_ptdev_info(temp_str, CPU_PAGE_SIZE); shell_puts(p_shell, temp_str); @@ -922,8 +929,9 @@ int shell_show_req_info(struct shell *p_shell, { char *temp_str = alloc_page(); - if (temp_str == NULL) + if (temp_str == NULL) { return -ENOMEM; + } get_req_info(temp_str, CPU_PAGE_SIZE); shell_puts(p_shell, temp_str); @@ -938,15 +946,17 @@ int shell_show_vioapic_info(struct shell *p_shell, int argc, char **argv) char *temp_str = alloc_page(); uint32_t vmid; - if (temp_str == NULL) + if (temp_str == NULL) { return -ENOMEM; + } /* User input invalidation */ if (argc != 2) { snprintf(temp_str, CPU_PAGE_SIZE, "\r\nvmid param needed\r\n"); goto END; - } else + } else { vmid = atoi(argv[1]); + } get_vioapic_info(temp_str, CPU_PAGE_SIZE, vmid); END: @@ -961,8 +971,9 @@ int shell_show_ioapic_info(struct shell *p_shell, { char *temp_str = alloc_pages(2); - if (temp_str == NULL) + if (temp_str == NULL) { return -ENOMEM; + } get_ioapic_info(temp_str, 2 * CPU_PAGE_SIZE); shell_puts(p_shell, temp_str); @@ -977,8 +988,9 @@ int shell_show_vmexit_profile(struct shell *p_shell, { char *temp_str = alloc_pages(2); - if (temp_str == NULL) + if (temp_str == NULL) { return -ENOMEM; + } get_vmexit_profile(temp_str, 2*CPU_PAGE_SIZE); shell_puts(p_shell, temp_str); @@ -997,8 +1009,9 @@ int shell_dump_logbuf(__unused struct shell *p_shell, if (argc == 2) { val = atoi(argv[1]); - if (val < 0) + if (val < 0) { return status; + } pcpu_id = (uint16_t)val; print_logmsg_buffer(pcpu_id); return 0; diff --git a/hypervisor/debug/shell_public.c b/hypervisor/debug/shell_public.c index c07d1076a..17ed1c40b 100644 --- a/hypervisor/debug/shell_public.c +++ b/hypervisor/debug/shell_public.c @@ -138,8 +138,9 @@ int shell_init(void) int status; status = shell_construct(&serial_session); - if (status != 0) + if (status != 0) { return status; + } /* Set the function pointers for the shell i/p and o/p functions */ serial_session->session_io.io_init = shell_init_serial; @@ -201,8 +202,9 @@ int shell_switch_console(void) struct vuart *vuart; vuart = vuart_console_active(); - if (vuart == NULL) + if (vuart == NULL) { return -EINVAL; + } vuart->active = false; /* Output that switching to ACRN shell */ diff --git a/hypervisor/debug/uart16550.c b/hypervisor/debug/uart16550.c index 80d5ec354..42ce4b74c 100644 --- a/hypervisor/debug/uart16550.c +++ b/hypervisor/debug/uart16550.c @@ -89,8 +89,9 @@ static int uart16550_calc_baud_div(__unused struct tgt_uart *tgt_uart, { uint32_t baud_multiplier = baud_rate < BAUD_460800 ? 16 : 13; - if (baud_rate == 0) + if (baud_rate == 0) { baud_rate = BAUD_115200; + } *baud_div_ptr = ref_freq / (baud_multiplier * baud_rate); return 0; @@ -154,8 +155,9 @@ static int uart16550_open(struct tgt_uart *tgt_uart, int status = 0; if (strcmp(tgt_uart->uart_id, "STDIO") == 0) { - if (atomic_cmpxchg(&tgt_uart->open_count, 0, 1) != 0) + if (atomic_cmpxchg(&tgt_uart->open_count, 0, 1) != 0) { return -EBUSY; + } /* Call UART setup function */ /* Enable TX and RX FIFOs */ @@ -221,16 +223,19 @@ static uint32_t uart16550_get_rx_err(uint32_t rx_data) uint32_t rx_status = SD_RX_NO_ERROR; /* Check for RX overrun error */ - if ((rx_data & LSR_OE) != 0U) + if ((rx_data & LSR_OE) != 0U) { rx_status |= SD_RX_OVERRUN_ERROR; + } /* Check for RX parity error */ - if ((rx_data & LSR_PE) != 0U) + if ((rx_data & LSR_PE) != 0U) { rx_status |= SD_RX_PARITY_ERROR; + } /* Check for RX frame error */ - if ((rx_data & LSR_FE) != 0U) + if ((rx_data & LSR_FE) != 0U) { rx_status |= SD_RX_FRAME_ERROR; + } /* Return the rx status */ return rx_status; @@ -274,8 +279,9 @@ static void uart16550_write(struct tgt_uart *tgt_uart, uart16550_write_reg(tgt_uart->base_address, *(uint8_t *)buffer, THR_IDX); - if (bytes_written != NULL) + if (bytes_written != NULL) { *bytes_written = 1; + } } static bool uart16550_tx_is_busy(struct tgt_uart *tgt_uart) diff --git a/hypervisor/debug/vuart.c b/hypervisor/debug/vuart.c index b32e3ea7e..974109b86 100644 --- a/hypervisor/debug/vuart.c +++ b/hypervisor/debug/vuart.c @@ -82,8 +82,9 @@ static char fifo_getchar(struct fifo *fifo) fifo->rindex = (fifo->rindex + 1) % fifo->size; fifo->num--; return c; - } else + } else { return -1; + } } static int fifo_numchars(struct fifo *fifo) @@ -100,14 +101,15 @@ static int fifo_numchars(struct fifo *fifo) */ static uint8_t uart_intr_reason(struct vuart *vu) { - if ((vu->lsr & LSR_OE) != 0 && (vu->ier & IER_ELSI) != 0) + if ((vu->lsr & LSR_OE) != 0 && (vu->ier & IER_ELSI) != 0) { return IIR_RLS; - else if (fifo_numchars(&vu->rxfifo) > 0 && (vu->ier & IER_ERBFI) != 0) + } else if (fifo_numchars(&vu->rxfifo) > 0 && (vu->ier & IER_ERBFI) != 0) { return IIR_RXTOUT; - else if (vu->thre_int_pending && (vu->ier & IER_ETBEI) != 0) + } else if (vu->thre_int_pending && (vu->ier & IER_ETBEI) != 0) { return IIR_TXRDY; - else + } else { return IIR_NOPEND; + } } static void uart_init(struct vuart *vu) @@ -136,12 +138,14 @@ static void uart_toggle_intr(struct vuart *vu) intr_reason = uart_intr_reason(vu); if (intr_reason != IIR_NOPEND) { - if (vu->vm->vpic != NULL) + if (vu->vm->vpic != NULL) { vpic_assert_irq(vu->vm, COM1_IRQ); + } vioapic_assert_irq(vu->vm, COM1_IRQ); - if (vu->vm->vpic != NULL) + if (vu->vm->vpic != NULL) { vpic_deassert_irq(vu->vm, COM1_IRQ); + } vioapic_deassert_irq(vu->vm, COM1_IRQ); } @@ -189,8 +193,9 @@ static void uart_write(__unused struct vm_io_handler *hdlr, if ((value & FCR_FIFOE) == 0) { vu->fcr = 0; } else { - if ((value & FCR_RFR) != 0) + if ((value & FCR_RFR) != 0) { fifo_reset(&vu->rxfifo); + } vu->fcr = value & (FCR_FIFOE | FCR_DMA | FCR_RX_MASK); @@ -262,8 +267,9 @@ static uint32_t uart_read(__unused struct vm_io_handler *hdlr, /* * Deal with side effects of reading the IIR register */ - if (intr_reason == IIR_TXRDY) + if (intr_reason == IIR_TXRDY) { vu->thre_int_pending = false; + } iir |= intr_reason; reg = iir; break; @@ -277,10 +283,11 @@ static uint32_t uart_read(__unused struct vm_io_handler *hdlr, /* Transmitter is always ready for more data */ vu->lsr |= LSR_TEMT | LSR_THRE; /* Check for new receive data */ - if (fifo_numchars(&vu->rxfifo) > 0) + if (fifo_numchars(&vu->rxfifo) > 0) { vu->lsr |= LSR_DR; - else + } else { vu->lsr &= ~LSR_DR; + } reg = vu->lsr; /* The LSR_OE bit is cleared on LSR read */ vu->lsr &= ~LSR_OE; @@ -318,8 +325,9 @@ void vuart_console_tx_chars(void) struct vuart *vu; vu = vuart_console_active(); - if (vu == NULL) + if (vu == NULL) { return; + } vuart_lock(vu); while (fifo_numchars(&vu->txfifo) > 0) { @@ -342,8 +350,9 @@ void vuart_console_rx_chars(uint32_t serial_handle) } vu = vuart_console_active(); - if (vu == NULL) + if (vu == NULL) { return; + } vuart_lock(vu); /* Get data from serial */ @@ -377,8 +386,9 @@ struct vuart *vuart_console_active(void) if ((vm != NULL) && (vm->vuart != NULL)) { struct vuart *vu = vm->vuart; - if (vu->active) + if (vu->active) { return vm->vuart; + } } return NULL; } diff --git a/hypervisor/include/arch/x86/io.h b/hypervisor/include/arch/x86/io.h index 38aad426f..29756bad0 100644 --- a/hypervisor/include/arch/x86/io.h +++ b/hypervisor/include/arch/x86/io.h @@ -63,20 +63,23 @@ static inline uint32_t io_read_long(uint16_t port) static inline void io_write(uint32_t v, uint16_t addr, size_t sz) { - if (sz == 1U) + if (sz == 1U) { io_write_byte((uint8_t)v, addr); - else if (sz == 2U) + } else if (sz == 2U) { io_write_word((uint16_t)v, addr); - else + } else { io_write_long(v, addr); + } } static inline uint32_t io_read(uint16_t addr, size_t sz) { - if (sz == 1U) + if (sz == 1U) { return io_read_byte(addr); - if (sz == 2U) + } + if (sz == 2U) { return io_read_word(addr); + } return io_read_long(addr); } diff --git a/hypervisor/include/debug/trace.h b/hypervisor/include/debug/trace.h index 580376ace..a24e28ba0 100644 --- a/hypervisor/include/debug/trace.h +++ b/hypervisor/include/debug/trace.h @@ -78,11 +78,13 @@ struct trace_entry { static inline bool trace_check(uint16_t cpu_id, __unused uint32_t evid) { - if (cpu_id >= phys_cpu_num) + if (cpu_id >= phys_cpu_num) { return false; + } - if (per_cpu(sbuf, cpu_id)[ACRN_TRACE] == NULL) + if (per_cpu(sbuf, cpu_id)[ACRN_TRACE] == NULL) { return false; + } return true; } @@ -107,8 +109,9 @@ TRACE_2L(uint32_t evid, uint64_t e, uint64_t f) struct trace_entry entry; uint16_t cpu_id = get_cpu_id(); - if (!trace_check(cpu_id, evid)) + if (!trace_check(cpu_id, evid)) { return; + } entry.payload.fields_64.e = e; entry.payload.fields_64.f = f; @@ -122,8 +125,9 @@ TRACE_4I(uint32_t evid, uint32_t a, uint32_t b, uint32_t c, struct trace_entry entry; uint16_t cpu_id = get_cpu_id(); - if (!trace_check(cpu_id, evid)) + if (!trace_check(cpu_id, evid)) { return; + } entry.payload.fields_32.a = a; entry.payload.fields_32.b = b; @@ -139,8 +143,9 @@ TRACE_6C(uint32_t evid, uint8_t a1, uint8_t a2, uint8_t a3, struct trace_entry entry; uint16_t cpu_id = get_cpu_id(); - if (!trace_check(cpu_id, evid)) + if (!trace_check(cpu_id, evid)) { return; + } entry.payload.fields_8.a1 = a1; entry.payload.fields_8.a2 = a2; @@ -162,8 +167,9 @@ TRACE_16STR(uint32_t evid, const char name[]) uint16_t cpu_id = get_cpu_id(); size_t len, i; - if (!trace_check(cpu_id, evid)) + if (!trace_check(cpu_id, evid)) { return; + } entry.payload.fields_64.e = 0UL; entry.payload.fields_64.f = 0UL; diff --git a/hypervisor/include/lib/bits.h b/hypervisor/include/lib/bits.h index f2ca0992a..73df81aef 100644 --- a/hypervisor/include/lib/bits.h +++ b/hypervisor/include/lib/bits.h @@ -66,8 +66,9 @@ static inline uint16_t fls32(uint32_t value) { uint32_t ret = 0U; - if (value == 0U) + if (value == 0U) { return (INVALID_BIT_INDEX); + } asm volatile("bsrl %1,%0" : "=r" (ret) : "rm" (value)); @@ -77,8 +78,9 @@ static inline uint16_t fls32(uint32_t value) static inline uint16_t fls64(uint64_t value) { uint64_t ret = 0UL; - if (value == 0UL) + if (value == 0UL) { return (INVALID_BIT_INDEX); + } asm volatile("bsrq %1,%0" : "=r" (ret) : "rm" (value)); @@ -113,8 +115,9 @@ static inline uint16_t fls64(uint64_t value) static inline uint16_t ffs64(uint64_t value) { uint64_t ret = 0UL; - if (value == 0UL) + if (value == 0UL) { return (INVALID_BIT_INDEX); + } asm volatile("bsfq %1,%0" : "=r" (ret) : "rm" (value)); @@ -144,9 +147,9 @@ static inline uint16_t ffz64(uint64_t value) */ static inline uint16_t clz(uint32_t value) { - if (value == 0U) + if (value == 0U) { return 32U; - else{ + } else { return (31U - fls32(value)); } } @@ -160,9 +163,9 @@ static inline uint16_t clz(uint32_t value) */ static inline uint16_t clz64(uint64_t value) { - if (value == 0UL) + if (value == 0UL) { return 64U; - else{ + } else { return (63U - fls64(value)); } } diff --git a/hypervisor/include/lib/list.h b/hypervisor/include/lib/list.h index e8ca48590..f2f4a201e 100644 --- a/hypervisor/include/lib/list.h +++ b/hypervisor/include/lib/list.h @@ -94,8 +94,9 @@ static inline void __list_splice(struct list_head *list, static inline void list_splice(struct list_head *list, struct list_head *head) { - if (!list_empty(list)) + if (!list_empty(list)) { __list_splice(list, head); + } } static inline void list_splice_init(struct list_head *list, diff --git a/hypervisor/lib/div.c b/hypervisor/lib/div.c index 9501dfc97..1ebed962d 100644 --- a/hypervisor/lib/div.c +++ b/hypervisor/lib/div.c @@ -88,8 +88,9 @@ int udiv64(uint64_t dividend, uint64_t divisor, struct udiv_result *res) /* simplified case: only 32 bit operands Note that the preconditions * for do_udiv32() are fulfilled, since the tests were made above. */ - if (((divisor >> 32UL) == 0UL) && ((dividend >> 32UL) == 0UL)) + if (((divisor >> 32UL) == 0UL) && ((dividend >> 32UL) == 0UL)) { return do_udiv32((uint32_t) dividend, (uint32_t) divisor, res); + } /* dividend is always greater than or equal to the divisor. Neither * divisor nor dividend are 0. Thus: * clz(dividend) and clz(divisor)