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:
Yan, Like 2018-12-18 21:59:41 +08:00 committed by wenlingz
parent 08cf8f648c
commit 530388db30
2 changed files with 64 additions and 75 deletions

View File

@ -136,26 +136,23 @@ static void free_irq_vector(uint32_t irq)
uint32_t vr; uint32_t vr;
uint64_t rflags; uint64_t rflags;
if (irq >= NR_IRQS) { if (irq < NR_IRQS) {
return; desc = &irq_desc_array[irq];
if ((irq >= NR_LEGACY_IRQ) && (desc->vector < VECTOR_FIXED_START)) {
/* do nothing for LEGACY_IRQ and static allocated ones */
spinlock_irqsave_obtain(&irq_alloc_spinlock, &rflags);
vr = desc->vector;
desc->vector = VECTOR_INVALID;
vr &= NR_MAX_VECTOR;
if (vector_to_irq[vr] == irq) {
vector_to_irq[vr] = IRQ_INVALID;
}
spinlock_irqrestore_release(&irq_alloc_spinlock, rflags);
}
} }
desc = &irq_desc_array[irq];
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;
desc->vector = VECTOR_INVALID;
vr &= NR_MAX_VECTOR;
if (vector_to_irq[vr] == irq) {
vector_to_irq[vr] = IRQ_INVALID;
}
spinlock_irqrestore_release(&irq_alloc_spinlock, rflags);
} }
/* /*
@ -186,40 +183,42 @@ int32_t request_irq(uint32_t req_irq, irq_action_t action_fn, void *priv_data,
struct irq_desc *desc; struct irq_desc *desc;
uint32_t irq, vector; uint32_t irq, vector;
uint64_t rflags; uint64_t rflags;
int32_t ret;
irq = alloc_irq_num(req_irq); irq = alloc_irq_num(req_irq);
if (irq == IRQ_INVALID) { if (irq == IRQ_INVALID) {
pr_err("[%s] invalid irq num", __func__); pr_err("[%s] invalid irq num", __func__);
return -EINVAL; ret = -EINVAL;
}
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;
}
desc = &irq_desc_array[irq];
spinlock_irqsave_obtain(&desc->lock, &rflags);
if (desc->action == NULL) {
desc->flags = flags;
desc->priv_data = priv_data;
desc->action = action_fn;
spinlock_irqrestore_release(&desc->lock, rflags);
} else { } else {
spinlock_irqrestore_release(&desc->lock, rflags); vector = alloc_irq_vector(irq);
pr_err("%s: request irq(%u) vr(%u) failed,\
already requested", __func__, if (vector == VECTOR_INVALID) {
irq, irq_to_vector(irq)); pr_err("[%s] failed to alloc vector for irq %u",
return -EBUSY; __func__, irq);
free_irq_num(irq);
ret = -EINVAL;
} else {
desc = &irq_desc_array[irq];
spinlock_irqsave_obtain(&desc->lock, &rflags);
if (desc->action == NULL) {
desc->flags = flags;
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);
ret = -EBUSY;
pr_err("%s: request irq(%u) vr(%u) failed, already requested", __func__,
irq, irq_to_vector(irq));
}
}
} }
dev_dbg(ACRN_DBG_IRQ, "[%s] irq%d vr:0x%x", return ret;
__func__, irq, desc->vector);
return (int32_t)irq;
} }
void free_irq(uint32_t irq) void free_irq(uint32_t irq)
@ -333,33 +332,23 @@ void dispatch_interrupt(const struct intr_excp_ctx *ctx)
* < NR_IRQS, which is the irq number it bound with; * < NR_IRQS, which is the irq number it bound with;
* Any other value means there is something wrong. * Any other value means there is something wrong.
*/ */
if (irq == IRQ_INVALID || irq >= NR_IRQS) { if (irq < NR_IRQS) {
goto ERR; desc = &irq_desc_array[irq];
} per_cpu(irq_count, get_cpu_id())[irq]++;
desc = &irq_desc_array[irq]; if (vr == desc->vector &&
per_cpu(irq_count, get_cpu_id())[irq]++; bitmap_test((uint16_t)(irq & 0x3FU), irq_alloc_bitmap + (irq >> 6U)) != 0U) {
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;
}
#ifdef PROFILING_ON #ifdef PROFILING_ON
/* Saves ctx info into irq_desc */ /* Saves ctx info into irq_desc */
desc->ctx_rip = ctx->rip; desc->ctx_rip = ctx->rip;
desc->ctx_rflags = ctx->rflags; desc->ctx_rflags = ctx->rflags;
desc->ctx_cs = ctx->cs; desc->ctx_cs = ctx->cs;
#endif #endif
handle_irq(desc); handle_irq(desc);
return; }
ERR: } else {
handle_spurious_interrupt(vr); handle_spurious_interrupt(vr);
return; }
} }
void dispatch_exception(struct intr_excp_ctx *ctx) 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; union idt_64_descriptor *idt_desc = (union idt_64_descriptor *)idtd->idt;
uint32_t entry_hi_32, entry_lo_32; 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_lo_32 = idt_desc[i].fields.offset_63_32;
entry_hi_32 = idt_desc[i].fields.rsvd; entry_hi_32 = idt_desc[i].fields.rsvd;
idt_desc[i].fields.rsvd = 0U; idt_desc[i].fields.rsvd = 0U;

View File

@ -14,9 +14,9 @@
/* Interrupt Descriptor Table (LDT) selectors are 16 bytes on x86-64 instead of /* Interrupt Descriptor Table (LDT) selectors are 16 bytes on x86-64 instead of
* 8 bytes. * 8 bytes.
*/ */
#define X64_IDT_DESC_SIZE (0x10) #define X64_IDT_DESC_SIZE (0x10U)
/* Number of the HOST IDT entries */ /* Number of the HOST IDT entries */
#define HOST_IDT_ENTRIES (0x100) #define HOST_IDT_ENTRIES (0x100U)
/* Size of the IDT */ /* Size of the IDT */
#define HOST_IDT_SIZE (HOST_IDT_ENTRIES * X64_IDT_DESC_SIZE) #define HOST_IDT_SIZE (HOST_IDT_ENTRIES * X64_IDT_DESC_SIZE)