Skip to content

Commit 23a5c74

Browse files
mgcaolijinxia
authored andcommitted
HV: handle integral issues as MISRA-C report
mainly focus on: like U/UL as unsigned suffix; char and int mix usage; also change some function's params for data type consistent. Signed-off-by: Minggui Cao <minggui.cao@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 0252ae9 commit 23a5c74

File tree

13 files changed

+106
-104
lines changed

13 files changed

+106
-104
lines changed

hypervisor/arch/x86/trusty.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ static bool setup_trusty_info(struct vcpu *vcpu,
359359
(void)memcpy_s(&mem->first_page.data.key_info, sizeof(g_key_info),
360360
&g_key_info, sizeof(g_key_info));
361361

362-
(void)memset(mem->first_page.data.key_info.dseed_list, 0,
362+
(void)memset(mem->first_page.data.key_info.dseed_list, 0U,
363363
sizeof(mem->first_page.data.key_info.dseed_list));
364364
/* Derive dvseed from dseed for Trusty */
365365
key_info = &mem->first_page.data.key_info;
@@ -370,7 +370,7 @@ static bool setup_trusty_info(struct vcpu *vcpu,
370370
BUP_MKHI_BOOTLOADER_SEED_LEN,
371371
NULL, 0U,
372372
vcpu->vm->GUID, sizeof(vcpu->vm->GUID)) == 0) {
373-
(void)memset(key_info, 0, sizeof(struct key_info));
373+
(void)memset(key_info, 0U, sizeof(struct key_info));
374374
pr_err("%s: derive dvseed failed!", __func__);
375375
return false;
376376
}
@@ -439,7 +439,7 @@ bool initialize_trusty(struct vcpu *vcpu, uint64_t param)
439439
struct vm *vm = vcpu->vm;
440440
struct trusty_boot_param boot_param;
441441

442-
memset(&boot_param, 0, sizeof(boot_param));
442+
memset(&boot_param, 0U, sizeof(boot_param));
443443
if (copy_from_gpa(vcpu->vm, &boot_param, param, sizeof(boot_param))) {
444444
pr_err("%s: Unable to copy trusty_boot_param\n", __func__);
445445
return false;
@@ -497,7 +497,7 @@ void trusty_set_dseed(void *dseed, uint8_t dseed_num)
497497
(dseed_num > BOOTLOADER_SEED_MAX_ENTRIES)) {
498498

499499
g_key_info.num_seeds = 1U;
500-
(void)memset(g_key_info.dseed_list[0].seed, 0xA5,
500+
(void)memset(g_key_info.dseed_list[0].seed, 0xA5U,
501501
sizeof(g_key_info.dseed_list[0].seed));
502502
return;
503503
}

hypervisor/arch/x86/trusty2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ uint64_t gpa2hpa_for_trusty(struct vm *vm, uint64_t gpa)
5353
*
5454
*/
5555
void create_secure_world_ept(struct vm *vm, uint64_t gpa_orig,
56-
int64_t size, uint64_t gpa_rebased)
56+
uint64_t size, uint64_t gpa_rebased)
5757
{
5858
uint64_t nworld_pml4e = 0UL;
5959
uint64_t sworld_pml4e = 0UL;

hypervisor/boot/sbl/hob_parse.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
void parse_seed_list(struct seed_list_hob *seed_hob)
1111
{
1212
uint8_t i;
13-
uint8_t dseed_index = 0;
13+
uint8_t dseed_index = 0U;
1414
struct seed_entry *entry;
1515
struct seed_info dseed_list[BOOTLOADER_SEED_MAX_ENTRIES];
1616

@@ -19,15 +19,15 @@ void parse_seed_list(struct seed_list_hob *seed_hob)
1919
goto fail;
2020
}
2121

22-
if (seed_hob->total_seed_count == 0) {
22+
if (seed_hob->total_seed_count == 0U) {
2323
pr_warn("Total seed count is 0. Use fake seed!");
2424
goto fail;
2525
}
2626

2727
entry = (struct seed_entry *)((uint8_t *)seed_hob +
2828
sizeof(struct seed_list_hob));
2929

30-
for (i = 0; i < seed_hob->total_seed_count; i++) {
30+
for (i = 0U; i < seed_hob->total_seed_count; i++) {
3131
/* retrieve dseed */
3232
if ((SEED_ENTRY_TYPE_SVNSEED == entry->type) &&
3333
(SEED_ENTRY_USAGE_DSEED == entry->usage)) {
@@ -52,18 +52,18 @@ void parse_seed_list(struct seed_list_hob *seed_hob)
5252
dseed_index++;
5353

5454
/* erase original seed in seed entry */
55-
(void)memset(entry->seed, 0, sizeof(struct seed_info));
55+
(void)memset(entry->seed, 0U, sizeof(struct seed_info));
5656
}
5757

5858
entry = (struct seed_entry *)((uint8_t *)entry +
5959
entry->seed_entry_size);
6060
}
6161

6262
trusty_set_dseed(dseed_list, dseed_index);
63-
(void)memset(dseed_list, 0, sizeof(dseed_list));
63+
(void)memset(dseed_list, 0U, sizeof(dseed_list));
6464
return;
6565

6666
fail:
67-
trusty_set_dseed(NULL, 0);
68-
(void)memset(dseed_list, 0, sizeof(dseed_list));
67+
trusty_set_dseed(NULL, 0U);
68+
(void)memset(dseed_list, 0U, sizeof(dseed_list));
6969
}

hypervisor/boot/sbl/multiboot.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#define BOOT_ARGS_LOAD_ADDR 0x24EFC000
1313

14-
#define ACRN_DBG_BOOT 6
14+
#define ACRN_DBG_BOOT 6U
1515

1616
/* There are two sources for vm0 kernel cmdline:
1717
* - cmdline from sbl. mbi->cmdline
@@ -22,12 +22,12 @@ static char kernel_cmdline[MEM_2K];
2222

2323
/* now modules support: FIRMWARE & RAMDISK & SeedList */
2424
static void parse_other_modules(struct vm *vm,
25-
struct multiboot_module *mods, int mods_count)
25+
struct multiboot_module *mods, uint32_t mods_count)
2626
{
27-
int i = 0;
27+
uint32_t i;
2828

29-
for (i = 0; i < mods_count; i++) {
30-
int type_len = 0;
29+
for (i = 0U; i < mods_count; i++) {
30+
uint32_t type_len;
3131
const char *start = HPA2HVA((uint64_t)mods[i].mm_string);
3232
const char *end;
3333
void *mod_addr = HPA2HVA((uint64_t)mods[i].mm_mod_start);
@@ -43,13 +43,13 @@ static void parse_other_modules(struct vm *vm,
4343
}
4444

4545
end = start;
46-
while (*end != ' ' && (*end) != 0) {
46+
while (*end != ' ' && (*end) != '\0') {
4747
end++;
4848
}
4949

5050
type_len = end - start;
5151
if (strncmp("FIRMWARE", start, type_len) == 0) {
52-
char dyn_bootargs[100] = {0};
52+
char dyn_bootargs[100] = {'\0'};
5353
void *load_addr = GPA2HVA(vm,
5454
(uint64_t)vm->sw.linux_info.bootargs_load_addr);
5555
uint32_t args_size = vm->sw.linux_info.bootargs_size;
@@ -63,23 +63,23 @@ static void parse_other_modules(struct vm *vm,
6363
/*copy boot args to load addr, set src=load addr*/
6464
if (copy_once != 0) {
6565
copy_once = 0;
66-
(void)strcpy_s(load_addr, MEM_2K,
67-
vm->sw.linux_info.bootargs_src_addr);
66+
(void)strcpy_s(load_addr, MEM_2K, (const
67+
char *)vm->sw.linux_info.bootargs_src_addr);
6868
vm->sw.linux_info.bootargs_src_addr = load_addr;
6969
}
7070

7171
(void)strcpy_s(load_addr + args_size,
72-
100, dyn_bootargs);
72+
100U, dyn_bootargs);
7373
vm->sw.linux_info.bootargs_size =
7474
strnlen_s(load_addr, MEM_2K);
7575

7676
} else if (strncmp("RAMDISK", start, type_len) == 0) {
7777
vm->sw.linux_info.ramdisk_src_addr = mod_addr;
7878
vm->sw.linux_info.ramdisk_load_addr =
79-
mods[i].mm_mod_start;
79+
(void *)(uint64_t)mods[i].mm_mod_start;
8080
vm->sw.linux_info.ramdisk_size = mod_size;
8181
} else if (strncmp("SeedList", start, type_len) == 0) {
82-
parse_seed_list(mod_addr);
82+
parse_seed_list((struct seed_list_hob *)mod_addr);
8383
} else {
8484
pr_warn("not support mod, cmd: %s", start);
8585
}
@@ -151,22 +151,21 @@ int init_vm0_boot_info(struct vm *vm)
151151
vm->sw.kernel_info.kernel_load_addr = (void *)HVA2GPA(vm,
152152
get_kernel_load_addr(vm->sw.kernel_info.kernel_src_addr));
153153

154-
155154
/*
156155
* If there is cmdline from mbi->mi_cmdline, merge it with
157156
* mods[0].mm_string
158157
*/
159158
if ((mbi->mi_flags & MULTIBOOT_INFO_HAS_CMDLINE) != 0U) {
160159
char *cmd_src, *cmd_dst;
161-
int off = 0;
160+
uint32_t off;
162161

163162
cmd_dst = kernel_cmdline;
164163
cmd_src = HPA2HVA((uint64_t)mbi->mi_cmdline);
165164
(void)strncpy_s(cmd_dst, MEM_2K, cmd_src,
166165
strnlen_s(cmd_src, MEM_2K));
167166
off = strnlen_s(cmd_dst, MEM_2K);
168167
cmd_dst[off] = ' '; /* insert space */
169-
off += 1;
168+
off += 1U;
170169

171170
cmd_dst += off;
172171
cmd_src = HPA2HVA((uint64_t)mods[0].mm_string);
@@ -186,7 +185,7 @@ int init_vm0_boot_info(struct vm *vm)
186185

187186
vm->sw.linux_info.bootargs_load_addr = (void *)BOOT_ARGS_LOAD_ADDR;
188187

189-
if (mbi->mi_mods_count > 1) {
188+
if (mbi->mi_mods_count > 1U) {
190189
/*parse other modules, like firmware /ramdisk */
191190
parse_other_modules(vm, mods + 1, mbi->mi_mods_count - 1);
192191
}

hypervisor/include/arch/x86/hob_parse.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
#ifndef HOB_PARSE_H_
88
#define HOB_PARSE_H_
99

10-
#define SEED_ENTRY_TYPE_SVNSEED 0x1
11-
#define SEED_ENTRY_TYPE_RPMBSEED 0x2
10+
#define SEED_ENTRY_TYPE_SVNSEED 0x1U
11+
#define SEED_ENTRY_TYPE_RPMBSEED 0x2U
1212

13-
#define SEED_ENTRY_USAGE_USEED 0x1
14-
#define SEED_ENTRY_USAGE_DSEED 0x2
13+
#define SEED_ENTRY_USAGE_USEED 0x1U
14+
#define SEED_ENTRY_USAGE_DSEED 0x2U
1515

1616
struct seed_list_hob {
1717
uint8_t revision;

hypervisor/include/arch/x86/trusty.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#define RPMB_MAX_PARTITION_NUMBER 6
1616
#define MMC_PROD_NAME_WITH_PSN_LEN 15
17-
#define BUP_MKHI_BOOTLOADER_SEED_LEN 64
17+
#define BUP_MKHI_BOOTLOADER_SEED_LEN 64U
1818

1919
/* Trusty EPT rebase gpa: 511G */
2020
#define TRUSTY_EPT_REBASE_GPA (511UL * 1024UL * 1024UL * 1024UL)
@@ -96,7 +96,7 @@ struct key_info {
9696

9797
#ifdef WORKAROUND_FOR_TRUSTY_4G_MEM
9898
void create_secure_world_ept(struct vm *vm, uint64_t gpa_orig,
99-
int64_t size, uint64_t gpa_rebased);
99+
uint64_t size, uint64_t gpa_rebased);
100100
struct secure_world_memory {
101101
/* The secure world base address of GPA for secure world*/
102102
uint64_t base_gpa;

hypervisor/include/lib/sprintf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct print_param {
2424
/* Contains variables which are recalculated for each argument. */
2525
struct {
2626
/* A bitfield with the parsed format flags. */
27-
int flags;
27+
uint32_t flags;
2828
/* The parsed format width. */
2929
int width;
3030
/* The parsed format precision. */

hypervisor/lib/div.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ int udiv32(uint32_t dividend, uint32_t divisor, struct udiv_result *res)
4343
/* test for "division by 0" condition */
4444
if (divisor == 0U) {
4545
res->q.dwords.low = 0xffffffffU;
46-
return !0;
46+
return 1;
4747
}
4848
/* trivial case: divisor==dividend */
4949
if (divisor == dividend) {
50-
res->q.dwords.low = 1;
50+
res->q.dwords.low = 1U;
5151
return 0;
5252
}
5353
/* trivial case: divisor>dividend */

hypervisor/lib/mdelay.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
void mdelay(uint32_t loop_count)
1010
{
1111
/* Loop until done */
12-
while (loop_count != 0) {
12+
while (loop_count != 0U) {
1313
/* Delay for 1 ms */
14-
udelay(1000);
14+
udelay(1000U);
1515
loop_count--;
1616
}
1717
}

hypervisor/lib/memory.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static void *allocate_mem(struct mem_pool *pool, unsigned int num_bytes)
9595
/* Check requested_buffs number of buffers availability
9696
* in memory-pool right after selected buffer
9797
*/
98-
for (i = 1; i < requested_buffs; i++) {
98+
for (i = 1U; i < requested_buffs; i++) {
9999
/* Check if tmp_bit_idx is out-of-range */
100100
tmp_bit_idx++;
101101
if (tmp_bit_idx == BITMAP_WORD_SIZE) {
@@ -244,8 +244,8 @@ void *malloc(unsigned int num_bytes)
244244
*/
245245
memory = allocate_mem(&Memory_Pool, num_bytes);
246246
} else {
247-
int page_num =
248-
(num_bytes + CPU_PAGE_SIZE - 1) >> CPU_PAGE_SHIFT;
247+
uint32_t page_num =
248+
(num_bytes + CPU_PAGE_SIZE - 1U) >> CPU_PAGE_SHIFT;
249249
/* Request memory allocation through alloc_page */
250250
memory = alloc_pages(page_num);
251251
}
@@ -276,7 +276,7 @@ void *alloc_pages(unsigned int page_num)
276276

277277
void *alloc_page(void)
278278
{
279-
return alloc_pages(1);
279+
return alloc_pages(1U);
280280
}
281281

282282
void *calloc(unsigned int num_elements, unsigned int element_size)
@@ -286,7 +286,7 @@ void *calloc(unsigned int num_elements, unsigned int element_size)
286286
/* Determine if memory was allocated */
287287
if (memory != NULL) {
288288
/* Zero all the memory */
289-
(void)memset(memory, 0, num_elements * element_size);
289+
(void)memset(memory, 0U, num_elements * element_size);
290290
}
291291

292292
/* Return pointer to memory */

0 commit comments

Comments
 (0)