HV:debug:fix "expression is not Boolean"

MISRA C explicit required expression should be boolean when
in branch statements (if,while...).

Signed-off-by: Huihuang Shi <huihuang.shi@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Huihuang Shi 2018-06-19 14:45:30 +08:00 committed by lijinxia
parent fe0314e8c3
commit 23921384d0
8 changed files with 50 additions and 49 deletions

View File

@ -61,13 +61,13 @@ int console_puts(const char *s)
if (serial_handle != SERIAL_INVALID_HANDLE) {
res = 0;
while (*s) {
while ((*s) != 0) {
/* start output at the beginning of the string search
* for end of string or '\n'
*/
p = s;
while (*p && *p != '\n')
while ((*p != 0) && *p != '\n')
++p;
/* write all characters up to p */

View File

@ -27,13 +27,13 @@ static inline void alloc_earlylog_sbuf(uint32_t cpu_id)
- SBUF_HEAD_SIZE) / ele_size;
per_cpu(earlylog_sbuf, cpu_id) = sbuf_allocate(ele_num, ele_size);
if (!per_cpu(earlylog_sbuf,cpu_id))
if (per_cpu(earlylog_sbuf, cpu_id) == NULL)
printf("failed to allcate sbuf for hvlog - %d\n", cpu_id);
}
static inline void free_earlylog_sbuf(uint32_t cpu_id)
{
if (!per_cpu(earlylog_sbuf, cpu_id))
if (per_cpu(earlylog_sbuf, cpu_id) == NULL)
return;
free(per_cpu(earlylog_sbuf, cpu_id));
@ -47,8 +47,8 @@ static int do_copy_earlylog(struct shared_buf *dst_sbuf,
uint32_t cur_tail;
spinlock_rflags;
if (src_sbuf->ele_size != dst_sbuf->ele_size
&& src_sbuf->ele_num != dst_sbuf->ele_num) {
if ((src_sbuf->ele_size != dst_sbuf->ele_size)
&& (src_sbuf->ele_num != dst_sbuf->ele_num)) {
spinlock_irqsave_obtain(&(logmsg.lock));
printf("Error to copy early hvlog: size mismatch\n");
spinlock_irqrestore_release(&(logmsg.lock));
@ -89,9 +89,9 @@ void do_logmsg(uint32_t severity, const char *fmt, ...)
char *buffer;
spinlock_rflags;
do_console_log = ((logmsg.flags & LOG_FLAG_STDOUT) &&
do_console_log = ((logmsg.flags & LOG_FLAG_STDOUT) != 0U &&
(severity <= console_loglevel));
do_mem_log = ((logmsg.flags & LOG_FLAG_MEMORY) &&
do_mem_log = ((logmsg.flags & LOG_FLAG_MEMORY) != 0U &&
(severity <= mem_loglevel));
if (!do_console_log && !do_mem_log)
@ -138,8 +138,8 @@ void do_logmsg(uint32_t severity, const char *fmt, ...)
per_cpu(sbuf, cpu_id)[ACRN_HVLOG];
struct shared_buf *early_sbuf = per_cpu(earlylog_sbuf, cpu_id);
if (early_sbuf) {
if (sbuf) {
if (early_sbuf != NULL) {
if (sbuf != NULL) {
/* switch to sbuf from sos */
do_copy_earlylog(sbuf, early_sbuf);
free_earlylog_sbuf(cpu_id);
@ -171,7 +171,7 @@ void print_logmsg_buffer(uint32_t cpu_id)
if (cpu_id >= (uint32_t)phy_cpu_num)
return;
if (per_cpu(earlylog_sbuf, cpu_id)) {
if (per_cpu(earlylog_sbuf, cpu_id) != NULL) {
sbuf = &per_cpu(earlylog_sbuf, cpu_id);
is_earlylog = 1;
} else
@ -179,10 +179,10 @@ void print_logmsg_buffer(uint32_t cpu_id)
&per_cpu(sbuf, cpu_id)[ACRN_HVLOG];
spinlock_irqsave_obtain(&(logmsg.lock));
if (*sbuf)
if ((*sbuf) != NULL)
printf("CPU%d: head: 0x%x, tail: 0x%x %s\n\r",
cpu_id, (*sbuf)->head, (*sbuf)->tail,
is_earlylog ? "[earlylog]" : "");
(is_earlylog != 0) ? "[earlylog]" : "");
spinlock_irqrestore_release(&(logmsg.lock));
do {

View File

@ -28,7 +28,7 @@ static int charout(int cmd, const char *s, int sz, void *hnd)
/* fill mode */
else {
*nchars += sz;
while (sz--)
while ((sz--) != 0)
console_putc(*s);
}

View File

@ -45,13 +45,13 @@ struct shared_buf *sbuf_allocate(uint32_t ele_num, uint32_t ele_size)
struct shared_buf *sbuf;
uint32_t sbuf_allocate_size;
if (!ele_num || !ele_size) {
if (ele_num == 0U || ele_size == 0U) {
pr_err("%s invalid parameter!", __func__);
return NULL;
}
sbuf_allocate_size = sbuf_calculate_allocate_size(ele_num, ele_size);
if (!sbuf_allocate_size)
if (sbuf_allocate_size == 0U)
return NULL;
sbuf = calloc(1, sbuf_allocate_size);
@ -133,7 +133,7 @@ int sbuf_put(struct shared_buf *sbuf, uint8_t *data)
if (next_tail == sbuf->head) {
/* accumulate overrun count if necessary */
sbuf->overrun_cnt += sbuf->flags & OVERRUN_CNT_EN;
if (!(sbuf->flags & OVERWRITE_EN)) {
if ((sbuf->flags & OVERWRITE_EN) == 0U) {
/* if not enable over write, return here. */
return 0;
}

View File

@ -38,7 +38,7 @@ int serial_init(void)
/* Allocate memory for generic control block of enabled UART */
sio_ports[index] = calloc(1, sizeof(struct uart));
if (!sio_ports[index]) {
if (sio_ports[index] == NULL) {
status = -ENOMEM;
break;
}
@ -88,7 +88,7 @@ uint32_t serial_open(char *uart_id)
uart = get_uart_by_id(uart_id, &index);
if (uart != NULL && index < SERIAL_MAX_DEVS &&
sio_initialized[index] &&
sio_initialized[index] != 0U &&
(uart->open_flag == false)) {
/* Reset the buffer lock */
spinlock_init(&uart->buffer_lock);
@ -142,7 +142,7 @@ int serial_get_rx_data(uint32_t uart_handle)
/* Place all the data available in RX FIFO, in circular buffer */
while ((data_avail = uart->tgt_uart->rx_data_is_avail(
uart->tgt_uart, &lsr_reg))) {
uart->tgt_uart, &lsr_reg)) != 0) {
/* Read the byte */
uart->tgt_uart->read(uart->tgt_uart, (void *)&ch, &bytes_read);
@ -284,7 +284,7 @@ static int serial_putc(uint32_t uart_handle, int c)
/* Wait for TX hardware to be ready */
do {
busy = uart->tgt_uart->tx_is_busy(uart->tgt_uart);
} while (busy);
} while (busy != 0);
/* Transmit character */
uart->tgt_uart->write(uart->tgt_uart, &(c), &bytes_written);

View File

@ -171,7 +171,7 @@ static uint8_t shell_input_line(struct shell *p_shell)
} else {
/* prINTable character */
/* See if a "special" character handler is installed */
if (p_shell->session_io.io_special) {
if (p_shell->session_io.io_special != NULL) {
/* Call special character handler */
p_shell->session_io.io_special(p_shell, ch);
}
@ -255,7 +255,7 @@ struct shell_cmd *shell_find_cmd(struct shell *p_shell, const char *cmd_str)
void kick_shell(struct shell *p_shell)
{
int status = p_shell ? 0 : EINVAL;
int status = (p_shell != NULL) ? 0 : EINVAL;
static uint8_t is_cmd_cmplt = 1;
if (status == 0) {
@ -267,9 +267,10 @@ void kick_shell(struct shell *p_shell)
* Show HV shell prompt ONLY when HV owns the
* serial port.
*/
if (!vuart_console_active()) {
if (vuart_console_active() == NULL) {
/* Prompt the user for a selection. */
if (is_cmd_cmplt && p_shell->session_io.io_puts)
if ((is_cmd_cmplt != 0U) &&
(p_shell->session_io.io_puts != NULL))
p_shell->session_io.io_puts(p_shell,
SHELL_PROMPT_STR);
@ -279,7 +280,7 @@ void kick_shell(struct shell *p_shell)
/* If user has pressed the ENTER then process
* the command
*/
if (is_cmd_cmplt)
if (is_cmd_cmplt != 0U)
/* Process current input line. */
status = shell_process(p_shell);
}
@ -425,12 +426,12 @@ int shell_cmd_help(struct shell *p_shell,
space_buf[spaces] = ' ';
/* Display parameter info if applicable. */
if (p_cmd->cmd_param) {
if (p_cmd->cmd_param != NULL) {
shell_puts(p_shell, p_cmd->cmd_param);
}
/* Display help text if available. */
if (p_cmd->help_str) {
if (p_cmd->help_str != NULL) {
shell_puts(p_shell, " - ");
shell_puts(p_shell, p_cmd->help_str);
}
@ -554,9 +555,9 @@ int shell_pause_vcpu(struct shell *p_shell,
vcpu_id = atoi(argv[2]);
vm = get_vm_from_vmid(vm_id);
if (vm) {
if (vm != NULL) {
vcpu = vcpu_from_vid(vm, vcpu_id);
if (vcpu) {
if (vcpu != NULL) {
if (vcpu->dbg_req_state != VCPU_PAUSED) {
vcpu->dbg_req_state = VCPU_PAUSED;
/* TODO: do we need file a IPI to kick
@ -602,9 +603,9 @@ int shell_resume_vcpu(struct shell *p_shell,
vm_id = atoi(argv[1]);
vcpu_id = atoi(argv[2]);
vm = get_vm_from_vmid(vm_id);
if (vm) {
if (vm != NULL) {
vcpu = vcpu_from_vid(vm, vcpu_id);
if (vcpu) {
if (vcpu != NULL) {
if (vcpu->dbg_req_state == VCPU_PAUSED) {
vcpu->dbg_req_state = 0;
shell_puts(p_shell,
@ -656,14 +657,14 @@ int shell_vcpu_dumpreg(struct shell *p_shell,
vcpu_id = atoi(argv[2]);
vm = get_vm_from_vmid(vm_id);
if (!vm) {
if (vm == NULL) {
shell_puts(p_shell, "No vm found in the input "
"<vm_id, vcpu_id>\r\n");
return -EINVAL;
}
vcpu = vcpu_from_vid(vm, vcpu_id);
if (!vcpu) {
if (vcpu == NULL) {
shell_puts(p_shell, "No vcpu found in the input "
"<vm_id, vcpu_id>\r\n");
return -EINVAL;
@ -790,7 +791,7 @@ int shell_vcpu_dumpmem(struct shell *p_shell,
}
vcpu = vcpu_from_vid(vm, (long)vcpu_id);
if (vcpu) {
if (vcpu != NULL) {
status = copy_from_gva(vcpu, tmp, gva, length, &err_code);
if (status < 0) {
shell_puts(p_shell,
@ -1106,7 +1107,7 @@ int shell_construct(struct shell **p_shell)
/* Allocate memory for shell session */
*p_shell = (struct shell *) calloc(1, sizeof(**p_shell));
if (!(*p_shell)) {
if ((*p_shell) == NULL) {
pr_err("Error: out of memory");
status = -ENOMEM;
}

View File

@ -63,7 +63,7 @@ enum UART_REG_IDX{
static inline uint32_t uart16550_read_reg(uint64_t base, uint32_t reg_idx)
{
if (serial_port_mapped) {
if (serial_port_mapped != 0) {
return io_read_byte((uint16_t)base + reg_idx);
} else {
return mmio_read_long((void*)((uint32_t*)HPA2HVA(base) + reg_idx));
@ -73,7 +73,7 @@ static inline uint32_t uart16550_read_reg(uint64_t base, uint32_t reg_idx)
static inline void uart16550_write_reg(uint64_t base,
uint32_t val, uint32_t reg_idx)
{
if (serial_port_mapped) {
if (serial_port_mapped != 0) {
io_write_byte(val, (uint16_t)base + reg_idx);
} else {
mmio_write_long(val, (void*)((uint32_t*)HPA2HVA(base) + reg_idx));
@ -129,7 +129,7 @@ static int uart16550_init(struct tgt_uart *tgt_uart)
{
int status = 0;
if (!uart_enabled) {
if (uart_enabled == 0) {
/*uart will not be used */
status = -ENODEV;
} else {
@ -219,15 +219,15 @@ static int uart16550_get_rx_err(uint32_t rx_data)
int rx_status = SD_RX_NO_ERROR;
/* Check for RX overrun error */
if ((rx_data & LSR_OE))
if ((rx_data & LSR_OE) != 0U)
rx_status |= SD_RX_OVERRUN_ERROR;
/* Check for RX parity error */
if ((rx_data & LSR_PE))
if ((rx_data & LSR_PE) != 0U)
rx_status |= SD_RX_PARITY_ERROR;
/* Check for RX frame error */
if ((rx_data & LSR_FE))
if ((rx_data & LSR_FE) != 0U)
rx_status |= SD_RX_FRAME_ERROR;
/* Return the rx status */
@ -265,8 +265,8 @@ static void uart16550_write(struct tgt_uart *tgt_uart,
{
/* Ensure there are no further Transmit buffer write requests */
do {
} while (!(uart16550_read_reg(tgt_uart->base_address,
ISR_IDX) & LSR_THRE));
} while ((uart16550_read_reg(tgt_uart->base_address,
ISR_IDX) & LSR_THRE) == 0U);
/* Transmit the character. */
uart16550_write_reg(tgt_uart->base_address,

View File

@ -136,11 +136,11 @@ static void uart_toggle_intr(struct vuart *vu)
intr_reason = uart_intr_reason(vu);
if (intr_reason != IIR_NOPEND) {
if (vu->vm->vpic)
if (vu->vm->vpic != NULL)
vpic_assert_irq(vu->vm, COM1_IRQ);
vioapic_assert_irq(vu->vm, COM1_IRQ);
if (vu->vm->vpic)
if (vu->vm->vpic != NULL)
vpic_deassert_irq(vu->vm, COM1_IRQ);
vioapic_deassert_irq(vu->vm, COM1_IRQ);
@ -256,7 +256,7 @@ static uint32_t uart_read(__unused struct vm_io_handler *hdlr,
reg = vu->ier;
break;
case UART16550_IIR:
iir = (vu->fcr & FCR_FIFOE) ? IIR_FIFO_MASK : 0;
iir = ((vu->fcr & FCR_FIFOE) != 0) ? IIR_FIFO_MASK : 0;
intr_reason = uart_intr_reason(vu);
/*
* Deal with side effects of reading the IIR register
@ -346,7 +346,7 @@ void vuart_console_rx_chars(uint32_t serial_handle)
vuart_lock(vu);
/* Get data from serial */
vbuf_len = serial_gets(serial_handle, buffer, 100);
if (vbuf_len) {
if (vbuf_len != 0U) {
while (buf_idx < vbuf_len) {
if (buffer[buf_idx] == GUEST_CONSOLE_TO_HV_SWITCH_KEY) {
/* Switch the console */
@ -370,7 +370,7 @@ struct vuart *vuart_console_active(void)
{
struct vm *vm = get_vm_from_vmid(0);
if (vm && vm->vuart) {
if ((vm != NULL) && (vm->vuart != NULL)) {
struct vuart *vu = vm->vuart;
if (vu->active)