HV:debug:fix "signed/unsigned conversion without cast"

Misra C required signed/unsigned conversion with cast.

V1->V2:
  a.split patch to patch series

V2->V3:
  a.Change the API tgt_uart/ static int uart16550_get_rx_err(uint32_t rx_data) to return uint32_t
  b.modified the format of if from "if (length > 32*(length/32))" to
"if (length % 32U > 0)"

V3->V4:
  a.change the uint64_t type numeric constant's suffix from U to UL

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-07-03 11:51:27 +08:00 committed by lijinxia
parent 8b94957774
commit 91fdffb19a
9 changed files with 60 additions and 57 deletions

View File

@ -114,7 +114,7 @@ static void dump_guest_stack(struct vcpu *vcpu)
printf("\r\nGuest Stack:\r\n");
printf("Dump stack for vcpu %d, from gva 0x%016llx\r\n",
vcpu->vcpu_id, cur_context->rsp);
for (i = 0; i < DUMP_STACK_SIZE/32; i++) {
for (i = 0U; i < DUMP_STACK_SIZE/32U; i++) {
printf("guest_rsp(0x%llx): 0x%016llx 0x%016llx "
"0x%016llx 0x%016llx\r\n",
(cur_context->rsp+i*32),
@ -127,7 +127,7 @@ static void dump_guest_stack(struct vcpu *vcpu)
static void show_guest_call_trace(struct vcpu *vcpu)
{
uint64_t bp;
uint64_t count = 0;
uint64_t count = 0UL;
struct run_context *cur_context =
&vcpu->arch_vcpu.contexts[vcpu->arch_vcpu.cur_context];
int err;
@ -150,9 +150,9 @@ static void show_guest_call_trace(struct vcpu *vcpu)
* if the address is invalid, it will cause hv page fault
* then halt system */
while ((count++ < CALL_TRACE_HIERARCHY_MAX) && (bp != 0)) {
uint64_t parent_bp = 0;
uint64_t parent_bp = 0UL;
err_code = 0;
err_code = 0U;
err = copy_from_gva(vcpu, &parent_bp, bp, sizeof(parent_bp),
&err_code);
if (err < 0) {
@ -181,15 +181,15 @@ static void dump_guest_context(uint32_t cpu_id)
static void show_host_call_trace(uint64_t rsp, uint64_t rbp, uint32_t cpu_id)
{
int i = 0;
int cb_hierarchy = 0;
uint32_t i = 0U;
uint32_t cb_hierarchy = 0U;
uint64_t *sp = (uint64_t *)rsp;
printf("\r\nHost Stack: CPU_ID = %d\r\n", cpu_id);
for (i = 0; i < DUMP_STACK_SIZE/32; i++) {
for (i = 0U; i < DUMP_STACK_SIZE/32U; i++) {
printf("addr(0x%llx) 0x%016llx 0x%016llx 0x%016llx "
"0x%016llx\r\n", (rsp+i*32), sp[i*4], sp[i*4+1],
sp[i*4+2], sp[i*4+3]);
"0x%016llx\r\n", (rsp+i*32U), sp[i*4U], sp[i*4U+1U],
sp[i*4U+2U], sp[i*4U+3U]);
}
printf("\r\n");
@ -249,7 +249,7 @@ void dump_intr_excp_frame(struct intr_excp_ctx *ctx)
printf("\n\n================================================");
printf("================================\n=\n");
if (ctx->vector < 0x20) {
if (ctx->vector < 0x20UL) {
name = excp_names[ctx->vector];
printf("= Unhandled exception: %d (%s)\n", ctx->vector, name);
}

View File

@ -76,7 +76,7 @@ void sbuf_free(struct shared_buf *sbuf)
return;
}
sbuf->magic = 0;
sbuf->magic = 0UL;
free(sbuf);
}

View File

@ -13,7 +13,7 @@ static uint8_t sio_initialized[SERIAL_MAX_DEVS];
static struct uart *get_uart_by_id(char *uart_id, uint32_t *index)
{
/* Initialize the index to the start of array. */
*index = 0;
*index = 0U;
while (sio_ports[*index] != NULL) {
if (strncmp(sio_ports[*index]->tgt_uart->uart_id, uart_id,
@ -120,25 +120,26 @@ uint32_t serial_open(char *uart_id)
SERIAL_INVALID_HANDLE;
}
int serial_get_rx_data(uint32_t uart_handle)
uint32_t serial_get_rx_data(uint32_t uart_handle)
{
uint32_t index;
struct uart *uart;
int data_avail, rx_byte_status;
int data_avail;
uint32_t rx_byte_status;
uint32_t lsr_reg, bytes_read;
uint8_t ch;
int total_bytes_read = 0;
uint32_t total_bytes_read = 0U;
if (!SERIAL_VALIDATE_HANDLE(uart_handle))
return 0;
return 0U;
index = SERIAL_DECODE_INDEX(uart_handle);
if (index >= SERIAL_MAX_DEVS)
return 0;
return 0U;
uart = sio_ports[index];
if (uart == NULL)
return 0;
return 0U;
/* Place all the data available in RX FIFO, in circular buffer */
while ((data_avail = uart->tgt_uart->rx_data_is_avail(
@ -230,7 +231,7 @@ int serial_gets(uint32_t uart_handle, char *buffer, uint32_t length)
uint32_t index;
int status = 0;
if ((buffer == NULL) || (length == 0))
if ((buffer == NULL) || (length == 0U))
return 0;
if (!SERIAL_VALIDATE_HANDLE(uart_handle))
@ -242,7 +243,7 @@ int serial_gets(uint32_t uart_handle, char *buffer, uint32_t length)
port = sio_ports[index];
if ((port != NULL) && (port->open_flag == true)) {
for (; length > 0; data_read++, length--) {
for (; length > 0U; length--) {
/* Disable interrupts for critical section */
spinlock_obtain(&port->buffer_lock);
@ -256,6 +257,7 @@ int serial_gets(uint32_t uart_handle, char *buffer, uint32_t length)
/* Save character in buffer */
*data_read = (char) c;
data_read++;
}
}
/* Return actual number of bytes read */
@ -264,7 +266,7 @@ int serial_gets(uint32_t uart_handle, char *buffer, uint32_t length)
static int serial_putc(uint32_t uart_handle, int c)
{
uint32_t index, bytes_written = 0;
uint32_t index, bytes_written = 0U;
struct uart *uart;
int busy;
@ -290,7 +292,7 @@ static int serial_putc(uint32_t uart_handle, int c)
uart->tgt_uart->write(uart->tgt_uart, &(c), &bytes_written);
/* Return character written or EOF for error */
return ((bytes_written > 0) ? c : (SERIAL_EOF));
return ((bytes_written > 0U) ? c : (SERIAL_EOF));
}
int serial_puts(uint32_t uart_handle, const char *s, uint32_t length)
@ -300,7 +302,7 @@ int serial_puts(uint32_t uart_handle, const char *s, uint32_t length)
struct uart *port;
int retval = 0;
if ((s == NULL) || (length == 0))
if ((s == NULL) || (length == 0U))
return 0;
if (!SERIAL_VALIDATE_HANDLE(uart_handle))
@ -326,7 +328,7 @@ int serial_puts(uint32_t uart_handle, const char *s, uint32_t length)
* Loop through the string until desired length of bytes have
* been written or SERIAL_EOF is returned.
*/
for (; length > 0 && retval != SERIAL_EOF; s++, length--)
for (; length > 0U && retval != SERIAL_EOF; s++, length--)
retval = serial_putc(uart_handle, (int) *s);
/* Allow other threads to use this service. */

View File

@ -10,7 +10,7 @@
struct shared_buf;
/* Maximum serial devices supported by the platform. */
#define SERIAL_MAX_DEVS 1
#define SERIAL_MAX_DEVS 1U
/* Maximum length of unique id of each UART port enabled in platform. */
#define SERIAL_ID_MAX_LENGTH 8
@ -144,7 +144,7 @@ struct tgt_uart {
const void *buffer, uint32_t *bytes_written);
bool (*tx_is_busy)(struct tgt_uart *tgt_uart);
bool (*rx_data_is_avail)(struct tgt_uart *tgt_uart, uint32_t *lsr_reg);
int (*get_rx_err)(uint32_t rx_data);
uint32_t (*get_rx_err)(uint32_t rx_data);
};
/* Control Block definition of light-weight serial driver */
@ -179,6 +179,6 @@ uint32_t serial_open(char *uart_id);
int serial_getc(uint32_t uart_handle);
int serial_gets(uint32_t uart_handle, char *buffer, uint32_t length);
int serial_puts(uint32_t uart_handle, const char *s, uint32_t length);
int serial_get_rx_data(uint32_t uart_handle);
uint32_t serial_get_rx_data(uint32_t uart_handle);
#endif /* !SERIAL_INTER_H */

View File

@ -32,14 +32,15 @@ uint32_t console_loglevel = CONFIG_CONSOLE_LOGLEVEL_DEFAULT;
uint32_t mem_loglevel = CONFIG_MEM_LOGLEVEL_DEFAULT;
static int string_to_argv(char *argv_str, void *p_argv_mem,
__unused uint32_t argv_mem_size, int *p_argc, char ***p_argv)
__unused uint32_t argv_mem_size,
uint32_t *p_argc, char ***p_argv)
{
uint32_t argc;
char **argv;
char *p_ch;
/* Setup initial argument values. */
argc = 0;
argc = 0U;
argv = NULL;
/* Ensure there are arguments to be processed. */
@ -103,7 +104,7 @@ static uint8_t shell_input_line(struct shell *p_shell)
/* Backspace */
case '\b':
/* Ensure length is not 0 */
if (p_shell->input_line_len > 0) {
if (p_shell->input_line_len > 0U) {
/* Reduce the length of the string by one */
p_shell->input_line_len--;
@ -140,7 +141,7 @@ static uint8_t shell_input_line(struct shell *p_shell)
done = true;
/* Reset command length for next command processing */
p_shell->input_line_len = 0;
p_shell->input_line_len = 0U;
break;
/* Line feed */
@ -153,7 +154,7 @@ static uint8_t shell_input_line(struct shell *p_shell)
/* Ensure data doesn't exceed full terminal width */
if (p_shell->input_line_len < SHELL_CMD_MAX_LEN) {
/* See if a "standard" prINTable ASCII character received */
if ((ch >= 32) && (ch <= 126)) {
if ((ch >= 32U) && (ch <= 126U)) {
/* Add character to string */
p_shell->input_line[p_shell->input_line_active]
[p_shell->input_line_len] = ch;
@ -187,7 +188,7 @@ static uint8_t shell_input_line(struct shell *p_shell)
done = true;
/* Reset command length for next command processing */
p_shell->input_line_len = 0;
p_shell->input_line_len = 0U;
}
break;
@ -225,7 +226,7 @@ static int shell_process(struct shell *p_shell)
/* Now that the command is processed, zero fill the input buffer */
memset((void *) p_shell->input_line[p_shell->input_line_active], 0,
SHELL_CMD_MAX_LEN + 1);
SHELL_CMD_MAX_LEN + 1U);
/* Process command and return result to caller */
return status;
@ -236,10 +237,10 @@ 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 <= 0)
if (p_shell->cmd_count <= 0U)
return NULL;
for (i = 0; i < p_shell->cmd_count; i++) {
for (i = 0U; i < p_shell->cmd_count; i++) {
p_cmd = &p_shell->shell_cmd[i];
if (strcmp(p_cmd->str, cmd_str) == 0)
break;
@ -297,8 +298,8 @@ int shell_process_cmd(struct shell *p_shell, char *p_input_line)
int status = 0;
struct shell_cmd *p_cmd;
shell_cmd_fn_t cmd_fcn;
char cmd_argv_str[SHELL_CMD_MAX_LEN + 1];
int cmd_argv_mem[sizeof(char *) * ((SHELL_CMD_MAX_LEN + 1) / 2)];
char cmd_argv_str[SHELL_CMD_MAX_LEN + 1U];
int cmd_argv_mem[sizeof(char *) * ((SHELL_CMD_MAX_LEN + 1U) / 2U)];
int cmd_argc;
char **cmd_argv;
@ -360,7 +361,7 @@ int shell_init_serial(struct shell *p_shell)
/* Zero fill the input buffer */
memset((void *)p_shell->input_line[p_shell->input_line_active], 0,
SHELL_CMD_MAX_LEN + 1);
SHELL_CMD_MAX_LEN + 1U);
return status;
}
@ -383,14 +384,14 @@ int shell_cmd_help(struct shell *p_shell,
memset(space_buf, ' ', sizeof(space_buf));
/* Proceed based on the number of registered commands. */
if (p_shell->cmd_count == 0) {
if (p_shell->cmd_count == 0U) {
/* No registered commands */
shell_puts(p_shell, "NONE\r\n");
} else {
int i = 0;
int32_t i = 0;
uint32_t j;
for (j = 0; j < p_shell->cmd_count; j++) {
for (j = 0U; j < p_shell->cmd_count; j++) {
p_cmd = &p_shell->shell_cmd[j];
/* Check if we've filled the screen with info */
@ -733,12 +734,12 @@ int shell_vcpu_dumpreg(struct shell *p_shell,
vm_id, cur_context->rsp);
shell_puts(p_shell, temp_str);
for (i = 0; i < 8; i++) {
for (i = 0UL; i < 8UL; i++) {
snprintf(temp_str, MAX_STR_SIZE,
"= 0x%016llx 0x%016llx "
"0x%016llx 0x%016llx\r\n",
tmp[i*4], tmp[i*4+1],
tmp[i*4+2], tmp[i*4+3]);
tmp[i*4UL], tmp[i*4UL+1UL],
tmp[i*4UL+2UL], tmp[i*4UL+3UL]);
shell_puts(p_shell, temp_str);
}
}
@ -746,7 +747,7 @@ int shell_vcpu_dumpreg(struct shell *p_shell,
return status;
}
#define MAX_MEMDUMP_LEN (32*8)
#define MAX_MEMDUMP_LEN (32U*8U)
int shell_vcpu_dumpmem(struct shell *p_shell,
int argc, char **argv)
{
@ -754,7 +755,7 @@ int shell_vcpu_dumpmem(struct shell *p_shell,
uint32_t vm_id, vcpu_id;
uint64_t gva;
uint64_t tmp[MAX_MEMDUMP_LEN/8];
uint32_t i, length = 32;
uint32_t i, length = 32U;
char temp_str[MAX_STR_SIZE];
struct vm *vm;
struct vcpu *vcpu;
@ -802,14 +803,14 @@ int shell_vcpu_dumpmem(struct shell *p_shell,
"length %d:\r\n", vcpu_id, gva, length);
shell_puts(p_shell, temp_str);
for (i = 0; i < length/32; i++) {
for (i = 0U; i < length/32U; i++) {
snprintf(temp_str, MAX_STR_SIZE,
"= 0x%016llx 0x%016llx 0x%016llx "
"0x%016llx\r\n", tmp[i*4], tmp[i*4+1],
tmp[i*4+2], tmp[i*4+3]);
shell_puts(p_shell, temp_str);
}
if (length > 32*(length/32)) {
if ((length % 32U) != 0) {
snprintf(temp_str, MAX_STR_SIZE,
"= 0x%016llx 0x%016llx 0x%016llx "
"0x%016llx\r\n", tmp[i*4], tmp[i*4+1],
@ -1095,7 +1096,7 @@ void shell_special_serial(struct shell *p_shell, uint8_t ch)
{
switch (ch) {
/* Escape character */
case 0x1b:
case 0x1bU:
/* Consume the next 2 characters */
(void) p_shell->session_io.io_getc(p_shell);
(void) p_shell->session_io.io_getc(p_shell);

View File

@ -22,7 +22,7 @@ struct shell_io {
bool io_echo_on;
};
#define SHELL_CMD_MAX_LEN 100
#define SHELL_CMD_MAX_LEN 100U
#define SHELL_NAME_MAX_LEN 50
#define SHELL_PARA_MAX_LEN 64
#define SHELL_HELP_MAX_LEN 256
@ -32,7 +32,7 @@ struct shell_io {
struct shell_cmd;
struct shell {
struct shell_io session_io; /* Session I/O information */
char input_line[2][SHELL_CMD_MAX_LEN + 1]; /* current & last */
char input_line[2][SHELL_CMD_MAX_LEN + 1U]; /* current & last */
char name[SHELL_NAME_MAX_LEN]; /* Session name */
uint32_t input_line_len; /* Length of current input line */
uint32_t input_line_active; /* Active input line index */

View File

@ -214,9 +214,9 @@ static int uart16550_open(struct tgt_uart *tgt_uart,
return status;
}
static int uart16550_get_rx_err(uint32_t rx_data)
static uint32_t uart16550_get_rx_err(uint32_t rx_data)
{
int rx_status = SD_RX_NO_ERROR;
uint32_t rx_status = SD_RX_NO_ERROR;
/* Check for RX overrun error */
if ((rx_data & LSR_OE) != 0U)

View File

@ -10,8 +10,8 @@
struct intr_excp_ctx;
#ifdef HV_DEBUG
#define CALL_TRACE_HIERARCHY_MAX 20
#define DUMP_STACK_SIZE 0x200
#define CALL_TRACE_HIERARCHY_MAX 20U
#define DUMP_STACK_SIZE 0x200U
void dump_intr_excp_frame(struct intr_excp_ctx *ctx);
void dump_exception(struct intr_excp_ctx *ctx, uint32_t cpu_id);

View File

@ -12,7 +12,7 @@
#ifndef SHARED_BUFFER_H
#define SHARED_BUFFER_H
#define SBUF_MAGIC 0x5aa57aa71aa13aa3
#define SBUF_MAGIC 0x5aa57aa71aa13aa3UL
#define SBUF_MAX_SIZE (1 << 22)
#define SBUF_HEAD_SIZE 64