Skip to content

Commit 88a3205

Browse files
rarindamwenlingz
authored andcommitted
HV: Fix missing brackets for MISRA C Violations
Patch 1 of 7. Added changes to make sure Misra C violations are fixed for rules 11S and 12S. Signed-off-by: Arindam Roy <arindam.roy@intel.com>
1 parent b4a6b93 commit 88a3205

File tree

5 files changed

+255
-135
lines changed

5 files changed

+255
-135
lines changed

hypervisor/arch/x86/assign.c

Lines changed: 80 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ entry_id(struct ptdev_remapping_info *entry)
3030
{
3131
uint32_t id;
3232

33-
if (entry->type == PTDEV_INTR_INTX)
33+
if (entry->type == PTDEV_INTR_INTX) {
3434
id = entry_id_from_intx(entry->ptdev_intr_info.intx.phys_pin);
35-
else
35+
} else {
3636
id = entry_id_from_msix(entry->phys_bdf,
3737
entry->ptdev_intr_info.msi.msix_entry_index);
38+
}
3839

3940
return id;
4041
}
@@ -61,8 +62,9 @@ _lookup_entry_by_id(uint32_t id)
6162
list_for_each(pos, &ptdev_list) {
6263
entry = list_entry(pos, struct ptdev_remapping_info,
6364
entry_node);
64-
if (entry_id(entry) == id)
65+
if (entry_id(entry) == id) {
6566
return entry;
67+
}
6668
}
6769

6870
return NULL;
@@ -82,8 +84,9 @@ _lookup_entry_by_vmsi(struct vm *vm, uint16_t vbdf, int32_t index)
8284
&& (entry->vm == vm)
8385
&& (entry->virt_bdf == vbdf)
8486
&& (entry->ptdev_intr_info.msi.msix_entry_index
85-
== index))
87+
== index)) {
8688
return entry;
89+
}
8790
}
8891

8992
return NULL;
@@ -114,8 +117,9 @@ _lookup_entry_by_vintx(struct vm *vm, uint8_t vpin,
114117
if ((entry->type == PTDEV_INTR_INTX)
115118
&& (entry->vm == vm)
116119
&& (entry->ptdev_intr_info.intx.virt_pin == vpin)
117-
&& (entry->ptdev_intr_info.intx.vpin_src == vpin_src))
120+
&& (entry->ptdev_intr_info.intx.vpin_src == vpin_src)) {
118121
return entry;
122+
}
119123
}
120124

121125
return NULL;
@@ -151,13 +155,15 @@ ptdev_update_irq_handler(struct vm *vm, struct ptdev_remapping_info *entry)
151155

152156
/* VPIN_IOAPIC src means we have vioapic enabled */
153157
vioapic_get_rte(vm, entry->ptdev_intr_info.intx.virt_pin, &rte);
154-
if ((rte & IOAPIC_RTE_TRGRMOD) == IOAPIC_RTE_TRGRLVL)
158+
if ((rte & IOAPIC_RTE_TRGRMOD) == IOAPIC_RTE_TRGRLVL) {
155159
trigger_lvl = true;
160+
}
156161

157-
if (trigger_lvl)
162+
if (trigger_lvl) {
158163
update_irq_handler(phys_irq, common_dev_handler_level);
159-
else
164+
} else {
160165
update_irq_handler(phys_irq, common_handler_edge);
166+
}
161167
}
162168
/* update irq handler for PIC */
163169
if ((entry->type == PTDEV_INTR_INTX) && (phys_irq < NR_LEGACY_IRQ)
@@ -167,20 +173,22 @@ ptdev_update_irq_handler(struct vm *vm, struct ptdev_remapping_info *entry)
167173
/* VPIN_PIC src means we have vpic enabled */
168174
vpic_get_irq_trigger(vm,
169175
entry->ptdev_intr_info.intx.virt_pin, &trigger);
170-
if (trigger == LEVEL_TRIGGER)
176+
if (trigger == LEVEL_TRIGGER) {
171177
update_irq_handler(phys_irq, common_dev_handler_level);
172-
else
178+
} else {
173179
update_irq_handler(phys_irq, common_handler_edge);
180+
}
174181
}
175182
}
176183

177184
static bool ptdev_hv_owned_intx(struct vm *vm, struct ptdev_intx_info *info)
178185
{
179186
/* vm0 pin 4 (uart) is owned by hypervisor under debug version */
180-
if (is_vm0(vm) && (vm->vuart != NULL) && info->virt_pin == 4U)
187+
if (is_vm0(vm) && (vm->vuart != NULL) && info->virt_pin == 4U) {
181188
return true;
182-
else
189+
} else {
183190
return false;
191+
}
184192
}
185193

