From nobody Tue Feb 10 11:56:15 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.128.48 as permitted sender) client-ip=209.85.128.48; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-f48.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.128.48 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1613918106; cv=none; d=zohomail.com; s=zohoarc; b=ZxwjgjS+xFz0h3ME/eB2C7/9gn3BlVC58/Nz3aIFZwZSAR7L/UFA2NGspgMSZMWjCKfmawa4dzzvjaVZK36ucLon2OcnZE2QuSwcQQdUl5PWm6b9msoziPUaFSnqSSbazt/L6n+wsv22Zv7Yc9y26eNm+DcU3wsxq0FMUjc5Y+0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613918106; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2T22PSlc3zWYY+N/sqvIVsDv+5hyrx8dL5ATa6HQsLQ=; b=eopE/iEJGu3X0dkkkDbVBUFmzHlFa0ziKgZKJ5ig4rleE0ZVYOfjXn/F+WT9uCOPXplC9VlyM+y+O6U2TVBTTL1/tm9QFnbDi1tfeaKbSXBRvHUyGBeLBrLUjf43wNrtwo1W6c2Yjfbs0ic47riu7rLpkgEUt+2fUN1+uzZIN3g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.128.48 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by mx.zohomail.com with SMTPS id 1613918106445840.789361281914; Sun, 21 Feb 2021 06:35:06 -0800 (PST) Received: by mail-wm1-f48.google.com with SMTP id a207so12079294wmd.1 for ; Sun, 21 Feb 2021 06:35:05 -0800 (PST) Return-Path: Return-Path: Received: from localhost.localdomain (68.red-83-57-175.dynamicip.rima-tde.net. [83.57.175.68]) by smtp.gmail.com with ESMTPSA id q25sm17091796wmq.15.2021.02.21.06.35.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Feb 2021 06:35:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2T22PSlc3zWYY+N/sqvIVsDv+5hyrx8dL5ATa6HQsLQ=; b=GyWALZ+NtZQXEw1s09Ch58Ww9zTA1O7tUI2Fa5CtI+xfYe06YxGbG/sebTNkyH9FW9 Mz3sBfSMhdZ/fwnH1Jqrv+d0W/m1ZqeuKTBBxyuNRlzut4lOirjyJk+CCFdsRtQvey8M wFtOBFpFLWeoueBtb+CxgU68OButJJI+36blZlevoGKjue3M/XVFoN6vW1nSL16uRY5v 37lOMzhJEPkn3V1+G07/NqEX+lfTlbru7XwdKWNie0JcVf6SBPKCCtLEoNOCDHNU3lHK MgIz+nHOZNJWfVfeGXgQmPEAMUqNmqQXRpxPM3Z12S4qStcL1wndkuS93+mMoi9jsIV+ P0jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=2T22PSlc3zWYY+N/sqvIVsDv+5hyrx8dL5ATa6HQsLQ=; b=jPdiHb0+loxZUTJe9ioTHVv906MZcLl7sbQEqc89wGcqJV6nNZ5gNoCWTNw518E9aH RTyfQPG0PkFWCJEuiercn62cgwqsESjKDp5Q5uttPRamGgrFl4MKy2ESqmhXUeMT0EXa ao2XeptNHuS7sKczrDz4P47cwzmZmJ0Id0SZJuJ59RhKpSIo2LxVguSQmIA2kIRkzxAA eBMyJV6xDs9ChhcR6p4Yai2uJ7synOf5OGYCn1NLOc2sdKl2AhWdUs+92W1FoslhGVzO cijSadWOCJ7plJ1UoSEGlTEgbZTYh7+qmu5QBn8LSNUYpAiAZKw2W5ouoHFkLdmRIZ7a seeg== X-Gm-Message-State: AOAM5324Aj7ehEHPogfsAILBobHqoLL/xqS5ohbuHuv97h6E/mZas/h5 vJ/9x6Lo3ACPo8iEI5x4vjU= X-Google-Smtp-Source: ABdhPJyOWyvZ7IZomi4JYQATp/tuqiatJbvteY4agtIF0C2fU7dUsJmkAJsSBDIZ5aE1lUNDE9KaAw== X-Received: by 2002:a7b:c397:: with SMTP id s23mr16156014wmj.10.1613918104747; Sun, 21 Feb 2021 06:35:04 -0800 (PST) Sender: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Paul Burton , Wainer dos Santos Moschetta , Aleksandar Rikalo , Aurelien Jarno , Marcel Apfelbaum , Cleber Rosa , "Michael S. Tsirkin" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Huacai Chen , Jiaxun Yang Subject: [PULL 06/43] hw/intc/loongson_liointc: Fix per core ISR handling Date: Sun, 21 Feb 2021 15:33:55 +0100 Message-Id: <20210221143432.2468220-7-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210221143432.2468220-1-f4bug@amsat.org> References: <20210221143432.2468220-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) From: Jiaxun Yang Per core ISR is a set of 32-bit registers spaced by 8 bytes. This patch fixed calculation of it's size and also added check of alignment at reading & writing. Fixes: Coverity CID 1438965 and CID 1438967 Signed-off-by: Jiaxun Yang Reviewed-by: Huacai Chen Message-Id: <20210112012527.28927-1-jiaxun.yang@flygoat.com> [PMD: Added Coverity CID] Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/intc/loongson_liointc.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/hw/intc/loongson_liointc.c b/hw/intc/loongson_liointc.c index f823d484e08..cc11b544cb4 100644 --- a/hw/intc/loongson_liointc.c +++ b/hw/intc/loongson_liointc.c @@ -41,7 +41,7 @@ #define R_IEN_CLR 0x2c #define R_ISR_SIZE 0x8 #define R_START 0x40 -#define R_END 0x64 +#define R_END (R_START + R_ISR_SIZE * NUM_CORES) =20 struct loongson_liointc { SysBusDevice parent_obj; @@ -125,7 +125,12 @@ liointc_read(void *opaque, hwaddr addr, unsigned int s= ize) } =20 if (addr >=3D R_START && addr < R_END) { - int core =3D (addr - R_START) / R_ISR_SIZE; + hwaddr offset =3D addr - R_START; + int core =3D offset / R_ISR_SIZE; + + if (offset % R_ISR_SIZE) { + goto out; + } r =3D p->per_core_isr[core]; goto out; } @@ -169,7 +174,12 @@ liointc_write(void *opaque, hwaddr addr, } =20 if (addr >=3D R_START && addr < R_END) { - int core =3D (addr - R_START) / R_ISR_SIZE; + hwaddr offset =3D addr - R_START; + int core =3D offset / R_ISR_SIZE; + + if (offset % R_ISR_SIZE) { + goto out; + } p->per_core_isr[core] =3D value; goto out; } --=20 2.26.2