diff --git a/hypervisor/arch/x86/guest/pm.c b/hypervisor/arch/x86/guest/pm.c index 5ad6238a7..1a1321690 100644 --- a/hypervisor/arch/x86/guest/pm.c +++ b/hypervisor/arch/x86/guest/pm.c @@ -198,8 +198,9 @@ register_gas_io_handler(struct vm *vm, struct acpi_generic_address *gas) if ((gas->address == 0UL) || (gas->space_id != SPACE_SYSTEM_IO) || (gas->access_size == 0U) - || (gas->access_size > 4U)) + || (gas->access_size > 4U)) { return; + } gas_io.flags = IO_ATTR_RW, gas_io.base = (uint16_t)gas->address, diff --git a/hypervisor/arch/x86/guest/ucode.c b/hypervisor/arch/x86/guest/ucode.c index c714a8a7e..6d543d565 100644 --- a/hypervisor/arch/x86/guest/ucode.c +++ b/hypervisor/arch/x86/guest/ucode.c @@ -51,8 +51,9 @@ void acrn_update_ucode(struct vcpu *vcpu, uint64_t v) (data_size + CPU_PAGE_SIZE - 1) >> CPU_PAGE_SHIFT; ucode_ptr = alloc_pages(data_page_num); - if (ucode_ptr == NULL) + if (ucode_ptr == NULL) { return; + } err_code = 0U; err = copy_from_gva(vcpu, ucode_ptr, gva, data_size, &err_code); diff --git a/hypervisor/arch/x86/guest/vlapic.c b/hypervisor/arch/x86/guest/vlapic.c index a971b3d24..92474c120 100644 --- a/hypervisor/arch/x86/guest/vlapic.c +++ b/hypervisor/arch/x86/guest/vlapic.c @@ -1682,8 +1682,9 @@ vlapic_deliver_intr(struct vm *vm, bool level, uint32_t dest, bool phys, struct vlapic *vlapic; bitmap_clear(vcpu_id, &dmask); target_vcpu = vcpu_from_vid(vm, vcpu_id); - if (target_vcpu == NULL) + if (target_vcpu == NULL) { return; + } /* only make request when vlapic enabled */ vlapic = target_vcpu->arch_vcpu.vlapic; @@ -2112,8 +2113,9 @@ int vlapic_create(struct vcpu *vcpu) (uint64_t)DEFAULT_APIC_BASE, (uint64_t)DEFAULT_APIC_BASE + CPU_PAGE_SIZE, - (void *) 0) != 0) + (void *) 0) != 0) { return -1; + } } vcpu->arch_vcpu.vlapic = vlapic; @@ -2455,8 +2457,9 @@ int apic_write_vmexit_handler(struct vcpu *vcpu) break; case APIC_OFFSET_ICR_LOW: error = vlapic_icrlo_write_handler(vlapic); - if (error != 0) + if (error != 0) { handled = 0; + } break; case APIC_OFFSET_CMCI_LVT: case APIC_OFFSET_TIMER_LVT: diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index 684f7f75f..f2173296c 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -87,8 +87,9 @@ int create_vm(struct vm_description *vm_desc, struct vm **rtn_vm) /* Init mmio list */ INIT_LIST_HEAD(&vm->mmio_list); - if (vm->hw.num_vcpus == 0U) + if (vm->hw.num_vcpus == 0U) { vm->hw.num_vcpus = phys_cpu_num; + } vm->hw.vcpu_array = calloc(1, sizeof(struct vcpu *) * vm->hw.num_vcpus); @@ -221,8 +222,9 @@ int shutdown_vm(struct vm *vm) vioapic_cleanup(vm->arch_vm.virt_ioapic); /* Destroy secure world */ - if (vm->sworld_control.sworld_enabled) + if (vm->sworld_control.sworld_enabled) { destroy_secure_world(vm); + } /* Free EPT allocated resources assigned to VM */ destroy_ept(vm); diff --git a/hypervisor/arch/x86/guest/vpic.c b/hypervisor/arch/x86/guest/vpic.c index 8610963bc..03c7a448c 100644 --- a/hypervisor/arch/x86/guest/vpic.c +++ b/hypervisor/arch/x86/guest/vpic.c @@ -489,8 +489,9 @@ static void vpic_set_pinstate(struct vpic *vpic, uint8_t pin, bool newstate) } else if (oldcnt == 1 && newcnt == 0) { /* falling edge */ dev_dbg(ACRN_DBG_PIC, "pic pin%hhu: deasserted\n", pin); - if (level) + if (level) { pic->request &= ~(uint8_t)(1U << (pin & 0x7U)); + } } else { dev_dbg(ACRN_DBG_PIC, "pic pin%hhu: %s, ignored, acnt %d\n", @@ -598,8 +599,9 @@ int vpic_get_irq_trigger(struct vm *vm, uint32_t irq, enum vpic_trigger *trigger { struct vpic *vpic; - if (irq >= NR_VPIC_PINS_TOTAL) + if (irq >= NR_VPIC_PINS_TOTAL) { return -EINVAL; + } vpic = vm_pic(vm); if (vpic == NULL) { @@ -659,8 +661,9 @@ static void vpic_pin_accepted(struct pic *pic, uint8_t pin) } if (pic->aeoi == true) { - if (pic->rotate == true) + if (pic->rotate == true) { pic->lowprio = pin; + } } else { pic->service |= (uint8_t)(1U << pin); } @@ -756,8 +759,9 @@ static int vpic_write(struct vpic *vpic, struct pic *pic, break; } } else { - if ((val & (1U << 4U)) != 0U) + if ((val & (1U << 4U)) != 0U) { error = vpic_icw1(vpic, pic, val); + } if (pic->ready) { if ((val & (1U << 3U)) != 0U) { diff --git a/hypervisor/arch/x86/irq.c b/hypervisor/arch/x86/irq.c index acdf910f4..f8ad6131b 100644 --- a/hypervisor/arch/x86/irq.c +++ b/hypervisor/arch/x86/irq.c @@ -619,8 +619,9 @@ void unregister_handler_common(struct dev_handler_node *node) } while (head->next != NULL) { - if (head->next == node) + if (head->next == node) { break; + } head = head->next; } diff --git a/hypervisor/arch/x86/mmu.c b/hypervisor/arch/x86/mmu.c index 84a008d03..93cce65b3 100644 --- a/hypervisor/arch/x86/mmu.c +++ b/hypervisor/arch/x86/mmu.c @@ -345,8 +345,9 @@ static uint32_t map_mem_region(void *vaddr, void *paddr, /* Invalidate TLB and page-structure cache, * if it is the first mapping no need to invalidate TLB */ - if ((table_type == PTT_HOST) && prev_entry_present) + if ((table_type == PTT_HOST) && prev_entry_present) { mmu_need_invtlb = true; + } break; } case PAGING_REQUEST_TYPE_UNMAP: @@ -360,8 +361,9 @@ static uint32_t map_mem_region(void *vaddr, void *paddr, /* Unmap, need to invalidate TLB and * page-structure cache */ - if (table_type == PTT_HOST) + if (table_type == PTT_HOST) { mmu_need_invtlb = true; + } } break; } @@ -379,8 +381,9 @@ static uint32_t map_mem_region(void *vaddr, void *paddr, /* Modify, need to invalidate TLB and * page-structure cache */ - if (table_type == PTT_HOST) + if (table_type == PTT_HOST) { mmu_need_invtlb = true; + } break; } case PAGING_REQUEST_TYPE_MODIFY_MT: @@ -554,8 +557,9 @@ static void *walk_paging_struct(void *addr, void *table_base, /* Write entry to current table to reference the new * sub-table */ - if (map_params->page_table_type == PTT_HOST) + if (map_params->page_table_type == PTT_HOST) { entry_present |= attr; + } mem_write64(table_base + table_offset, HVA2HPA(sub_table_addr) | entry_present); @@ -683,8 +687,9 @@ bool check_continuous_hpa(struct vm *vm, uint64_t gpa, uint64_t size) curr_hpa = gpa2hpa(vm, gpa); gpa += PAGE_SIZE_4K; next_hpa = gpa2hpa(vm, gpa); - if (next_hpa != (curr_hpa + PAGE_SIZE_4K)) + if (next_hpa != (curr_hpa + PAGE_SIZE_4K)) { return false; + } size -= PAGE_SIZE_4K; } return true; @@ -703,8 +708,9 @@ int obtain_last_page_table_entry(struct map_params *map_params, /* Obtain page table entry from PML4 table*/ ret = get_table_entry(addr, table_addr, IA32E_PML4, &table_entry); - if (ret < 0) + if (ret < 0) { return ret; + } entry_present = check_page_table_present(map_params->page_table_type, table_entry); if (entry_present == PT_MISCFG_PRESENT) { @@ -726,8 +732,9 @@ int obtain_last_page_table_entry(struct map_params *map_params, /* Obtain page table entry from PDPT table*/ table_addr = HPA2HVA(table_entry & IA32E_REF_MASK); ret = get_table_entry(addr, table_addr, IA32E_PDPT, &table_entry); - if (ret < 0) + if (ret < 0) { return ret; + } entry_present = check_page_table_present(map_params->page_table_type, table_entry); if (entry_present == PT_MISCFG_PRESENT) { @@ -761,8 +768,9 @@ int obtain_last_page_table_entry(struct map_params *map_params, /* Obtain page table entry from PD table*/ table_addr = HPA2HVA(table_entry & IA32E_REF_MASK); ret = get_table_entry(addr, table_addr, IA32E_PD, &table_entry); - if (ret < 0) + if (ret < 0) { return ret; + } entry_present = check_page_table_present(map_params->page_table_type, table_entry); if (entry_present == PT_MISCFG_PRESENT) { @@ -792,8 +800,9 @@ int obtain_last_page_table_entry(struct map_params *map_params, /* Obtain page table entry from PT table*/ table_addr = HPA2HVA(table_entry & IA32E_REF_MASK); ret = get_table_entry(addr, table_addr, IA32E_PT, &table_entry); - if (ret < 0) + if (ret < 0) { return ret; + } entry_present = check_page_table_present(map_params->page_table_type, table_entry); if (entry_present == PT_MISCFG_PRESENT) { @@ -825,8 +834,9 @@ static uint64_t update_page_table_entry(struct map_params *map_params, /* Walk from the PML4 table to the PDPT table */ table_addr = walk_paging_struct(vaddr, table_addr, IA32E_PML4, map_params, attr); - if (table_addr == NULL) + if (table_addr == NULL) { return 0; + } if ((remaining_size >= MEM_1G) && (MEM_ALIGNED_CHECK(vaddr, MEM_1G)) @@ -842,8 +852,9 @@ static uint64_t update_page_table_entry(struct map_params *map_params, /* Walk from the PDPT table to the PD table */ table_addr = walk_paging_struct(vaddr, table_addr, IA32E_PDPT, map_params, attr); - if (table_addr == NULL) + if (table_addr == NULL) { return 0; + } /* Map this 2 MByte memory region */ adjustment_size = map_mem_region(vaddr, paddr, table_addr, attr, IA32E_PD, table_type, @@ -852,13 +863,15 @@ static uint64_t update_page_table_entry(struct map_params *map_params, /* Walk from the PDPT table to the PD table */ table_addr = walk_paging_struct(vaddr, table_addr, IA32E_PDPT, map_params, attr); - if (table_addr == NULL) + if (table_addr == NULL) { return 0; + } /* Walk from the PD table to the page table */ table_addr = walk_paging_struct(vaddr, table_addr, IA32E_PD, map_params, attr); - if (table_addr == NULL) + if (table_addr == NULL) { return 0; + } /* Map this 4 KByte memory region */ adjustment_size = map_mem_region(vaddr, paddr, table_addr, attr, IA32E_PT, @@ -1010,8 +1023,9 @@ static int modify_paging(struct map_params *map_params, void *paddr, */ while (remaining_size > 0) { if (obtain_last_page_table_entry(map_params, &entry, vaddr, - direct) < 0) + direct) < 0) { return -EINVAL; + } /* filter the unmap request, no action in this case*/ page_size = entry.page_size; if ((request_type == PAGING_REQUEST_TYPE_UNMAP) @@ -1040,8 +1054,9 @@ static int modify_paging(struct map_params *map_params, void *paddr, */ page_size = break_page_table(map_params, paddr, vaddr, page_size, direct); - if (page_size == 0UL) + if (page_size == 0UL) { return -EINVAL; + } } } else { page_size = ((uint64_t)remaining_size < page_size) @@ -1050,8 +1065,9 @@ static int modify_paging(struct map_params *map_params, void *paddr, /* The function return the memory size that one entry can map */ adjust_size = update_page_table_entry(map_params, paddr, vaddr, page_size, attr, request_type, direct); - if (adjust_size == 0UL) + if (adjust_size == 0UL) { return -EINVAL; + } vaddr += adjust_size; paddr += adjust_size; remaining_size -= adjust_size; @@ -1068,8 +1084,9 @@ int map_mem(struct map_params *map_params, void *paddr, void *vaddr, /* used for MMU and EPT*/ ret = modify_paging(map_params, paddr, vaddr, size, flags, PAGING_REQUEST_TYPE_MAP, true); - if (ret < 0) + if (ret < 0) { return ret; + } /* only for EPT */ if (map_params->page_table_type == PTT_EPT) { ret = modify_paging(map_params, vaddr, paddr, size, flags, @@ -1086,8 +1103,9 @@ int unmap_mem(struct map_params *map_params, void *paddr, void *vaddr, /* used for MMU and EPT */ ret = modify_paging(map_params, paddr, vaddr, size, flags, PAGING_REQUEST_TYPE_UNMAP, true); - if (ret < 0) + if (ret < 0) { return ret; + } /* only for EPT */ if (map_params->page_table_type == PTT_EPT) { ret = modify_paging(map_params, vaddr, paddr, size, flags, @@ -1104,8 +1122,9 @@ int modify_mem(struct map_params *map_params, void *paddr, void *vaddr, /* used for MMU and EPT*/ ret = modify_paging(map_params, paddr, vaddr, size, flags, PAGING_REQUEST_TYPE_MODIFY, true); - if (ret < 0) + if (ret < 0) { return ret; + } /* only for EPT */ if (map_params->page_table_type == PTT_EPT) { ret = modify_paging(map_params, vaddr, paddr, size, flags, @@ -1122,8 +1141,9 @@ int modify_mem_mt(struct map_params *map_params, void *paddr, void *vaddr, /* used for MMU and EPT*/ ret = modify_paging(map_params, paddr, vaddr, size, flags, PAGING_REQUEST_TYPE_MODIFY_MT, true); - if (ret < 0) + if (ret < 0) { return ret; + } /* only for EPT */ if (map_params->page_table_type == PTT_EPT) { diff --git a/hypervisor/arch/x86/notify.c b/hypervisor/arch/x86/notify.c index 0ba426d15..2d31b36f5 100644 --- a/hypervisor/arch/x86/notify.c +++ b/hypervisor/arch/x86/notify.c @@ -46,8 +46,9 @@ void setup_notification(void) char name[32] = {0}; cpu = get_cpu_id(); - if (cpu > 0U) + if (cpu > 0U) { return; + } /* support IPI notification, VM0 will register all CPU */ snprintf(name, 32, "NOTIFY_ISR%d", cpu); @@ -63,7 +64,8 @@ void setup_notification(void) static void cleanup_notification(void) { - if (notification_node != NULL) + if (notification_node != NULL) { unregister_handler_common(notification_node); + } notification_node = NULL; } diff --git a/hypervisor/arch/x86/softirq.c b/hypervisor/arch/x86/softirq.c index 902829a2a..90d317eed 100644 --- a/hypervisor/arch/x86/softirq.c +++ b/hypervisor/arch/x86/softirq.c @@ -31,8 +31,9 @@ void raise_softirq(int softirq_id) uint16_t cpu_id = get_cpu_id(); uint64_t *bitmap = &per_cpu(softirq_pending, cpu_id); - if (cpu_id >= phys_cpu_num) + if (cpu_id >= phys_cpu_num) { return; + } bitmap_set(softirq_id, bitmap); } @@ -44,8 +45,9 @@ void exec_softirq(void) uint16_t softirq_id; - if (cpu_id >= phys_cpu_num) + if (cpu_id >= phys_cpu_num) { return; + } if (((*bitmap) & SOFTIRQ_MASK) == 0UL) { return; @@ -90,4 +92,3 @@ again: enable_softirq(cpu_id); } - diff --git a/hypervisor/arch/x86/vmexit.c b/hypervisor/arch/x86/vmexit.c index 77fbb8928..8486d449c 100644 --- a/hypervisor/arch/x86/vmexit.c +++ b/hypervisor/arch/x86/vmexit.c @@ -313,8 +313,9 @@ static int xsetbv_vmexit_handler(struct vcpu *vcpu) } idx = vcpu->arch_vcpu.cur_context; - if (idx >= NR_WORLD) + if (idx >= NR_WORLD) { return -1; + } ctx_ptr = &(vcpu->arch_vcpu.contexts[idx]); diff --git a/hypervisor/arch/x86/vmx.c b/hypervisor/arch/x86/vmx.c index 222010c78..2d6800408 100644 --- a/hypervisor/arch/x86/vmx.c +++ b/hypervisor/arch/x86/vmx.c @@ -560,8 +560,9 @@ static void init_guest_state(struct vcpu *vcpu) /*************************************************/ pr_dbg("Natural-width********"); - if (vcpu_mode == CPU_MODE_64BIT) + if (vcpu_mode == CPU_MODE_64BIT) { cur_context->ia32_efer = MSR_IA32_EFER_LME_BIT; + } /* Setup guest control register values * cr4 should be set before cr0, because when set cr0, cr4 value will be diff --git a/hypervisor/arch/x86/vtd.c b/hypervisor/arch/x86/vtd.c index b05a9e641..1b54544b1 100644 --- a/hypervisor/arch/x86/vtd.c +++ b/hypervisor/arch/x86/vtd.c @@ -410,11 +410,13 @@ static void dmar_register_hrhd(struct dmar_drhd_rt *dmar_uint) #endif /* check capability */ - if ((iommu_cap_super_page_val(dmar_uint->cap) & 0x1UL) == 0) + if ((iommu_cap_super_page_val(dmar_uint->cap) & 0x1UL) == 0) { dev_dbg(ACRN_DBG_IOMMU, "dmar uint doesn't support 2MB page!"); + } - if ((iommu_cap_super_page_val(dmar_uint->cap) & 0x2UL) == 0) + if ((iommu_cap_super_page_val(dmar_uint->cap) & 0x2UL) == 0) { dev_dbg(ACRN_DBG_IOMMU, "dmar uint doesn't support 1GB page!"); + } /* when the hardware support snoop control, * to make sure snoop control is always enabled, @@ -610,8 +612,9 @@ static void dmar_invalid_iotlb(struct dmar_drhd_rt *dmar_uint, case DMAR_IIRG_PAGE: cmd |= DMA_IOTLB_PAGE_INVL | DMA_IOTLB_DID(did); addr = address | DMA_IOTLB_INVL_ADDR_AM(am); - if (hint) + if (hint) { addr |= DMA_IOTLB_INVL_ADDR_IH_UNMODIFIED; + } break; default: pr_err("unknown IIRG type"); @@ -736,8 +739,9 @@ static void fault_status_analysis(uint32_t status) static void fault_record_analysis(__unused uint64_t low, uint64_t high) { - if (DMA_FRCD_UP_F(high) == 0U) + if (DMA_FRCD_UP_F(high) == 0U) { return; + } /* currently skip PASID related parsing */ pr_info("%s, Reason: 0x%x, SID: %x.%x.%x @0x%llx", diff --git a/hypervisor/common/vm_load.c b/hypervisor/common/vm_load.c index 901e856fe..64c873937 100644 --- a/hypervisor/common/vm_load.c +++ b/hypervisor/common/vm_load.c @@ -115,16 +115,18 @@ int general_sw_loader(struct vm *vm, struct vcpu *vcpu) pr_dbg("Loading guest to run-time location"); /* FIXME: set config according to predefined offset */ - if (!is_vm0(vm)) + if (!is_vm0(vm)) { return load_guest(vm, vcpu); + } /* calculate the kernel entry point */ zeropage = (struct zero_page *) vm->sw.kernel_info.kernel_src_addr; kernel_entry_offset = (zeropage->hdr.setup_sects + 1) * 512; - if (vcpu->arch_vcpu.cpu_mode == CPU_MODE_64BIT) + if (vcpu->arch_vcpu.cpu_mode == CPU_MODE_64BIT) { /* 64bit entry is the 512bytes after the start */ kernel_entry_offset += 512; + } vm->sw.kernel_info.kernel_entry_addr = (void *)((uint64_t)vm->sw.kernel_info.kernel_load_addr diff --git a/hypervisor/debug/logmsg.c b/hypervisor/debug/logmsg.c index 955f09677..eb6c191d0 100644 --- a/hypervisor/debug/logmsg.c +++ b/hypervisor/debug/logmsg.c @@ -149,9 +149,10 @@ void do_logmsg(uint32_t severity, const char *fmt, ...) /* switch to sbuf from sos */ do_copy_earlylog(sbuf, early_sbuf); free_earlylog_sbuf(pcpu_id); - } else + } else { /* use earlylog sbuf if no sbuf from sos */ sbuf = early_sbuf; + } } if (sbuf != NULL) { diff --git a/hypervisor/debug/serial.c b/hypervisor/debug/serial.c index d105cf02f..3d66d0587 100644 --- a/hypervisor/debug/serial.c +++ b/hypervisor/debug/serial.c @@ -135,8 +135,9 @@ uint32_t serial_get_rx_data(uint32_t uart_handle) uint8_t ch; uint32_t total_bytes_read = 0U; - if (!SERIAL_VALIDATE_HANDLE(uart_handle)) + if (!SERIAL_VALIDATE_HANDLE(uart_handle)) { return 0U; + } index = SERIAL_DECODE_INDEX(uart_handle); if (index >= SERIAL_MAX_DEVS) { diff --git a/hypervisor/debug/shell_internal.c b/hypervisor/debug/shell_internal.c index b20edb4ea..307af0ff8 100644 --- a/hypervisor/debug/shell_internal.c +++ b/hypervisor/debug/shell_internal.c @@ -567,8 +567,9 @@ int shell_pause_vcpu(struct shell *p_shell, vm_id = (uint16_t)status; } vcpu_id = (uint16_t)atoi(argv[2]); - if (vcpu_id >= phys_cpu_num) + if (vcpu_id >= phys_cpu_num) { return (-EINVAL); + } vm = get_vm_from_vmid(vm_id); if (vm != NULL) { vcpu = vcpu_from_vid(vm, vcpu_id); @@ -622,8 +623,9 @@ int shell_resume_vcpu(struct shell *p_shell, } vm_id = (uint16_t)status; vcpu_id = (uint16_t)atoi(argv[2]); - if (vcpu_id >= phys_cpu_num) + if (vcpu_id >= phys_cpu_num) { return (-EINVAL); + } vm = get_vm_from_vmid(vm_id); if (vm != NULL) { vcpu = vcpu_from_vid(vm, vcpu_id); @@ -682,8 +684,9 @@ int shell_vcpu_dumpreg(struct shell *p_shell, } vm_id = (uint16_t)status; vcpu_id = (uint16_t)atoi(argv[2]); - if (vcpu_id >= phys_cpu_num) + if (vcpu_id >= phys_cpu_num) { return (-EINVAL); + } vm = get_vm_from_vmid(vm_id); if (vm == NULL) { shell_puts(p_shell, "No vm found in the input " @@ -804,8 +807,9 @@ int shell_vcpu_dumpmem(struct shell *p_shell, } vm_id = (uint16_t)status; vcpu_id = (uint16_t)atoi(argv[2]); - if (vcpu_id >= phys_cpu_num) + if (vcpu_id >= phys_cpu_num) { return (-EINVAL); + } vm = get_vm_from_vmid(vm_id); if (vm == NULL) { status = -EINVAL; diff --git a/hypervisor/lib/memory.c b/hypervisor/lib/memory.c index a81d0c50e..5179e5637 100644 --- a/hypervisor/lib/memory.c +++ b/hypervisor/lib/memory.c @@ -64,8 +64,9 @@ static void *allocate_mem(struct mem_pool *pool, unsigned int num_bytes) uint32_t requested_buffs; /* Check if provided memory pool exists */ - if (pool == NULL) + if (pool == NULL) { return NULL; + } /* Acquire the pool lock */ spinlock_obtain(&pool->spinlock); @@ -102,8 +103,9 @@ static void *allocate_mem(struct mem_pool *pool, unsigned int num_bytes) * out-of-range */ tmp_idx++; - if (tmp_idx == pool->bmp_size) + if (tmp_idx == pool->bmp_size) { break; + } /* Reset tmp_bit_idx */ tmp_bit_idx = 0U; } @@ -424,8 +426,9 @@ void *memset(void *base, uint8_t v, size_t n) dest_p = (uint8_t *)base; - if ((dest_p == NULL) || (n == 0U)) + if ((dest_p == NULL) || (n == 0U)) { return NULL; + } /*do the few bytes to get uint64_t alignment*/ count = n; diff --git a/hypervisor/lib/sprintf.c b/hypervisor/lib/sprintf.c index 08d3f51fe..2c395c109 100644 --- a/hypervisor/lib/sprintf.c +++ b/hypervisor/lib/sprintf.c @@ -229,8 +229,9 @@ static int format_number(struct print_param *param) /* emit prefix, return early if an error occurred */ res = param->emit(PRINT_CMD_COPY, param->vars.prefix, param->vars.prefixlen, param->data); - if ((param->vars.prefix != NULL) && (res < 0)) + if ((param->vars.prefix != NULL) && (res < 0)) { return res; + } /* invalidate prefix */ param->vars.prefix = NULL; @@ -241,8 +242,9 @@ static int format_number(struct print_param *param) * an error occurred */ res = param->emit(PRINT_CMD_FILL, &pad, w, param->data); - if (res < 0) + if (res < 0) { return res; + } } /* emit prefix (if any), return early in case of an error */ @@ -271,8 +273,9 @@ static int format_number(struct print_param *param) if ((param->vars.flags & PRINT_FLAG_LEFT_JUSTIFY) != 0) { /* emit trailing blanks, return early in case of an error */ res = param->emit(PRINT_CMD_FILL, " ", w, param->data); - if (res < 0) + if (res < 0) { return res; + } } /* done, return the last result */ @@ -520,8 +523,9 @@ int do_print(const char *fmt, struct print_param *param, if (*fmt == '.') { fmt++; fmt = get_int(fmt, &(param->vars.precision)); - if (param->vars.precision < 0) + if (param->vars.precision < 0) { param->vars.precision = 0; + } } fmt = get_length_modifier(fmt, &(param->vars.flags), diff --git a/hypervisor/lib/string.c b/hypervisor/lib/string.c index 2c9f3af56..785fc3c29 100644 --- a/hypervisor/lib/string.c +++ b/hypervisor/lib/string.c @@ -85,8 +85,7 @@ long strtol_deci(const char *nptr) if (any < 0) { acc = (neg != 0) ? LONG_MIN : LONG_MAX; - } - else if (neg != 0) { + } else if (neg != 0) { acc = -acc; } return acc; @@ -123,14 +122,11 @@ uint64_t strtoul_hex(const char *nptr) do { if (c >= '0' && c <= '9') { c -= '0'; - } - else if (c >= 'A' && c <= 'F') { + } else if (c >= 'A' && c <= 'F') { c -= 'A' - 10; - } - else if (c >= 'a' && c <= 'f') { + } else if (c >= 'a' && c <= 'f') { c -= 'a' - 10; - } - else { + } else { break; } if (c >= base) { @@ -138,8 +134,7 @@ uint64_t strtoul_hex(const char *nptr) } if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) { any = -1; - } - else { + } else { any = 1; acc *= base; acc += c; @@ -220,8 +215,9 @@ char *strcpy_s(char *d, size_t dmax, const char *s) } *d = *s; - if (*d == '\0') + if (*d == '\0') { return dest_base; + } d++; s++; @@ -347,8 +343,9 @@ size_t strnlen_s(const char *str, size_t maxlen) { size_t count; - if (str == NULL) + if (str == NULL) { return 0; + } count = 0U; while ((*str) != 0) {