Skip to content

Commit 91fdffb

Browse files
Shawnshhlijinxia
authored andcommitted
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>
1 parent 8b94957 commit 91fdffb

File tree

9 files changed

+60
-57
lines changed

9 files changed

+60
-57
lines changed

hypervisor/debug/dump.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static void dump_guest_stack(struct vcpu *vcpu)
114114
printf("\r\nGuest Stack:\r\n");
115115
printf("Dump stack for vcpu %d, from gva 0x%016llx\r\n",
116116
vcpu->vcpu_id, cur_context->rsp);
117-
for (i = 0; i < DUMP_STACK_SIZE/32; i++) {
117+
for (i = 0U; i < DUMP_STACK_SIZE/32U; i++) {
118118
printf("guest_rsp(0x%llx): 0x%016llx 0x%016llx "
119119
"0x%016llx 0x%016llx\r\n",
120120
(cur_context->rsp+i*32),
@@ -127,7 +127,7 @@ static void dump_guest_stack(struct vcpu *vcpu)
127127
static void show_guest_call_trace(struct vcpu *vcpu)
128128
{
129129
uint64_t bp;
130-
uint64_t count = 0;
130+
uint64_t count = 0UL;
131131
struct run_context *cur_context =
132132
&vcpu->arch_vcpu.contexts[vcpu->arch_vcpu.cur_context];
133133
int err;
@@ -150,9 +150,9 @@ static void show_guest_call_trace(struct vcpu *vcpu)
150150
* if the address is invalid, it will cause hv page fault
151151
* then halt system */
152152
while ((count++ < CALL_TRACE_HIERARCHY_MAX) && (bp != 0)) {
153-
uint64_t parent_bp = 0;
153+
uint64_t parent_bp = 0UL;
154154

155-
err_code = 0;
155+
err_code = 0U;
156156
err = copy_from_gva(vcpu, &parent_bp, bp, sizeof(parent_bp),
157157
&err_code);
158158
if (err < 0) {
@@ -181,15 +181,15 @@ static void dump_guest_context(uint32_t cpu_id)
181181

182182
static void show_host_call_trace(uint64_t rsp, uint64_t rbp, uint32_t cpu_id)
183183
{
184-
int i = 0;
185-
int cb_hierarchy = 0;
184+
uint32_t i = 0U;
185+
uint32_t cb_hierarchy = 0U;
186186
uint64_t *sp = (uint64_t *)rsp;
187187

188188
printf("\r\nHost Stack: CPU_ID = %d\r\n", cpu_id);
189-
for (i = 0; i < DUMP_STACK_SIZE/32; i++) {
189+
for (i = 0U; i < DUMP_STACK_SIZE/32U; i++) {
190190
printf("addr(0x%llx) 0x%016llx 0x%016llx 0x%016llx "
191-
"0x%016llx\r\n", (rsp+i*32), sp[i*4], sp[i*4+1],
192-
sp[i*4+2], sp[i*4+3]);
191+
"0x%016llx\r\n", (rsp+i*32U), sp[i*4U], sp[i*4U+1U],
192+
sp[i*4U+2U], sp[i*4U+3U]);
193193
}
194194
printf("\r\n");
195195

@@ -249,7 +249,7 @@ void dump_intr_excp_frame(struct intr_excp_ctx *ctx)
249249

250250
printf("\n\n================================================");
251251
printf("================================\n=\n");
252-
if (ctx->vector < 0x20) {
252+
if (ctx->vector < 0x20UL) {
253253
name = excp_names[ctx->vector];
254254
printf("= Unhandled exception: %d (%s)\n", ctx->vector, name);
255255
}

hypervisor/debug/sbuf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void sbuf_free(struct shared_buf *sbuf)
7676
return;
7777
}
7878

79-
sbuf->magic = 0;
79+
sbuf->magic = 0UL;
8080
free(sbuf);
8181
}
8282

hypervisor/debug/serial.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ static uint8_t sio_initialized[SERIAL_MAX_DEVS];
1313
static struct uart *get_uart_by_id(char *uart_id, uint32_t *index)
1414
{
1515
/* Initialize the index to the start of array. */
16-
*index = 0;
16+
*index = 0U;
1717

1818
while (sio_ports[*index] != NULL) {
1919
if (strncmp(sio_ports[*index]->tgt_uart->uart_id, uart_id,
@@ -120,25 +120,26 @@ uint32_t serial_open(char *uart_id)
120120
SERIAL_INVALID_HANDLE;
121121
}
122122

123-
int serial_get_rx_data(uint32_t uart_handle)
123+
uint32_t serial_get_rx_data(uint32_t uart_handle)
124124
{
125125
uint32_t index;
126126
struct uart *uart;
127-
int data_avail, rx_byte_status;
127+
int data_avail;
128+
uint32_t rx_byte_status;
128129
uint32_t lsr_reg, bytes_read;
129130
uint8_t ch;
130-
int total_bytes_read = 0;
131+
uint32_t total_bytes_read = 0U;
131132

132133
if (!SERIAL_VALIDATE_HANDLE(uart_handle))
133-
return 0;
134+
return 0U;
134135

135136
index = SERIAL_DECODE_INDEX(uart_handle);
136137
if (index >= SERIAL_MAX_DEVS)
137-
return 0;
138+
return 0U;
138139

139140
uart = sio_ports[index];
140141
if (uart == NULL)
141-
return 0;
142+
return 0U;
142143

143144
/* Place all the data available in RX FIFO, in circular buffer */
144145
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)
230231
uint32_t index;
231232
int status = 0;
232233

233-
if ((buffer == NULL) || (length == 0))
234+
if ((buffer == NULL) || (length == 0U))
234235
return 0;
235236

236237
if (!SERIAL_VALIDATE_HANDLE(uart_handle))
@@ -242,7 +243,7 @@ int serial_gets(uint32_t uart_handle, char *buffer, uint32_t length)
242243

243244
port = sio_ports[index];
244245
if ((port != NULL) && (port->open_flag == true)) {
245-
for (; length > 0; data_read++, length--) {
246+
for (; length > 0U; length--) {
246247
/* Disable interrupts for critical section */
247248
spinlock_obtain(&port->buffer_lock);
248249

@@ -256,6 +257,7 @@ int serial_gets(uint32_t uart_handle, char *buffer, uint32_t length)
256257

257258
/* Save character in buffer */
258259
*data_read = (char) c;
260+
data_read++;
259261
}
260262
}
261263
/* Return actual number of bytes read */
@@ -264,7 +266,7 @@ int serial_gets(uint32_t uart_handle, char *buffer, uint32_t length)
264266

265267
static int serial_putc(uint32_t uart_handle, int c)
266268
{
267-
uint32_t index, bytes_written = 0;
269+
uint32_t index, bytes_written = 0U;
268270
struct uart *uart;
269271
int busy;
270272

@@ -290,7 +292,7 @@ static int serial_putc(uint32_t uart_handle, int c)
290292
uart->tgt_uart->write(uart->tgt_uart, &(c), &bytes_written);
291293

292294
/* Return character written or EOF for error */
293-
return ((bytes_written > 0) ? c : (SERIAL_EOF));
295+
return ((bytes_written > 0U) ? c : (SERIAL_EOF));
294296
}
295297

296298
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)
300302
struct uart *port;
301303
int retval = 0;
302304

303-
if ((s == NULL) || (length == 0))
305+
if ((s == NULL) || (length == 0U))
304306
return 0;
305307

306308
if (!SERIAL_VALIDATE_HANDLE(uart_handle))
@@ -326,7 +328,7 @@ int serial_puts(uint32_t uart_handle, const char *s, uint32_t length)
326328
* Loop through the string until desired length of bytes have
327329
* been written or SERIAL_EOF is returned.
328330
*/
329-
for (; length > 0 && retval != SERIAL_EOF; s++, length--)
331+
for (; length > 0U && retval != SERIAL_EOF; s++, length--)
330332
retval = serial_putc(uart_handle, (int) *s);
331333

332334
/* Allow other threads to use this service. */

hypervisor/debug/serial_internal.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
struct shared_buf;
1111

1212
/* Maximum serial devices supported by the platform. */
13-
#define SERIAL_MAX_DEVS 1
13+
#define SERIAL_MAX_DEVS 1U
1414

1515
/* Maximum length of unique id of each UART port enabled in platform. */
1616
#define SERIAL_ID_MAX_LENGTH 8
@@ -144,7 +144,7 @@ struct tgt_uart {
144144
const void *buffer, uint32_t *bytes_written);
145145
bool (*tx_is_busy)(struct tgt_uart *tgt_uart);
146146
bool (*rx_data_is_avail)(struct tgt_uart *tgt_uart, uint32_t *lsr_reg);
147-
int (*get_rx_err)(uint32_t rx_data);
147+
uint32_t (*get_rx_err)(uint32_t rx_data);
148148
};
149149

150150
/* Control Block definition of light-weight serial driver */
@@ -179,6 +179,6 @@ uint32_t serial_open(char *uart_id);
179179
int serial_getc(uint32_t uart_handle);
180180
int serial_gets(uint32_t uart_handle, char *buffer, uint32_t length);
181181
int serial_puts(uint32_t uart_handle, const char *s, uint32_t length);
182-
int serial_get_rx_data(uint32_t uart_handle);
182+
uint32_t serial_get_rx_data(uint32_t uart_handle);
183183

184184
#endif /* !SERIAL_INTER_H */

hypervisor/debug/shell_internal.c

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ uint32_t console_loglevel = CONFIG_CONSOLE_LOGLEVEL_DEFAULT;
3232
uint32_t mem_loglevel = CONFIG_MEM_LOGLEVEL_DEFAULT;
3333

3434
static int string_to_argv(char *argv_str, void *p_argv_mem,
35-
__unused uint32_t argv_mem_size, int *p_argc, char ***p_argv)
35+
__unused uint32_t argv_mem_size,
36+
uint32_t *p_argc, char ***p_argv)
3637
{
3738
uint32_t argc;
3839
char **argv;
3940
char *p_ch;
4041

4142
/* Setup initial argument values. */
42-
argc = 0;
43+
argc = 0U;
4344
argv = NULL;
4445

4546
/* Ensure there are arguments to be processed. */
@@ -103,7 +104,7 @@ static uint8_t shell_input_line(struct shell *p_shell)
103104
/* Backspace */
104105
case '\b':
105106
/* Ensure length is not 0 */
106-
if (p_shell->input_line_len > 0) {
107+
if (p_shell->input_line_len > 0U) {
107108
/* Reduce the length of the string by one */
108109
p_shell->input_line_len--;
109110

@@ -140,7 +141,7 @@ static uint8_t shell_input_line(struct shell *p_shell)
140141
done = true;
141142

142143
/* Reset command length for next command processing */
143-
p_shell->input_line_len = 0;
144+
p_shell->input_line_len = 0U;
144145
break;
145146

146147
/* Line feed */
@@ -153,7 +154,7 @@ static uint8_t shell_input_line(struct shell *p_shell)
153154
/* Ensure data doesn't exceed full terminal width */
154155
if (p_shell->input_line_len < SHELL_CMD_MAX_LEN) {
155156
/* See if a "standard" prINTable ASCII character received */
156-
if ((ch >= 32) && (ch <= 126)) {
157+
if ((ch >= 32U) && (ch <= 126U)) {
157158
/* Add character to string */
158159
p_shell->input_line[p_shell->input_line_active]
159160
[p_shell->input_line_len] = ch;
@@ -187,7 +188,7 @@ static uint8_t shell_input_line(struct shell *p_shell)
187188
done = true;
188189

189190
/* Reset command length for next command processing */
190-
p_shell->input_line_len = 0;
191+
p_shell->input_line_len = 0U;
191192

192193
}
193194
break;
@@ -225,7 +226,7 @@ static int shell_process(struct shell *p_shell)
225226

226227
/* Now that the command is processed, zero fill the input buffer */
227228
memset((void *) p_shell->input_line[p_shell->input_line_active], 0,
228-
SHELL_CMD_MAX_LEN + 1);
229+
SHELL_CMD_MAX_LEN + 1U);
229230

230231
/* Process command and return result to caller */
231232
return status;
@@ -236,10 +237,10 @@ struct shell_cmd *shell_find_cmd(struct shell *p_shell, const char *cmd_str)
236237
uint32_t i;
237238
struct shell_cmd *p_cmd = NULL;
238239

239-
if (p_shell->cmd_count <= 0)
240+
if (p_shell->cmd_count <= 0U)
240241
return NULL;
241242

242-
for (i = 0; i < p_shell->cmd_count; i++) {
243+
for (i = 0U; i < p_shell->cmd_count; i++) {
243244
p_cmd = &p_shell->shell_cmd[i];
244245
if (strcmp(p_cmd->str, cmd_str) == 0)
245246
break;
@@ -297,8 +298,8 @@ int shell_process_cmd(struct shell *p_shell, char *p_input_line)
297298
int status = 0;
298299
struct shell_cmd *p_cmd;
299300
shell_cmd_fn_t cmd_fcn;
300-
char cmd_argv_str[SHELL_CMD_MAX_LEN + 1];
301-
int cmd_argv_mem[sizeof(char *) * ((SHELL_CMD_MAX_LEN + 1) / 2)];
301+
char cmd_argv_str[SHELL_CMD_MAX_LEN + 1U];
302+
int cmd_argv_mem[sizeof(char *) * ((SHELL_CMD_MAX_LEN + 1U) / 2U)];
302303
int cmd_argc;
303304
char **cmd_argv;
304305

@@ -360,7 +361,7 @@ int shell_init_serial(struct shell *p_shell)
360361

361362
/* Zero fill the input buffer */
362363
memset((void *)p_shell->input_line[p_shell->input_line_active], 0,
363-
SHELL_CMD_MAX_LEN + 1);
364+
SHELL_CMD_MAX_LEN + 1U);
364365

365366
return status;
366367
}
@@ -383,14 +384,14 @@ int shell_cmd_help(struct shell *p_shell,
383384

384385
memset(space_buf, ' ', sizeof(space_buf));
385386
/* Proceed based on the number of registered commands. */
386-
if (p_shell->cmd_count == 0) {
387+
if (p_shell->cmd_count == 0U) {
387388
/* No registered commands */
388389
shell_puts(p_shell, "NONE\r\n");
389390
} else {
390-
int i = 0;
391+
int32_t i = 0;
391392
uint32_t j;
392393

393-
for (j = 0; j < p_shell->cmd_count; j++) {
394+
for (j = 0U; j < p_shell->cmd_count; j++) {
394395
p_cmd = &p_shell->shell_cmd[j];
395396

396397
/* Check if we've filled the screen with info */
@@ -733,28 +734,28 @@ int shell_vcpu_dumpreg(struct shell *p_shell,
733734
vm_id, cur_context->rsp);
734735
shell_puts(p_shell, temp_str);
735736

736-
for (i = 0; i < 8; i++) {
737+
for (i = 0UL; i < 8UL; i++) {
737738
snprintf(temp_str, MAX_STR_SIZE,
738739
"= 0x%016llx 0x%016llx "
739740
"0x%016llx 0x%016llx\r\n",
740-
tmp[i*4], tmp[i*4+1],
741-
tmp[i*4+2], tmp[i*4+3]);
741+
tmp[i*4UL], tmp[i*4UL+1UL],
742+
tmp[i*4UL+2UL], tmp[i*4UL+3UL]);
742743
shell_puts(p_shell, temp_str);
743744
}
744745
}
745746

746747
return status;
747748
}
748749

749-
#define MAX_MEMDUMP_LEN (32*8)
750+
#define MAX_MEMDUMP_LEN (32U*8U)
750751
int shell_vcpu_dumpmem(struct shell *p_shell,
751752
int argc, char **argv)
752753
{
753754
int status = 0;
754755
uint32_t vm_id, vcpu_id;
755756
uint64_t gva;
756757
uint64_t tmp[MAX_MEMDUMP_LEN/8];
757-
uint32_t i, length = 32;
758+
uint32_t i, length = 32U;
758759
char temp_str[MAX_STR_SIZE];
759760
struct vm *vm;
760761
struct vcpu *vcpu;
@@ -802,14 +803,14 @@ int shell_vcpu_dumpmem(struct shell *p_shell,
802803
"length %d:\r\n", vcpu_id, gva, length);
803804
shell_puts(p_shell, temp_str);
804805

805-
for (i = 0; i < length/32; i++) {
806+
for (i = 0U; i < length/32U; i++) {
806807
snprintf(temp_str, MAX_STR_SIZE,
807808
"= 0x%016llx 0x%016llx 0x%016llx "
808809
"0x%016llx\r\n", tmp[i*4], tmp[i*4+1],
809810
tmp[i*4+2], tmp[i*4+3]);
810811
shell_puts(p_shell, temp_str);
811812
}
812-
if (length > 32*(length/32)) {
813+
if ((length % 32U) != 0) {
813814
snprintf(temp_str, MAX_STR_SIZE,
814815
"= 0x%016llx 0x%016llx 0x%016llx "
815816
"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)
10951096
{
10961097
switch (ch) {
10971098
/* Escape character */
1098-
case 0x1b:
1099+
case 0x1bU:
10991100
/* Consume the next 2 characters */
11001101
(void) p_shell->session_io.io_getc(p_shell);
11011102
(void) p_shell->session_io.io_getc(p_shell);

hypervisor/debug/shell_internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct shell_io {
2222
bool io_echo_on;
2323
};
2424

25-
#define SHELL_CMD_MAX_LEN 100
25+
#define SHELL_CMD_MAX_LEN 100U
2626
#define SHELL_NAME_MAX_LEN 50
2727
#define SHELL_PARA_MAX_LEN 64
2828
#define SHELL_HELP_MAX_LEN 256
@@ -32,7 +32,7 @@ struct shell_io {
3232
struct shell_cmd;
3333
struct shell {
3434
struct shell_io session_io; /* Session I/O information */
35-
char input_line[2][SHELL_CMD_MAX_LEN + 1]; /* current & last */
35+
char input_line[2][SHELL_CMD_MAX_LEN + 1U]; /* current & last */
3636
char name[SHELL_NAME_MAX_LEN]; /* Session name */
3737
uint32_t input_line_len; /* Length of current input line */
3838
uint32_t input_line_active; /* Active input line index */

0 commit comments

Comments
 (0)