HV:treewide:fix "Attempt to change parameter passed by value"

In the function scope,the parameter should not be
changed as Misra required.
V1->V2 recover some violations because of ldra's false positive.
V2->V3 sync local variable' type to parameter's type with the prefix of const.

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-25 11:19:52 +08:00 committed by lijinxia
parent e71a0887a0
commit 5189bcd272
26 changed files with 96 additions and 59 deletions

View File

@ -7,11 +7,12 @@
#include <hypervisor.h>
static inline struct vcpuid_entry *find_vcpuid_entry(struct vcpu *vcpu,
uint32_t leaf, uint32_t subleaf)
uint32_t leaf_arg, uint32_t subleaf)
{
uint32_t i = 0U, nr, half;
struct vcpuid_entry *entry = NULL;
struct vm *vm = vcpu->vm;
uint32_t leaf = leaf_arg;
nr = vm->vcpuid_entry_nr;
half = nr / 2U;

View File

@ -485,12 +485,15 @@ int ept_misconfig_vmexit_handler(__unused struct vcpu *vcpu)
return status;
}
int ept_mr_add(struct vm *vm, uint64_t hpa,
uint64_t gpa, uint64_t size, uint32_t prot)
int ept_mr_add(struct vm *vm, uint64_t hpa_arg,
uint64_t gpa_arg, uint64_t size, uint32_t prot_arg)
{
struct map_params map_params;
uint16_t i;
struct vcpu *vcpu;
uint64_t hpa = hpa_arg;
uint64_t gpa = gpa_arg;
uint32_t prot = prot_arg;
/* Setup memory map parameters */
map_params.page_table_type = PTT_EPT;
@ -536,12 +539,14 @@ int ept_mr_modify(struct vm *vm, uint64_t *pml4_page,
return ret;
}
int ept_mr_del(struct vm *vm, uint64_t hpa,
uint64_t gpa, uint64_t size)
int ept_mr_del(struct vm *vm, uint64_t hpa_arg,
uint64_t gpa_arg, uint64_t size)
{
struct map_params map_params;
uint16_t i;
struct vcpu *vcpu;
uint64_t hpa = hpa_arg;
uint64_t gpa = gpa_arg;
/* Setup memory map parameters */
map_params.page_table_type = PTT_EPT;

View File

@ -352,10 +352,12 @@ static inline uint32_t _copy_gpa(struct vm *vm, void *h_ptr, uint64_t gpa,
return len;
}
static inline int copy_gpa(struct vm *vm, void *h_ptr, uint64_t gpa,
uint32_t size, bool cp_from_vm)
static inline int copy_gpa(struct vm *vm, void *h_ptr, uint64_t gpa_arg,
uint32_t size_arg, bool cp_from_vm)
{
uint32_t len;
uint64_t gpa = gpa_arg;
uint32_t size = size_arg;
if (vm == NULL) {
pr_err("guest phy addr copy need vm param");
@ -376,12 +378,14 @@ static inline int copy_gpa(struct vm *vm, void *h_ptr, uint64_t gpa,
return 0;
}
static inline int copy_gva(struct vcpu *vcpu, void *h_ptr, uint64_t gva,
uint32_t size, uint32_t *err_code, bool cp_from_vm)
static inline int copy_gva(struct vcpu *vcpu, void *h_ptr, uint64_t gva_arg,
uint32_t size_arg, uint32_t *err_code, bool cp_from_vm)
{
uint64_t gpa = 0UL;
int32_t ret;
uint32_t len;
uint64_t gva = gva_arg;
uint32_t size = size_arg;
if (vcpu == NULL) {
pr_err("guest virt addr copy need vcpu param");
@ -639,9 +643,10 @@ int prepare_vm0_memmap_and_e820(struct vm *vm)
return 0;
}
uint64_t e820_alloc_low_memory(uint32_t size)
uint64_t e820_alloc_low_memory(uint32_t size_arg)
{
uint32_t i;
uint32_t size = size_arg;
struct e820_entry *entry, *new_entry;
/* We want memory in page boundary and integral multiple of pages */

View File

@ -309,10 +309,11 @@ vie_write_bytereg(struct vcpu *vcpu, struct vie *vie, uint8_t byte)
int
vie_update_register(struct vcpu *vcpu, enum cpu_reg_name reg,
uint64_t val, uint8_t size)
uint64_t val_arg, uint8_t size)
{
int error;
uint64_t origval;
uint64_t val = val_arg;
switch (size) {
case 1U:
@ -1572,10 +1573,12 @@ vie_size2mask(uint8_t size)
int
vie_calculate_gla(enum vm_cpu_mode cpu_mode, enum cpu_reg_name seg,
struct seg_desc *desc, uint64_t offset, uint8_t length,
struct seg_desc *desc, uint64_t offset_arg, uint8_t length_arg,
uint8_t addrsize, uint32_t prot, uint64_t *gla)
{
uint64_t firstoff, low_limit, high_limit, segbase;
uint64_t offset = offset_arg;
uint8_t length = length_arg;
uint8_t glasize;
uint32_t type;

View File

@ -57,7 +57,7 @@ int vmm_emulate_instruction(struct vcpu *vcpu, uint64_t gpa, struct vie *vie,
mem_region_write_t mrw, void *mrarg);
int vie_update_register(struct vcpu *vcpu, enum cpu_reg_name reg,
uint64_t val, uint8_t size);
uint64_t val_arg, uint8_t size);
/*
* Returns 1 if an alignment check exception should be injected and 0 otherwise.
@ -71,8 +71,8 @@ int vie_canonical_check(enum vm_cpu_mode cpu_mode, uint64_t gla);
uint64_t vie_size2mask(uint8_t size);
int vie_calculate_gla(enum vm_cpu_mode cpu_mode, enum cpu_reg_name seg,
struct seg_desc *desc, uint64_t off, uint8_t length, uint8_t addrsize,
uint32_t prot, uint64_t *gla);
struct seg_desc *desc, uint64_t offset_arg, uint8_t length_arg,
uint8_t addrsize, uint32_t prot, uint64_t *gla);
int vie_init(struct vie *vie, struct vcpu *vcpu);

View File

@ -409,9 +409,10 @@ static uint64_t vlapic_get_tsc_deadline_msr(struct vlapic *vlapic)
}
static void vlapic_set_tsc_deadline_msr(struct vlapic *vlapic,
uint64_t val)
uint64_t val_arg)
{
struct timer *timer;
uint64_t val = val_arg;
if (!vlapic_lvtt_tsc_deadline(vlapic)) {
return;
@ -1299,11 +1300,12 @@ vlapic_svr_write_handler(struct vlapic *vlapic)
}
static int
vlapic_read(struct vlapic *vlapic, int mmio_access, uint32_t offset,
vlapic_read(struct vlapic *vlapic, int mmio_access, uint32_t offset_arg,
uint64_t *data)
{
struct lapic_regs *lapic = vlapic->apic_page;
uint32_t i;
uint32_t offset = offset_arg;
if (mmio_access == 0) {
/*
@ -1830,11 +1832,12 @@ vlapic_set_intr(struct vcpu *vcpu, uint32_t vector, bool level)
}
int
vlapic_set_local_intr(struct vm *vm, uint16_t vcpu_id, uint32_t vector)
vlapic_set_local_intr(struct vm *vm, uint16_t vcpu_id_arg, uint32_t vector)
{
struct vlapic *vlapic;
uint64_t dmask = 0UL;
int error;
uint16_t vcpu_id = vcpu_id_arg;
if ((vcpu_id != BROADCAST_CPU_ID) && (vcpu_id >= phys_cpu_num)) {
return -EINVAL;

View File

@ -25,11 +25,12 @@ static const uint32_t emulated_msrs[] = {
*/
};
static void enable_msr_interception(uint8_t *bitmap, uint32_t msr)
static void enable_msr_interception(uint8_t *bitmap, uint32_t msr_arg)
{
uint8_t *read_map;
uint8_t *write_map;
uint8_t value;
uint32_t msr = msr_arg;
/* low MSR */
if (msr < 0x1FFFU) {
read_map = bitmap;
@ -51,11 +52,12 @@ static void enable_msr_interception(uint8_t *bitmap, uint32_t msr)
}
/* not used now just leave it for some cases it may be used as API*/
static void disable_msr_interception(uint8_t *bitmap, uint32_t msr)
static void disable_msr_interception(uint8_t *bitmap, uint32_t msr_arg)
{
uint8_t *read_map;
uint8_t *write_map;
uint8_t value;
uint32_t msr = msr_arg;
/* low MSR */
if (msr < 0x1FFFU) {
read_map = bitmap;

View File

@ -335,9 +335,10 @@ static int vpic_icw4(struct vpic *vpic, struct pic *pic, uint8_t val)
return 0;
}
bool vpic_is_pin_mask(struct vpic *vpic, uint8_t virt_pin)
bool vpic_is_pin_mask(struct vpic *vpic, uint8_t virt_pin_arg)
{
struct pic *pic;
uint8_t virt_pin = virt_pin_arg;
if (virt_pin < 8U) {
pic = &vpic->pic[0];

View File

@ -200,12 +200,13 @@ irq_desc_append_dev(struct irq_desc *desc, void *node, bool share)
}
static struct dev_handler_node*
common_register_handler(uint32_t irq,
common_register_handler(uint32_t irq_arg,
struct irq_request_info *info)
{
struct dev_handler_node *node = NULL;
struct irq_desc *desc;
bool added = false;
uint32_t irq = irq_arg;
/* ======================================================
* This is low level ISR handler registering function

View File

@ -209,8 +209,9 @@ bool check_mmu_1gb_support(enum _page_table_type page_table_type)
static inline uint32_t
check_page_table_present(enum _page_table_type page_table_type,
uint64_t table_entry)
uint64_t table_entry_arg)
{
uint64_t table_entry = table_entry_arg;
if (page_table_type == PTT_EPT) {
table_entry &= (IA32E_EPT_R_BIT | IA32E_EPT_W_BIT |
IA32E_EPT_X_BIT);
@ -234,11 +235,12 @@ check_page_table_present(enum _page_table_type page_table_type,
}
static uint32_t map_mem_region(void *vaddr, void *paddr,
void *table_base, uint64_t attr, uint32_t table_level,
void *table_base, uint64_t attr_arg, uint32_t table_level,
enum _page_table_type table_type,
enum mem_map_request_type request_type)
{
uint64_t table_entry;
uint64_t attr = attr_arg;
uint32_t table_offset;
uint32_t mapped_size;
@ -630,10 +632,12 @@ void free_paging_struct(void *ptr)
}
}
bool check_continuous_hpa(struct vm *vm, uint64_t gpa, uint64_t size)
bool check_continuous_hpa(struct vm *vm, uint64_t gpa_arg, uint64_t size_arg)
{
uint64_t curr_hpa = 0UL;
uint64_t next_hpa = 0UL;
uint64_t gpa = gpa_arg;
uint64_t size = size_arg;
/* if size <= PAGE_SIZE_4K, it is continuous,no need check
* if size > PAGE_SIZE_4K, need to fetch next page

View File

@ -6,12 +6,13 @@
#include <hypervisor.h>
static int charout(int cmd, const char *s, int sz, void *hnd)
static int charout(int cmd, const char *s, int32_t sz_arg, void *hnd)
{
/* pointer to an integer to store the number of characters */
int *nchars = (int *)hnd;
/* working pointer */
const char *p = s;
int32_t sz = sz_arg;
/* copy mode ? */
if (cmd == PRINT_CMD_COPY) {

View File

@ -16,9 +16,10 @@ static inline bool sbuf_is_empty(struct shared_buf *sbuf)
return (sbuf->head == sbuf->tail);
}
static inline uint32_t sbuf_next_ptr(uint32_t pos,
static inline uint32_t sbuf_next_ptr(uint32_t pos_arg,
uint32_t span, uint32_t scope)
{
uint32_t pos = pos_arg;
pos += span;
pos = (pos >= scope) ? (pos - scope) : pos;
return pos;

View File

@ -237,13 +237,14 @@ exit:
return ((status > 0) ? (int)(ch) : SERIAL_EOF);
}
int serial_gets(uint32_t uart_handle, char *buffer, uint32_t length)
int serial_gets(uint32_t uart_handle, char *buffer, uint32_t length_arg)
{
char *data_read = buffer;
int c;
struct uart *port;
uint32_t index;
int status = 0;
uint32_t length = length_arg;
if ((buffer == NULL) || (length == 0U)) {
return 0;
@ -316,12 +317,13 @@ static int serial_putc(uint32_t uart_handle, int c)
return ((bytes_written > 0U) ? c : (SERIAL_EOF));
}
int serial_puts(uint32_t uart_handle, const char *s, uint32_t length)
int serial_puts(uint32_t uart_handle, const char *s, uint32_t length_arg)
{
const char *old_data = s;
uint32_t index;
struct uart *port;
int retval = 0;
uint32_t length = length_arg;
if ((s == NULL) || (length == 0U)) {
return 0;

View File

@ -177,8 +177,8 @@ extern struct tgt_uart Tgt_Uarts[SERIAL_MAX_DEVS];
uint32_t serial_open(const 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_gets(uint32_t uart_handle, char *buffer, uint32_t length_arg);
int serial_puts(uint32_t uart_handle, const char *s, uint32_t length_arg);
uint32_t serial_get_rx_data(uint32_t uart_handle);
#endif /* !SERIAL_INTER_H */

View File

@ -85,8 +85,9 @@ static void uart16550_enable(__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 ref_freq, uint32_t *baud_div_ptr, uint32_t baud_rate_arg)
{
uint32_t baud_rate = baud_rate_arg;
uint32_t baud_multiplier = baud_rate < BAUD_460800 ? 16 : 13;
if (baud_rate == 0) {

View File

@ -59,7 +59,7 @@ struct e820_mem_params {
};
int prepare_vm0_memmap_and_e820(struct vm *vm);
uint64_t e820_alloc_low_memory(uint32_t size);
uint64_t e820_alloc_low_memory(uint32_t size_arg);
/* Definition for a mem map lookup */
struct vm_lu_mem_map {

View File

@ -90,7 +90,7 @@ vlapic_intr_edge(struct vcpu *vcpu, uint32_t vector)
* Triggers the LAPIC local interrupt (LVT) 'vector' on 'cpu'. 'cpu' can
* be set to -1 to trigger the interrupt on all CPUs.
*/
int vlapic_set_local_intr(struct vm *vm, uint16_t vcpu_id, uint32_t vector);
int vlapic_set_local_intr(struct vm *vm, uint16_t vcpu_id_arg, uint32_t vector);
int vlapic_intr_msi(struct vm *vm, uint64_t addr, uint64_t msg);

View File

@ -104,6 +104,6 @@ int vpic_set_irq_trigger(struct vm *vm, uint32_t irq,
int vpic_get_irq_trigger(struct vm *vm, uint32_t irq,
enum vpic_trigger *trigger);
bool vpic_is_pin_mask(struct vpic *vpic, uint8_t virt_pin);
bool vpic_is_pin_mask(struct vpic *vpic, uint8_t virt_pin_arg);
#endif /* _VPIC_H_ */

View File

@ -335,7 +335,7 @@ uint16_t allocate_vpid(void);
void flush_vpid_single(uint16_t vpid);
void flush_vpid_global(void);
void invept(struct vcpu *vcpu);
bool check_continuous_hpa(struct vm *vm, uint64_t gpa, uint64_t size);
bool check_continuous_hpa(struct vm *vm, uint64_t gpa_arg, uint64_t size_arg);
int obtain_last_page_table_entry(struct map_params *map_params,
struct entry_params *entry, void *addr, bool direct);
@ -398,13 +398,13 @@ void destroy_ept(struct vm *vm);
uint64_t gpa2hpa(struct vm *vm, uint64_t gpa);
uint64_t _gpa2hpa(struct vm *vm, uint64_t gpa, uint32_t *size);
uint64_t hpa2gpa(struct vm *vm, uint64_t hpa);
int ept_mr_add(struct vm *vm, uint64_t hpa,
uint64_t gpa, uint64_t size, uint32_t prot);
int ept_mr_add(struct vm *vm, uint64_t hpa_arg,
uint64_t gpa_arg, uint64_t size, uint32_t prot_arg);
int ept_mr_modify(struct vm *vm, uint64_t *pml4_page,
uint64_t gpa, uint64_t size,
uint64_t prot_set, uint64_t prot_clr);
int ept_mr_del(struct vm *vm, uint64_t hpa,
uint64_t gpa, uint64_t size);
int ept_mr_del(struct vm *vm, uint64_t hpa_arg,
uint64_t gpa_arg, uint64_t size);
int ept_violation_vmexit_handler(struct vcpu *vcpu);
int ept_misconfig_vmexit_handler(struct vcpu *vcpu);

View File

@ -30,14 +30,14 @@ void udelay(uint32_t us);
void *memchr(const void *void_s, int c, size_t n);
int strcmp(const char *s1, const char *s2);
int strncmp(const char *s1, const char *s2, size_t n);
char *strcpy_s(char *d, size_t dmax, const char *s);
char *strncpy_s(char *d, size_t dmax, const char *s, size_t slen);
char *strcpy_s(char *d, size_t dmax, const char *s_arg);
char *strncpy_s(char *d, size_t dmax, const char *s, size_t slen_arg);
char *strchr(const char *s, int ch);
void mdelay(unsigned int ms);
size_t strnlen_s(const char *str, size_t maxlen);
void mdelay(uint32_t loop_count_arg);
size_t strnlen_s(const char *str, size_t maxlen_arg);
void *memset(void *base, uint8_t v, size_t n);
void *memcpy_s(void *d, size_t dmax, const void *s, size_t slen);
int udiv64(uint64_t dividend, uint64_t divisor, struct udiv_result *res);
void *memcpy_s(void *d, size_t dmax, const void *s, size_t slen_arg);
int udiv64(uint64_t dividend_arg, uint64_t divisor_arg, struct udiv_result *res);
int udiv32(uint32_t dividend, uint32_t divisor, struct udiv_result *res);
int atoi(const char *str);
long strtol_deci(const char *nptr);

View File

@ -57,7 +57,7 @@ int do_print(const char *fmt, struct print_param *param,
* is smaller. On error a negative number is returned.
*/
int vsnprintf(char *dst, int sz, const char *fmt, va_list args);
int vsnprintf(char *dst, int32_t sz_arg, const char *fmt, va_list args);
/** The well known snprintf() function.
*

View File

@ -6,10 +6,10 @@
#include <hv_lib.h>
static int do_udiv32(uint32_t dividend, uint32_t divisor,
static int do_udiv32(uint32_t dividend_arg, uint32_t divisor,
struct udiv_result *res)
{
uint32_t dividend = dividend_arg;
uint32_t mask;
/* dividend is always greater than or equal to the divisor. Neither
* divisor nor dividend are 0. Thus: * clz(dividend) and clz(divisor)
@ -61,9 +61,10 @@ int udiv32(uint32_t dividend, uint32_t divisor, struct udiv_result *res)
return do_udiv32(dividend, divisor, res);
}
int udiv64(uint64_t dividend, uint64_t divisor, struct udiv_result *res)
int udiv64(uint64_t dividend_arg, uint64_t divisor_arg, struct udiv_result *res)
{
uint64_t dividend = dividend_arg;
uint64_t divisor = divisor_arg;
uint64_t mask;
uint64_t bits;

View File

@ -6,8 +6,9 @@
#include <hv_lib.h>
void mdelay(uint32_t loop_count)
void mdelay(uint32_t loop_count_arg)
{
uint32_t loop_count = loop_count_arg;
/* Loop until done */
while (loop_count != 0U) {
/* Delay for 1 ms */

View File

@ -351,11 +351,11 @@ void *memchr(const void *void_s, int c, size_t n)
* or else return null.
*
***********************************************************************/
void *memcpy_s(void *d, size_t dmax, const void *s, size_t slen)
void *memcpy_s(void *d, size_t dmax, const void *s, size_t slen_arg)
{
uint8_t *dest8;
uint8_t *src8;
size_t slen = slen_arg;
if (slen == 0U || dmax == 0U || dmax < slen) {
ASSERT(false);

View File

@ -682,10 +682,11 @@ static int charmem(int cmd, const char *s, int sz, void *hnd)
return n;
}
int vsnprintf(char *dst, int sz, const char *fmt, va_list args)
int vsnprintf(char *dst, int32_t sz_arg, const char *fmt, va_list args)
{
char c[1];
/* the result of this function */
int32_t sz = sz_arg;
int res = 0;
if (sz <= 0 || (dst == NULL)) {

View File

@ -190,12 +190,13 @@ char *strchr(const char *s, int ch)
* 1) both d and s shall not be null pointers.
* 2) dmax shall not 0.
*/
char *strcpy_s(char *d, size_t dmax, const char *s)
char *strcpy_s(char *d, size_t dmax, const char *s_arg)
{
char *dest_base;
size_t dest_avail;
uint64_t overlap_guard;
const char *s = s_arg;
if (s == NULL || d == NULL || dmax == 0U) {
pr_err("%s: invalid src, dest buffer or length.", __func__);
@ -266,11 +267,12 @@ char *strcpy_s(char *d, size_t dmax, const char *s)
* 3) will assert() if overlap happens or dest buffer has no
* enough space.
*/
char *strncpy_s(char *d, size_t dmax, const char *s, size_t slen)
char *strncpy_s(char *d, size_t dmax, const char *s, size_t slen_arg)
{
char *dest_base;
size_t dest_avail;
uint64_t overlap_guard;
size_t slen = slen_arg;
if (d == NULL || s == NULL) {
pr_err("%s: invlaid src or dest buffer", __func__);
@ -343,9 +345,10 @@ char *strncpy_s(char *d, size_t dmax, const char *s, size_t slen)
* string length, excluding the null character.
* will return 0 if str is null.
*/
size_t strnlen_s(const char *str, size_t maxlen)
size_t strnlen_s(const char *str, size_t maxlen_arg)
{
size_t count;
size_t maxlen = maxlen_arg;
if (str == NULL) {
return 0;
@ -384,8 +387,9 @@ int strcmp(const char *s1, const char *s2)
return *s1 - *s2;
}
int strncmp(const char *s1, const char *s2, size_t n)
int strncmp(const char *s1, const char *s2, size_t n_arg)
{
size_t n = n_arg;
while (((n - 1) != 0U) && ((*s1) != '\0') && ((*s2) != '\0')
&& ((*s1) == (*s2))) {
s1++;