Skip to content

Commit 58672cb

Browse files
Shawnshhlijinxia
authored andcommitted
fix "negative shift"
MISRA C doesn't allowed negative shift, changed any potential signed value to unsigned value. Signed-off-by: Huihuang Shi <huihuang.shi@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent de31cf4 commit 58672cb

File tree

7 files changed

+16
-13
lines changed

7 files changed

+16
-13
lines changed

hypervisor/arch/x86/cpu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ int ibrs_type;
5959
inline bool cpu_has_cap(uint32_t bit)
6060
{
6161
int feat_idx = bit >> 5;
62-
int feat_bit = bit & 0x1fU;
62+
uint32_t feat_bit = bit & 0x1fU;
6363

6464
if (feat_idx >= FEATURE_WORDS)
6565
return false;

hypervisor/arch/x86/guest/guest.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ enum vm_paging_mode get_vcpu_paging_mode(struct vcpu *vcpu)
127127
static int _gva2gpa_common(struct vcpu *vcpu, struct page_walk_info *pw_info,
128128
uint64_t gva, uint64_t *gpa, uint32_t *err_code)
129129
{
130-
int i, index, shift;
130+
int i, index;
131+
uint32_t shift;
131132
uint8_t *base;
132133
uint64_t entry;
133134
uint64_t addr, page_size;

hypervisor/arch/x86/guest/instr_emul.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1407,7 +1407,8 @@ emulate_bittest(struct vcpu *vcpu, uint64_t gpa, struct vie *vie,
14071407
void *memarg)
14081408
{
14091409
uint64_t val, rflags;
1410-
int error, bitmask, bitoff;
1410+
int error, bitmask;
1411+
uint32_t bitoff;
14111412

14121413
/*
14131414
* 0F BA is a Group 8 extended opcode.

hypervisor/arch/x86/guest/vioapic.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ vioapic_update_tmr(struct vcpu *vcpu)
223223
static uint32_t
224224
vioapic_read(struct vioapic *vioapic, uint32_t addr)
225225
{
226-
uint32_t regnum;
227-
int pin, rshift;
226+
uint32_t regnum, rshift;
227+
int pin;
228228

229229
regnum = addr & 0xffU;
230230
switch (regnum) {
@@ -291,8 +291,8 @@ vioapic_write(struct vioapic *vioapic, uint32_t addr, uint32_t data)
291291
{
292292
uint64_t data64, mask64;
293293
uint64_t last, new, changed;
294-
uint32_t regnum;
295-
int pin, lshift;
294+
uint32_t regnum, lshift;
295+
int pin;
296296

297297
regnum = addr & 0xffUL;
298298
switch (regnum) {

hypervisor/arch/x86/guest/vlapic.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -712,8 +712,9 @@ vlapic_update_ppr(struct vlapic *vlapic)
712712

713713
/* update ppr */
714714
{
715-
int i, lastprio, curprio, vector, idx;
715+
int i, lastprio, curprio, idx;
716716
struct lapic_reg *isrptr;
717+
uint32_t vector;
717718

718719
if (vlapic->isrvec_stk_top == 0 && isrvec != 0)
719720
panic("isrvec_stk is corrupted: %d", isrvec);
@@ -738,9 +739,9 @@ vlapic_update_ppr(struct vlapic *vlapic)
738739
*/
739740
i = 1;
740741
isrptr = &vlapic->apic_page->isr[0];
741-
for (vector = 0; vector < 256; vector++) {
742-
idx = vector / 32;
743-
if ((isrptr[idx].val & (1U << (vector % 32))) != 0U) {
742+
for (vector = 0U; vector < 256U; vector++) {
743+
idx = vector / 32U;
744+
if ((isrptr[idx].val & (1U << (vector % 32U))) != 0U) {
744745
if ((i > vlapic->isrvec_stk_top) ||
745746
((i < ISRVEC_STK_SIZE) &&
746747
(vlapic->isrvec_stk[i] != vector))) {

hypervisor/arch/x86/ioapic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ create_rte_for_gsi_irq(uint32_t irq, uint32_t vr)
191191
rte.lo_32 |= IOAPIC_RTE_INTALO;
192192

193193
/* Dest field */
194-
rte.hi_32 |= ALL_CPUS_MASK << 24;
194+
rte.hi_32 |= ALL_CPUS_MASK << 24U;
195195

196196
return rte;
197197
}

hypervisor/include/arch/x86/vtd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
#define iommu_cap_plmr(c) (((c) >> 5) & 1UL)
6767
#define iommu_cap_rwbf(c) (((c) >> 4) & 1UL)
6868
#define iommu_cap_afl(c) (((c) >> 3) & 1UL)
69-
#define iommu_cap_ndoms(c) (((unsigned long)1) << (4 + 2 * ((c) & 0x7UL)))
69+
#define iommu_cap_ndoms(c) ((1U) << (4U + 2U * ((c) & 0x7U)))
7070

7171
/*
7272
* Decoding Extended Capability Register

0 commit comments

Comments
 (0)