mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-22 21:47:22 +00:00
hv: irq: fix MISRA-C violations in irq.c and idt.h
This commit fixed following violations: - Procedure has more than one exit point: free_irq_vector/request_irq/dispatch_interrupt - goto detected: dispatch_interrupt - Pointer param should be declared pointer to const: fixup_idt - basic type declaration used: fixup_idt Tracked-On: #861 Signed-off-by: Yan, Like <like.yan@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
parent
08cf8f648c
commit
530388db30
@ -136,16 +136,11 @@ static void free_irq_vector(uint32_t irq)
|
||||
uint32_t vr;
|
||||
uint64_t rflags;
|
||||
|
||||
if (irq >= NR_IRQS) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (irq < NR_IRQS) {
|
||||
desc = &irq_desc_array[irq];
|
||||
|
||||
if ((irq < NR_LEGACY_IRQ) || (desc->vector >= VECTOR_FIXED_START)) {
|
||||
if ((irq >= NR_LEGACY_IRQ) && (desc->vector < VECTOR_FIXED_START)) {
|
||||
/* do nothing for LEGACY_IRQ and static allocated ones */
|
||||
return;
|
||||
}
|
||||
|
||||
spinlock_irqsave_obtain(&irq_alloc_spinlock, &rflags);
|
||||
vr = desc->vector;
|
||||
@ -157,6 +152,8 @@ static void free_irq_vector(uint32_t irq)
|
||||
}
|
||||
spinlock_irqrestore_release(&irq_alloc_spinlock, rflags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* There are four cases as to irq/vector allocation:
|
||||
@ -186,21 +183,21 @@ int32_t request_irq(uint32_t req_irq, irq_action_t action_fn, void *priv_data,
|
||||
struct irq_desc *desc;
|
||||
uint32_t irq, vector;
|
||||
uint64_t rflags;
|
||||
int32_t ret;
|
||||
|
||||
irq = alloc_irq_num(req_irq);
|
||||
if (irq == IRQ_INVALID) {
|
||||
pr_err("[%s] invalid irq num", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = -EINVAL;
|
||||
} else {
|
||||
vector = alloc_irq_vector(irq);
|
||||
|
||||
if (vector == VECTOR_INVALID) {
|
||||
pr_err("[%s] failed to alloc vector for irq %u",
|
||||
__func__, irq);
|
||||
free_irq_num(irq);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = -EINVAL;
|
||||
} else {
|
||||
desc = &irq_desc_array[irq];
|
||||
spinlock_irqsave_obtain(&desc->lock, &rflags);
|
||||
if (desc->action == NULL) {
|
||||
@ -208,18 +205,20 @@ int32_t request_irq(uint32_t req_irq, irq_action_t action_fn, void *priv_data,
|
||||
desc->priv_data = priv_data;
|
||||
desc->action = action_fn;
|
||||
spinlock_irqrestore_release(&desc->lock, rflags);
|
||||
|
||||
ret = (int32_t)irq;
|
||||
dev_dbg(ACRN_DBG_IRQ, "[%s] irq%d vr:0x%x", __func__, irq, desc->vector);
|
||||
} else {
|
||||
spinlock_irqrestore_release(&desc->lock, rflags);
|
||||
pr_err("%s: request irq(%u) vr(%u) failed,\
|
||||
already requested", __func__,
|
||||
|
||||
ret = -EBUSY;
|
||||
pr_err("%s: request irq(%u) vr(%u) failed, already requested", __func__,
|
||||
irq, irq_to_vector(irq));
|
||||
return -EBUSY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dev_dbg(ACRN_DBG_IRQ, "[%s] irq%d vr:0x%x",
|
||||
__func__, irq, desc->vector);
|
||||
|
||||
return (int32_t)irq;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void free_irq(uint32_t irq)
|
||||
@ -333,22 +332,12 @@ void dispatch_interrupt(const struct intr_excp_ctx *ctx)
|
||||
* < NR_IRQS, which is the irq number it bound with;
|
||||
* Any other value means there is something wrong.
|
||||
*/
|
||||
if (irq == IRQ_INVALID || irq >= NR_IRQS) {
|
||||
goto ERR;
|
||||
}
|
||||
|
||||
if (irq < NR_IRQS) {
|
||||
desc = &irq_desc_array[irq];
|
||||
per_cpu(irq_count, get_cpu_id())[irq]++;
|
||||
|
||||
if (vr != desc->vector) {
|
||||
goto ERR;
|
||||
}
|
||||
|
||||
if (bitmap_test((uint16_t)(irq & 0x3FU),
|
||||
irq_alloc_bitmap + (irq >> 6U)) == 0U) {
|
||||
/* mask irq if possible */
|
||||
goto ERR;
|
||||
}
|
||||
if (vr == desc->vector &&
|
||||
bitmap_test((uint16_t)(irq & 0x3FU), irq_alloc_bitmap + (irq >> 6U)) != 0U) {
|
||||
#ifdef PROFILING_ON
|
||||
/* Saves ctx info into irq_desc */
|
||||
desc->ctx_rip = ctx->rip;
|
||||
@ -356,10 +345,10 @@ void dispatch_interrupt(const struct intr_excp_ctx *ctx)
|
||||
desc->ctx_cs = ctx->cs;
|
||||
#endif
|
||||
handle_irq(desc);
|
||||
return;
|
||||
ERR:
|
||||
}
|
||||
} else {
|
||||
handle_spurious_interrupt(vr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void dispatch_exception(struct intr_excp_ctx *ctx)
|
||||
@ -445,13 +434,13 @@ void init_default_irqs(uint16_t cpu_id)
|
||||
}
|
||||
}
|
||||
|
||||
static inline void fixup_idt(struct host_idt_descriptor *idtd)
|
||||
static inline void fixup_idt(const struct host_idt_descriptor *idtd)
|
||||
{
|
||||
int i;
|
||||
uint32_t i;
|
||||
union idt_64_descriptor *idt_desc = (union idt_64_descriptor *)idtd->idt;
|
||||
uint32_t entry_hi_32, entry_lo_32;
|
||||
|
||||
for (i = 0; i < HOST_IDT_ENTRIES; i++) {
|
||||
for (i = 0U; i < HOST_IDT_ENTRIES; i++) {
|
||||
entry_lo_32 = idt_desc[i].fields.offset_63_32;
|
||||
entry_hi_32 = idt_desc[i].fields.rsvd;
|
||||
idt_desc[i].fields.rsvd = 0U;
|
||||
|
@ -14,9 +14,9 @@
|
||||
/* Interrupt Descriptor Table (LDT) selectors are 16 bytes on x86-64 instead of
|
||||
* 8 bytes.
|
||||
*/
|
||||
#define X64_IDT_DESC_SIZE (0x10)
|
||||
#define X64_IDT_DESC_SIZE (0x10U)
|
||||
/* Number of the HOST IDT entries */
|
||||
#define HOST_IDT_ENTRIES (0x100)
|
||||
#define HOST_IDT_ENTRIES (0x100U)
|
||||
/* Size of the IDT */
|
||||
#define HOST_IDT_SIZE (HOST_IDT_ENTRIES * X64_IDT_DESC_SIZE)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user