186194
static void ptdev_build_physical_msi(struct vm *vm, struct ptdev_msi_info *info,
@@ -200,8 +208,9 @@ static void ptdev_build_physical_msi(struct vm *vm, struct ptdev_msi_info *info,
200208

201209
/* get physical delivery mode */
202210
delmode = info->vmsi_data & APIC_DELMODE_MASK;
203-
if (delmode != APIC_DELMODE_FIXED && delmode != APIC_DELMODE_LOWPRIO)
211+
if (delmode != APIC_DELMODE_FIXED && delmode != APIC_DELMODE_LOWPRIO) {
204212
delmode = APIC_DELMODE_LOWPRIO;
213+
}
205214

206215
/* update physical delivery mode & vector */
207216
info->pmsi_data = info->vmsi_data;
@@ -244,8 +253,9 @@ static uint64_t ptdev_build_physical_rte(struct vm *vm,
244253
/* physical delivery mode */
245254
delmode = low & IOAPIC_RTE_DELMOD;
246255
if ((delmode != IOAPIC_RTE_DELFIXED) &&
247-
(delmode != IOAPIC_RTE_DELLOPRI))
256+
(delmode != IOAPIC_RTE_DELLOPRI)) {
248257
delmode = IOAPIC_RTE_DELLOPRI;
258+
}
249259

250260
/* update physical delivery mode, dest mode(logical) & vector */
251261
low &= ~(IOAPIC_RTE_DESTMOD |
@@ -271,8 +281,9 @@ static uint64_t ptdev_build_physical_rte(struct vm *vm,
271281
rte &= ~IOAPIC_RTE_TRGRMOD;
272282
vpic_get_irq_trigger(vm,
273283
entry->ptdev_intr_info.intx.virt_pin, &trigger);
274-
if (trigger == LEVEL_TRIGGER)
284+
if (trigger == LEVEL_TRIGGER) {
275285
rte |= IOAPIC_RTE_TRGRLVL;
286+
}
276287

277288
dev_dbg(ACRN_DBG_IRQ, "IOAPIC RTE = 0x%x:%x(P) -> 0x%x:%x(P)",
278289
physical_rte >> 32, (uint32_t)physical_rte,
@@ -339,12 +350,14 @@ remove_msix_remapping(struct vm *vm, uint16_t virt_bdf, int msix_entry_index)
339350

340351
spinlock_obtain(&ptdev_lock);
341352
entry = _lookup_entry_by_vmsi(vm, virt_bdf, msix_entry_index);
342-
if (entry == NULL)
353+
if (entry == NULL) {
343354
goto END;
355+
}
344356

345-
if (is_entry_active(entry))
357+
if (is_entry_active(entry)) {
346358
/*TODO: disable MSIX device when HV can in future */
347359
ptdev_deactivate_entry(entry);
360+
}
348361

349362
dev_dbg(ACRN_DBG_IRQ,
350363
"VM%d MSIX remove vector mapping vbdf-pbdf:0x%x-0x%x idx=%d",
@@ -420,13 +433,15 @@ static void remove_intx_remapping(struct vm *vm, uint8_t virt_pin, bool pic_pin)
420433

421434
spinlock_obtain(&ptdev_lock);
422435
entry = _lookup_entry_by_vintx(vm, virt_pin, vpin_src);
423-
if (entry == NULL)
436+
if (entry == NULL) {
424437
goto END;
438+
}
425439

426440
if (is_entry_active(entry)) {
427441
phys_irq = dev_to_irq(entry->node);
428-
if (!irq_is_gsi(phys_irq))
442+
if (!irq_is_gsi(phys_irq)) {
429443
goto END;
444+
}
430445

431446
/* disable interrupt */
432447
GSI_MASK_IRQ(phys_irq);
@@ -459,15 +474,17 @@ static void ptdev_intr_handle_irq(struct vm *vm,
459474

460475
/* VPIN_IOAPIC src means we have vioapic enabled */
461476
vioapic_get_rte(vm, entry->ptdev_intr_info.intx.virt_pin, &rte);
462-
if ((rte & IOAPIC_RTE_TRGRMOD) == IOAPIC_RTE_TRGRLVL)
477+
if ((rte & IOAPIC_RTE_TRGRMOD) == IOAPIC_RTE_TRGRLVL) {
463478
trigger_lvl = true;
479+
}
464480

465-
if (trigger_lvl)
481+
if (trigger_lvl) {
466482
vioapic_assert_irq(vm,
467483
entry->ptdev_intr_info.intx.virt_pin);
468-
else
484+
} else {
469485
vioapic_pulse_irq(vm,
470486
entry->ptdev_intr_info.intx.virt_pin);
487+
}
471488

472489
dev_dbg(ACRN_DBG_PTIRQ,
473490
"dev-assign: irq=0x%x assert vr: 0x%x vRTE=0x%x",
@@ -482,12 +499,13 @@ static void ptdev_intr_handle_irq(struct vm *vm,
482499
/* VPIN_PIC src means we have vpic enabled */
483500
vpic_get_irq_trigger(vm,
484501
entry->ptdev_intr_info.intx.virt_pin, &trigger);
485-
if (trigger == LEVEL_TRIGGER)
502+
if (trigger == LEVEL_TRIGGER) {
486503
vpic_assert_irq(vm,
487504
entry->ptdev_intr_info.intx.virt_pin);
488-
else
505+
} else {
489506
vpic_pulse_irq(vm,
490507
entry->ptdev_intr_info.intx.virt_pin);
508+
}
491509
break;
492510
}
493511
default:
@@ -501,8 +519,9 @@ void ptdev_softirq(__unused uint16_t cpu_id)
501519
struct ptdev_remapping_info *entry = ptdev_dequeue_softirq();
502520
struct vm *vm;
503521

504-
if (entry == NULL)
522+
if (entry == NULL) {
505523
break;
524+
}
506525

507526
/* skip any inactive entry */
508527
if (!is_entry_active(entry)) {
@@ -514,9 +533,9 @@ void ptdev_softirq(__unused uint16_t cpu_id)
514533
vm = entry->vm;
515534

516535
/* handle real request */
517-
if (entry->type == PTDEV_INTR_INTX)
536+
if (entry->type == PTDEV_INTR_INTX) {
518537
ptdev_intr_handle_irq(vm, entry);
519-
else {
538+
} else {
520539
/* TODO: msi destmode check required */
521540
vlapic_intr_msi(vm,
522541
entry->ptdev_intr_info.msi.vmsi_addr,
@@ -542,13 +561,15 @@ void ptdev_intx_ack(struct vm *vm, int virt_pin,
542561
int phys_pin;
543562

544563
entry = lookup_entry_by_vintx(vm, virt_pin, vpin_src);
545-
if (entry == NULL)
564+
if (entry == NULL) {
546565
return;
566+
}
547567

548568
phys_pin = entry->ptdev_intr_info.intx.phys_pin;
549569
phys_irq = pin_to_irq(phys_pin);
550-
if (!irq_is_gsi(phys_irq))
570+
if (!irq_is_gsi(phys_irq)) {
551571
return;
572+
}
552573

553574
/* NOTE: only Level trigger will process EOI/ACK and if we got here
554575
* means we have this vioapic or vpic or both enabled
@@ -651,12 +672,14 @@ static bool vpin_masked(struct vm *vm, uint8_t virt_pin,
651672
uint64_t rte;
652673

653674
vioapic_get_rte(vm, virt_pin, &rte);
654-
if ((rte & IOAPIC_RTE_INTMASK) == IOAPIC_RTE_INTMSET)
675+
if ((rte & IOAPIC_RTE_INTMASK) == IOAPIC_RTE_INTMSET) {
655676
return true;
656-
else
677+
} else {
657678
return false;
658-
} else
679+
}
680+
} else {
659681
return vpic_is_pin_mask(vm->vpic, virt_pin);
682+
}
660683
}
661684

662685
static void activate_physical_ioapic(struct vm *vm,
@@ -705,8 +728,9 @@ int ptdev_intx_pin_remap(struct vm *vm, struct ptdev_intx_info *info)
705728
*/
706729

707730
/* no remap for hypervisor owned intx */
708-
if (ptdev_hv_owned_intx(vm, info))
731+
if (ptdev_hv_owned_intx(vm, info)) {
709732
goto END;
733+
}
710734

711735
/* query if we have virt to phys mapping */
712736
entry = lookup_entry_by_vintx(vm, info->virt_pin, info->vpin_src);
@@ -726,22 +750,25 @@ int ptdev_intx_pin_remap(struct vm *vm, struct ptdev_intx_info *info)
726750
pic_ioapic_pin_map[info->virt_pin],
727751
pic_pin ? PTDEV_VPIN_IOAPIC
728752
: PTDEV_VPIN_PIC);
729-
if (entry != NULL)
753+
if (entry != NULL) {
730754
need_switch_vpin_src = true;
755+
}
731756
}
732757

733758
/* entry could be updated by above switch check */
734759
if (entry == NULL) {
735760
/* allocate entry during first unmask */
736761
if (vpin_masked(vm, info->virt_pin,
737-
info->vpin_src))
762+
info->vpin_src)) {
738763
goto END;
764+
}
739765

740766
info->phys_pin = info->virt_pin;
741767
/* fix vPIC pin to correct native IOAPIC pin */
742-
if (pic_pin)
768+
if (pic_pin) {
743769
info->phys_pin =
744770
pic_ioapic_pin_map[info->virt_pin];
771+
}
745772

746773
entry = add_intx_remapping(vm, info->virt_pin,
747774
info->phys_pin, pic_pin);
@@ -762,14 +789,16 @@ int ptdev_intx_pin_remap(struct vm *vm, struct ptdev_intx_info *info)
762789

763790
/* no need update if vpin is masked && entry is not active */
764791
if (!is_entry_active(entry) &&
765-
vpin_masked(vm, info->virt_pin, info->vpin_src))
792+
vpin_masked(vm, info->virt_pin, info->vpin_src)) {
766793
goto END;
794+
}
767795

768796
/* phys_pin from physical IOAPIC */
769797
phys_pin = entry->ptdev_intr_info.intx.phys_pin;
770798
phys_irq = pin_to_irq(phys_pin);
771-
if (!irq_is_gsi(phys_irq))
799+
if (!irq_is_gsi(phys_irq)) {
772800
goto END;
801+
}
773802

774803
/* if vpin source need switch, make sure the entry is deactived */
775804
if (need_switch_vpin_src) {
@@ -852,8 +881,9 @@ int ptdev_add_intx_remapping(struct vm *vm,
852881
}
853882

854883
entry = add_intx_remapping(vm, virt_pin, phys_pin, pic_pin);
855-
if (is_entry_invalid(entry))
884+
if (is_entry_invalid(entry)) {
856885
return -ENODEV;
886+
}
857887

858888
return 0;
859889
}
@@ -881,8 +911,9 @@ int ptdev_add_msix_remapping(struct vm *vm, uint16_t virt_bdf,
881911

882912
for (i = 0; i < vector_count; i++) {
883913
entry = add_msix_remapping(vm, virt_bdf, phys_bdf, i);
884-
if (is_entry_invalid(entry))
914+
if (is_entry_invalid(entry)) {
885915
return -ENODEV;
916+
}
886917
}
887918

888919
return 0;
@@ -914,10 +945,11 @@ static void get_entry_info(struct ptdev_remapping_info *entry, char *type,
914945
*dest = (entry->ptdev_intr_info.msi.pmsi_addr & 0xFF000U)
915946
>> 12;
916947
if ((entry->ptdev_intr_info.msi.pmsi_data &
917-
APIC_TRIGMOD_LEVEL) != 0U)
948+
APIC_TRIGMOD_LEVEL) != 0U) {
918949
*lvl_tm = true;
919-
else
950+
} else {
920951
*lvl_tm = false;
952+
}
921953
*pin = IRQ_INVALID;
922954
*vpin = -1;
923955
*bdf = entry->phys_bdf;
@@ -928,16 +960,18 @@ static void get_entry_info(struct ptdev_remapping_info *entry, char *type,
928960
uint64_t rte = 0;
929961

930962
if (entry->ptdev_intr_info.intx.vpin_src
931-
== PTDEV_VPIN_IOAPIC)
963+
== PTDEV_VPIN_IOAPIC) {
932964
(void)strcpy_s(type, 16, "IOAPIC");
933-
else
965+
} else {
934966
(void)strcpy_s(type, 16, "PIC");
967+
}
935968
ioapic_get_rte(phys_irq, &rte);
936969
*dest = ((rte >> 32) & IOAPIC_RTE_DEST) >> 24;
937-
if ((rte & IOAPIC_RTE_TRGRLVL) != 0U)
970+
if ((rte & IOAPIC_RTE_TRGRLVL) != 0U) {
938971
*lvl_tm = true;
939-
else
972+
} else {
940973
*lvl_tm = false;
974+
}
941975
*pin = entry->ptdev_intr_info.intx.phys_pin;
942976
*vpin = entry->ptdev_intr_info.intx.virt_pin;
943977
*bdf = 0;

0 commit comments

Comments
 (0)