drivers/irqchip/irq-riscv-imsic-state.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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
On Sat, Jul 18, 2026 at 9:21 AM Pengpeng Hou <pengpeng@iscas.ac.cn> wrote:
>
> 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>
I just recalled that a similar fix was already posted a week ago
by "Haofeng Li <lihaofeng@kylinos.cn>" with patch subject
"irqchip/riscv-imsic: fix MMIO lookup OOB and NULL cleanup"
Regards,
Anup
> ---
> 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
>
On Sat, Jul 18, 2026 at 9:21 AM Pengpeng Hou <pengpeng@iscas.ac.cn> wrote:
>
> 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>
LGTM.
Reviewed-by: Anup Patel <anup@brainfault.org>
Thanks,
Anup
> ---
> 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
>
© 2016 - 2026 Red Hat, Inc.