[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 2/5] hw/intc/loongarch_pch_pic: Fix bugs for update_irq functi
From: |
Xiaojuan Yang |
Subject: |
[PATCH v3 2/5] hw/intc/loongarch_pch_pic: Fix bugs for update_irq function |
Date: |
Fri, 15 Jul 2022 14:07:37 +0800 |
Fix such errors:
1. We should not use 'unsigned long' type as argument when we use
find_first_bit(), and we use ctz64() to replace find_first_bit()
to fix this bug.
2. It is not standard to use '1ULL << irq' to generate a irq mask.
So, we replace it with 'MAKE_64BIT_MASK(irq, 1)'.
Fix coverity CID: 1489761 1489764 1489765
Signed-off-by: Xiaojuan Yang <yangxiaojuan@loongson.cn>
---
hw/intc/loongarch_pch_pic.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/hw/intc/loongarch_pch_pic.c b/hw/intc/loongarch_pch_pic.c
index 3c9814a3b4..8fa64d2030 100644
--- a/hw/intc/loongarch_pch_pic.c
+++ b/hw/intc/loongarch_pch_pic.c
@@ -15,22 +15,26 @@
static void pch_pic_update_irq(LoongArchPCHPIC *s, uint64_t mask, int level)
{
- unsigned long val;
+ uint64_t val;
int irq;
if (level) {
val = mask & s->intirr & ~s->int_mask;
if (val) {
- irq = find_first_bit(&val, 64);
- s->intisr |= 0x1ULL << irq;
- qemu_set_irq(s->parent_irq[s->htmsi_vector[irq]], 1);
+ irq = ctz64(val);
+ if (irq < 64) {
+ s->intisr |= MAKE_64BIT_MASK(irq, 1);
+ qemu_set_irq(s->parent_irq[s->htmsi_vector[irq]], 1);
+ }
}
} else {
val = mask & s->intisr;
if (val) {
- irq = find_first_bit(&val, 64);
- s->intisr &= ~(0x1ULL << irq);
- qemu_set_irq(s->parent_irq[s->htmsi_vector[irq]], 0);
+ irq = ctz64(val);
+ if (irq < 64) {
+ s->intisr &= ~(MAKE_64BIT_MASK(irq, 1));
+ qemu_set_irq(s->parent_irq[s->htmsi_vector[irq]], 0);
+ }
}
}
}
--
2.31.1