From 1d628c640c0a29c9bde2be4ef27834834010e182 Mon Sep 17 00:00:00 2001 From: Mingqiang Chi Date: Thu, 12 Jul 2018 11:59:19 +0800 Subject: [PATCH] hv:fix MISRA-C return value violation 1) Change these 5 APIs to void type: vcpu_inject_pf uart16550_calc_baud_div uart16550_set_baud_rate console_init ptdev_activate_entry No need to return 'entry' for ptdev_activate_entry since the input parameter is 'entry'. 2) no need to check return value for the caller such as sbuf_put/console_putc/serial_puts/serial_get_rx_data Signed-off-by: Mingqiang Chi --- hypervisor/arch/x86/virq.c | 3 +-- hypervisor/common/ptdev.c | 3 +-- hypervisor/debug/console.c | 20 ++++++++---------- hypervisor/debug/logmsg.c | 2 +- hypervisor/debug/printf.c | 2 +- hypervisor/debug/serial.c | 2 +- hypervisor/debug/shell_internal.c | 2 +- hypervisor/debug/uart16550.c | 33 ++++++++++++------------------ hypervisor/include/arch/x86/irq.h | 2 +- hypervisor/include/common/ptdev.h | 2 +- hypervisor/include/debug/console.h | 8 ++------ hypervisor/include/debug/trace.h | 2 +- 12 files changed, 33 insertions(+), 48 deletions(-) diff --git a/hypervisor/arch/x86/virq.c b/hypervisor/arch/x86/virq.c index de7422b09..bd85b35fa 100644 --- a/hypervisor/arch/x86/virq.c +++ b/hypervisor/arch/x86/virq.c @@ -296,7 +296,7 @@ void vcpu_inject_gp(struct vcpu *vcpu, uint32_t err_code) vcpu_make_request(vcpu, ACRN_REQUEST_EXCP); } -int vcpu_inject_pf(struct vcpu *vcpu, uint64_t addr, uint32_t err_code) +void vcpu_inject_pf(struct vcpu *vcpu, uint64_t addr, uint32_t err_code) { struct run_context *cur_context = &vcpu->arch_vcpu.contexts[vcpu->arch_vcpu.cur_context]; @@ -304,7 +304,6 @@ int vcpu_inject_pf(struct vcpu *vcpu, uint64_t addr, uint32_t err_code) cur_context->cr2 = addr; vcpu_queue_exception(vcpu, IDT_PF, err_code); vcpu_make_request(vcpu, ACRN_REQUEST_EXCP); - return 0; } int interrupt_window_vmexit_handler(struct vcpu *vcpu) diff --git a/hypervisor/common/ptdev.c b/hypervisor/common/ptdev.c index 5ed2a7879..0d9988458 100644 --- a/hypervisor/common/ptdev.c +++ b/hypervisor/common/ptdev.c @@ -127,7 +127,7 @@ static int ptdev_interrupt_handler(__unused int irq, void *data) } /* active intr with irq registering */ -struct ptdev_remapping_info * +void ptdev_activate_entry(struct ptdev_remapping_info *entry, int phys_irq, bool lowpri) { @@ -141,7 +141,6 @@ ptdev_activate_entry(struct ptdev_remapping_info *entry, int phys_irq, entry->node = node; atomic_set_int(&entry->active, ACTIVE_FLAG); - return entry; } void diff --git a/hypervisor/debug/console.c b/hypervisor/debug/console.c index 1ae22a0d6..b032732f7 100644 --- a/hypervisor/debug/console.c +++ b/hypervisor/debug/console.c @@ -21,20 +21,18 @@ uint32_t get_serial_handle(void) static void print_char(char x) { - serial_puts(serial_handle, &x, 1); + (void)serial_puts(serial_handle, &x, 1); if (x == '\n') { - serial_puts(serial_handle, "\r", 1); + (void)serial_puts(serial_handle, "\r", 1); } } -int console_init(void) +void console_init(void) { spinlock_init(&lock); serial_handle = serial_open("STDIO"); - - return 0; } int console_putc(int ch) @@ -73,7 +71,7 @@ int console_puts(const char *s) } /* write all characters up to p */ - serial_puts(serial_handle, s, p - s); + (void)serial_puts(serial_handle, s, p - s); res += p - s; @@ -116,7 +114,7 @@ int console_write(const char *s, size_t len) } /* write all characters processed so far */ - serial_puts(serial_handle, s, p - s); + (void)serial_puts(serial_handle, s, p - s); res += p - s; @@ -156,14 +154,14 @@ 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)) { - console_putc('.'); + (void)console_putc('.'); } else { - console_putc(x[i]); + (void)console_putc(x[i]); } } /* continue with next row */ - console_putc('\n'); + (void)console_putc('\n'); /* set pointer one row ahead */ x += 16; } @@ -175,7 +173,7 @@ static void console_read(void) if (serial_handle != SERIAL_INVALID_HANDLE) { /* Get all the data available in the RX FIFO */ - serial_get_rx_data(serial_handle); + (void)serial_get_rx_data(serial_handle); } spinlock_release(&lock); diff --git a/hypervisor/debug/logmsg.c b/hypervisor/debug/logmsg.c index 142029015..955f09677 100644 --- a/hypervisor/debug/logmsg.c +++ b/hypervisor/debug/logmsg.c @@ -159,7 +159,7 @@ void do_logmsg(uint32_t severity, const char *fmt, ...) for (i = 0; i < (msg_len - 1) / LOG_ENTRY_SIZE + 1; i++) { - sbuf_put(sbuf, (uint8_t *)buffer + + (void)sbuf_put(sbuf, (uint8_t *)buffer + i * LOG_ENTRY_SIZE); } } diff --git a/hypervisor/debug/printf.c b/hypervisor/debug/printf.c index 3d7fd5c33..a7c85351f 100644 --- a/hypervisor/debug/printf.c +++ b/hypervisor/debug/printf.c @@ -28,7 +28,7 @@ static int charout(int cmd, const char *s, int sz, void *hnd) /* fill mode */ *nchars += sz; while (sz != 0) { - console_putc(*s); + (void)console_putc(*s); sz--; } } diff --git a/hypervisor/debug/serial.c b/hypervisor/debug/serial.c index 91d80309b..d105cf02f 100644 --- a/hypervisor/debug/serial.c +++ b/hypervisor/debug/serial.c @@ -178,7 +178,7 @@ uint32_t serial_get_rx_data(uint32_t uart_handle) spinlock_obtain(&uart->buffer_lock); /* Put the item on circular buffer */ - sbuf_put(uart->rx_sio_queue, &ch); + (void)sbuf_put(uart->rx_sio_queue, &ch); /* Exit Critical Section */ spinlock_release(&uart->buffer_lock); diff --git a/hypervisor/debug/shell_internal.c b/hypervisor/debug/shell_internal.c index 78caa58e7..97d8e6cdd 100644 --- a/hypervisor/debug/shell_internal.c +++ b/hypervisor/debug/shell_internal.c @@ -1107,7 +1107,7 @@ void shell_puts_serial(struct shell *p_shell, char *string_ptr) (uint32_t)(uint64_t)p_shell->session_io.io_session_info; /* Output the string */ - serial_puts(serial_handle, string_ptr, + (void)serial_puts(serial_handle, string_ptr, strnlen_s(string_ptr, SHELL_STRING_MAX_LEN)); } diff --git a/hypervisor/debug/uart16550.c b/hypervisor/debug/uart16550.c index 42ce4b74c..403fc08ee 100644 --- a/hypervisor/debug/uart16550.c +++ b/hypervisor/debug/uart16550.c @@ -84,7 +84,7 @@ static void uart16550_enable(__unused struct tgt_uart *tgt_uart) { } -static int uart16550_calc_baud_div(__unused struct tgt_uart *tgt_uart, +static void uart16550_calc_baud_div(__unused struct tgt_uart *tgt_uart, uint32_t ref_freq, uint32_t *baud_div_ptr, uint32_t baud_rate) { uint32_t baud_multiplier = baud_rate < BAUD_460800 ? 16 : 13; @@ -93,39 +93,32 @@ static int uart16550_calc_baud_div(__unused struct tgt_uart *tgt_uart, baud_rate = BAUD_115200; } *baud_div_ptr = ref_freq / (baud_multiplier * baud_rate); - - return 0; } -static int uart16550_set_baud_rate(struct tgt_uart *tgt_uart, +static void uart16550_set_baud_rate(struct tgt_uart *tgt_uart, uint32_t baud_rate) { - int status; uint32_t baud_div, duart_clock = CPU_OSC_CLOCK; uart_reg_t temp_reg; /* Calculate baud divisor */ - status = uart16550_calc_baud_div( + uart16550_calc_baud_div( tgt_uart, duart_clock, &baud_div, baud_rate); - if (status == 0) { - /* Enable DLL and DLM registers for setting the Divisor */ - temp_reg = uart16550_read_reg(tgt_uart->base_address, LCR_IDX); - temp_reg |= LCR_DLAB; - uart16550_write_reg(tgt_uart->base_address, temp_reg, LCR_IDX); + /* Enable DLL and DLM registers for setting the Divisor */ + temp_reg = uart16550_read_reg(tgt_uart->base_address, LCR_IDX); + temp_reg |= LCR_DLAB; + uart16550_write_reg(tgt_uart->base_address, temp_reg, LCR_IDX); - /* Write the appropriate divisor value */ - uart16550_write_reg(tgt_uart->base_address, + /* Write the appropriate divisor value */ + uart16550_write_reg(tgt_uart->base_address, ((baud_div >> 8) & 0xFFU), DLM_IDX); - uart16550_write_reg(tgt_uart->base_address, + uart16550_write_reg(tgt_uart->base_address, (baud_div & 0xFFU), DLL_IDX); - /* Disable DLL and DLM registers */ - temp_reg &= ~LCR_DLAB; - uart16550_write_reg(tgt_uart->base_address, temp_reg, LCR_IDX); - } - - return status; + /* Disable DLL and DLM registers */ + temp_reg &= ~LCR_DLAB; + uart16550_write_reg(tgt_uart->base_address, temp_reg, LCR_IDX); } static int uart16550_init(struct tgt_uart *tgt_uart) diff --git a/hypervisor/include/arch/x86/irq.h b/hypervisor/include/arch/x86/irq.h index 0b4671f39..523d8c43b 100644 --- a/hypervisor/include/arch/x86/irq.h +++ b/hypervisor/include/arch/x86/irq.h @@ -97,7 +97,7 @@ extern spurious_handler_t spurious_handler; void vcpu_inject_extint(struct vcpu *vcpu); void vcpu_inject_nmi(struct vcpu *vcpu); void vcpu_inject_gp(struct vcpu *vcpu, uint32_t err_code); -int vcpu_inject_pf(struct vcpu *vcpu, uint64_t addr, uint32_t err_code); +void vcpu_inject_pf(struct vcpu *vcpu, uint64_t addr, uint32_t err_code); void vcpu_make_request(struct vcpu *vcpu, int eventid); int vcpu_queue_exception(struct vcpu *vcpu, uint32_t vector, uint32_t err_code); diff --git a/hypervisor/include/common/ptdev.h b/hypervisor/include/common/ptdev.h index 3e528e499..392de7c80 100644 --- a/hypervisor/include/common/ptdev.h +++ b/hypervisor/include/common/ptdev.h @@ -75,7 +75,7 @@ struct ptdev_remapping_info *ptdev_dequeue_softirq(void); struct ptdev_remapping_info *alloc_entry(struct vm *vm, enum ptdev_intr_type type); void release_entry(struct ptdev_remapping_info *entry); -struct ptdev_remapping_info *ptdev_activate_entry( +void ptdev_activate_entry( struct ptdev_remapping_info *entry, int phys_irq, bool lowpri); void ptdev_deactivate_entry(struct ptdev_remapping_info *entry); diff --git a/hypervisor/include/debug/console.h b/hypervisor/include/debug/console.h index 99efc84ef..ca07f3e94 100644 --- a/hypervisor/include/debug/console.h +++ b/hypervisor/include/debug/console.h @@ -12,12 +12,9 @@ extern struct timer console_timer; /** Initializes the console module. * - * @param cdev A pointer to the character device to use for the console. - * - * @return '0' on success. Any other value indicates an error. */ -int console_init(void); +void console_init(void); /** Writes a NUL terminated string to the console. * @@ -76,9 +73,8 @@ static inline void resume_console(void) } #else -static inline int console_init(void) +static inline void console_init(void) { - return 0; } static inline int console_puts(__unused const char *str) { diff --git a/hypervisor/include/debug/trace.h b/hypervisor/include/debug/trace.h index a24e28ba0..b2602769d 100644 --- a/hypervisor/include/debug/trace.h +++ b/hypervisor/include/debug/trace.h @@ -100,7 +100,7 @@ _trace_put(uint16_t cpu_id, uint32_t evid, entry->id = evid; entry->n_data = (uint8_t)n_data; entry->cpu = (uint8_t)cpu_id; - sbuf_put(sbuf, (uint8_t *)entry); + (void)sbuf_put(sbuf, (uint8_t *)entry); } static inline void