From nobody Tue Feb 10 09:28:30 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1657614260628916.2923407335896; Tue, 12 Jul 2022 01:24:20 -0700 (PDT) Received: from localhost ([::1]:48728 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oBBBq-0001LM-Kh for importer@patchew.org; Tue, 12 Jul 2022 04:24:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45142) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBAq8-0003Nx-I0 for qemu-devel@nongnu.org; Tue, 12 Jul 2022 04:01:59 -0400 Received: from mail.loongson.cn ([114.242.206.163]:57090 helo=loongson.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oBAq5-0001Qj-Np for qemu-devel@nongnu.org; Tue, 12 Jul 2022 04:01:52 -0400 Received: from localhost.localdomain (unknown [10.2.5.185]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Dx_9JdKs1i3NgYAA--.15429S4; Tue, 12 Jul 2022 16:01:35 +0800 (CST) From: Xiaojuan Yang To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, gaosong@loongson.cn, maobibo@loongson.cn, mark.cave-ayland@ilande.co.uk, mst@redhat.com, imammedo@redhat.com, ani@anisinha.ca, f4bug@amsat.org, peter.maydell@linaro.org Subject: [PATCH 2/5] hw/intc/loongarch_pch_pic: Fix coverity errors in update irq Date: Tue, 12 Jul 2022 16:01:30 +0800 Message-Id: <20220712080133.4176971-3-yangxiaojuan@loongson.cn> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220712080133.4176971-1-yangxiaojuan@loongson.cn> References: <20220712080133.4176971-1-yangxiaojuan@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf9Dx_9JdKs1i3NgYAA--.15429S4 X-Coremail-Antispam: 1UD129KBjvJXoWxJr1xtrW7JF15Kr1DCryrCrg_yoW8XFWxpF WDAF13Kr4rJFsxX3s5Cay5WFyfuFnrZr17WFZIya4xCr45ArnYk3yvqrW3ZFy8WrWrJFyj qFZ3Wa15u3WDCaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnUUvcSsGvfC2KfnxnUUI43ZEXa7xR_UUUUUUUUU== X-CM-SenderInfo: p1dqw5xldry3tdq6z05rqj20fqof0/ Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=114.242.206.163; envelope-from=yangxiaojuan@loongson.cn; helo=loongson.cn X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1657614262273100001 Content-Type: text/plain; charset="utf-8" Fix coverity errors: 1. In find_first_bit function, the 'size' argument need 'unsigned long' type, so we add the suffix 'UL' on 'size' argument when use the function. 2. In expression 1ULL << irq, left shifting by more than 63 bits has undefined behavior. And out-of-bounds access error occured when 'irq' >=3D 64. So we add a condition to avoid this. Fix coverity CID: 1489761 1489764 1489765 Signed-off-by: Xiaojuan Yang --- hw/intc/loongarch_pch_pic.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/hw/intc/loongarch_pch_pic.c b/hw/intc/loongarch_pch_pic.c index 3c9814a3b4..779a087a03 100644 --- a/hw/intc/loongarch_pch_pic.c +++ b/hw/intc/loongarch_pch_pic.c @@ -21,16 +21,20 @@ static void pch_pic_update_irq(LoongArchPCHPIC *s, uint= 64_t mask, int level) if (level) { val =3D mask & s->intirr & ~s->int_mask; if (val) { - irq =3D find_first_bit(&val, 64); - s->intisr |=3D 0x1ULL << irq; - qemu_set_irq(s->parent_irq[s->htmsi_vector[irq]], 1); + irq =3D find_first_bit(&val, 64UL); + if (irq < 64) { + s->intisr |=3D 0x1ULL << irq; + qemu_set_irq(s->parent_irq[s->htmsi_vector[irq]], 1); + } } } else { val =3D mask & s->intisr; if (val) { - irq =3D find_first_bit(&val, 64); - s->intisr &=3D ~(0x1ULL << irq); - qemu_set_irq(s->parent_irq[s->htmsi_vector[irq]], 0); + irq =3D find_first_bit(&val, 64UL); + if (irq < 64) { + s->intisr &=3D ~(0x1ULL << irq); + qemu_set_irq(s->parent_irq[s->htmsi_vector[irq]], 0); + } } } } --=20 2.31.1