mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] irqchip/riscv-imsic: Fix MMIO regset lookup loop bound
@ 2026-09-04 14:31 GUO Ren (XuanTie)
  2026-09-04 14:38 ` Guo Ren
  0 siblings, 1 reply; 5+ messages in thread
From: GUO Ren (XuanTie) @ 2026-09-04 14:31 UTC (permalink / raw)
  To: Anup Patel, Thomas Gleixner, Radu Rendec, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Björn Töpel
  Cc: Anup Patel, linux-riscv, linux-kernel, stable, GUO Ren (XuanTie)

The nr_mmios is the number of entries in the MMIO resource array, while
j is the index used to iterate over the array. Testing nr_mmios directly
makes the loop condition permanently true whenever at least one MMIO
region exists.

So, change
  for (j = 0; nr_mmios; j++) {
to
  for (j = 0; j < nr_mmios; j++) {

Fixes: 21a8f8a0eb35 ("irqchip: Add RISC-V incoming MSI controller early driver")
Cc: stable@vger.kernel.org
Signed-off-by: GUO Ren (XuanTie) <guoren@kernel.org>
---
This patch fixes an out-of-bounds access in the RISC-V IMSIC MMIO
resource lookup.
---
 drivers/irqchip/irq-riscv-imsic-state.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-riscv-imsic-state.c
index b8d1bbbf42f7..008dfcf343e5 100644
--- a/drivers/irqchip/irq-riscv-imsic-state.c
+++ b/drivers/irqchip/irq-riscv-imsic-state.c
@@ -896,7 +896,7 @@ int __init imsic_setup_state(struct fwnode_handle *fwnode, void *opaque)
 		index = nr_mmios;
 		reloff = i * BIT(global->guest_index_bits) *
 			 IMSIC_MMIO_PAGE_SZ;
-		for (j = 0; nr_mmios; j++) {
+		for (j = 0; j < nr_mmios; j++) {
 			if (reloff < resource_size(&mmios[j])) {
 				index = j;
 				break;

---
base-commit: bc35965f6940a9bf834d54187b6088b8eb09206d
change-id: 20260904-nr_mmios-868e369de25b

Best regards,
--  
GUO Ren (XuanTie) <guoren@kernel.org>


^ permalink raw reply	[flat|nested] 5+ messages in thread
* [PATCH] irqchip/riscv-imsic: Fix MMIO regset lookup loop bound
@ 2026-07-18  3:51 Pengpeng Hou
  2026-07-20  3:31 ` Anup Patel
  2026-07-20  3:44 ` Anup Patel
  0 siblings, 2 replies; 5+ messages in thread
From: Pengpeng Hou @ 2026-07-18  3:51 UTC (permalink / raw)
  To: Anup Patel
  Cc: Pengpeng Hou, Thomas Gleixner, Paul Walmsley, Palmer Dabbelt,
	Albert Ou, Alexandre Ghiti, Björn Töpel, linux-riscv,
	linux-kernel

nr_mmios is the number of elements in the MMIO resource arrays, while j is
the index that advances through them. The loop currently tests the nonzero
count on every iteration. If no region contains reloff, it reads past mmios
before reaching the existing not-found check.

Compare j with nr_mmios. This preserves successful lookups and lets the
not-found path handle an offset beyond the listed regions.

Fixes: 21a8f8a0eb35 ("irqchip: Add RISC-V incoming MSI controller early driver")
Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
---
 drivers/irqchip/irq-riscv-imsic-state.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-riscv-imsic-state.c
index b8d1bbbf42f73..008dfcf343e53 100644
--- a/drivers/irqchip/irq-riscv-imsic-state.c
+++ b/drivers/irqchip/irq-riscv-imsic-state.c
@@ -896,7 +896,7 @@ int __init imsic_setup_state(struct fwnode_handle *fwnode, void *opaque)
 		index = nr_mmios;
 		reloff = i * BIT(global->guest_index_bits) *
 			 IMSIC_MMIO_PAGE_SZ;
-		for (j = 0; nr_mmios; j++) {
+		for (j = 0; j < nr_mmios; j++) {
 			if (reloff < resource_size(&mmios[j])) {
 				index = j;
 				break;
-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-09-04 14:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-04 14:31 [PATCH] irqchip/riscv-imsic: Fix MMIO regset lookup loop bound GUO Ren (XuanTie)
2026-09-04 14:38 ` Guo Ren
  -- strict thread matches above, loose matches on Subject: below --
2026-07-18  3:51 Pengpeng Hou
2026-07-20  3:31 ` Anup Patel
2026-07-20  3:44 ` Anup Patel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®