* [PATCH] lib: sbi_irqchip: fix device lookup by caps when first is NULL
@ 2026-07-01 18:13 David E. Garcia Porras
2026-07-16 5:59 ` Anup Patel
0 siblings, 1 reply; 2+ messages in thread
From: David E. Garcia Porras @ 2026-07-01 18:13 UTC (permalink / raw)
To: opensbi; +Cc: anup, David E. Garcia Porras
lib: sbi_irqchip: fix device lookup by caps when first is NULL
When called with first == NULL, sbi_irqchip_find_device_by_caps() should
scan the device list from the start. Instead it always returns NULL: "found"
starts false and only flips true when an entry equals "first", but no entry
ever equals NULL, so every entry hits "else continue" and nothing is checked.
This breaks MSI detection in sbi_mpxy, which calls it with first == NULL:
ms->msi_avail = !!sbi_irqchip_find_device_by_caps(SBI_IRQCHIP_CAPS_MSI, NULL);
msi_avail is therefore always false, so mpxy_write_std_attr() silently drops
the MSI attributes (MSI_ADDR_LO/HI, MSI_DATA, MSI_CONTROL) while still
returning success, and MSI-based MPXY notifications are never delivered.
Initialize "found" from "first" so a NULL "first" scans from the beginning,
and always continue in the pre-match branch so a non-NULL "first" resumes
after the given device.
Fixes: 8570b938444d ("lib: sbi_irqchip: Allow irqchip drivers advertise capabilities")
Signed-off-by: David E. Garcia Porras <david.garcia@aheadcomputing.com>
---
lib/sbi/sbi_irqchip.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/lib/sbi/sbi_irqchip.c b/lib/sbi/sbi_irqchip.c
index 6d0df02e..f1bc24ca 100644
--- a/lib/sbi/sbi_irqchip.c
+++ b/lib/sbi/sbi_irqchip.c
@@ -412,14 +412,13 @@ struct sbi_irqchip_device *sbi_irqchip_find_device_by_caps(unsigned long caps,
struct sbi_irqchip_device *first)
{
struct sbi_irqchip_device *chip;
- bool found = false;
+ bool found = (first == NULL);
sbi_list_for_each_entry(chip, &irqchip_list, node) {
if (!found) {
if (first == chip)
found = true;
- else
- continue;
+ continue;
}
if ((chip->caps & caps) == caps)
return chip;
--
2.43.0
--
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] lib: sbi_irqchip: fix device lookup by caps when first is NULL
2026-07-01 18:13 [PATCH] lib: sbi_irqchip: fix device lookup by caps when first is NULL David E. Garcia Porras
@ 2026-07-16 5:59 ` Anup Patel
0 siblings, 0 replies; 2+ messages in thread
From: Anup Patel @ 2026-07-16 5:59 UTC (permalink / raw)
To: David E. Garcia Porras; +Cc: opensbi
On Wed, Jul 1, 2026 at 11:43 PM David E. Garcia Porras
<david.garcia@aheadcomputing.com> wrote:
>
> lib: sbi_irqchip: fix device lookup by caps when first is NULL
No need to replicate the patch subject over here. I will drop it at
the time of merging.
>
> When called with first == NULL, sbi_irqchip_find_device_by_caps() should
> scan the device list from the start. Instead it always returns NULL: "found"
> starts false and only flips true when an entry equals "first", but no entry
> ever equals NULL, so every entry hits "else continue" and nothing is checked.
>
> This breaks MSI detection in sbi_mpxy, which calls it with first == NULL:
>
> ms->msi_avail = !!sbi_irqchip_find_device_by_caps(SBI_IRQCHIP_CAPS_MSI, NULL);
>
> msi_avail is therefore always false, so mpxy_write_std_attr() silently drops
> the MSI attributes (MSI_ADDR_LO/HI, MSI_DATA, MSI_CONTROL) while still
> returning success, and MSI-based MPXY notifications are never delivered.
>
> Initialize "found" from "first" so a NULL "first" scans from the beginning,
> and always continue in the pre-match branch so a non-NULL "first" resumes
> after the given device.
>
> Fixes: 8570b938444d ("lib: sbi_irqchip: Allow irqchip drivers advertise capabilities")
> Signed-off-by: David E. Garcia Porras <david.garcia@aheadcomputing.com>
LGTM.
Reviewed-by: Anup Patel <anup@brainfault.org>
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
> ---
> lib/sbi/sbi_irqchip.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/lib/sbi/sbi_irqchip.c b/lib/sbi/sbi_irqchip.c
> index 6d0df02e..f1bc24ca 100644
> --- a/lib/sbi/sbi_irqchip.c
> +++ b/lib/sbi/sbi_irqchip.c
> @@ -412,14 +412,13 @@ struct sbi_irqchip_device *sbi_irqchip_find_device_by_caps(unsigned long caps,
> struct sbi_irqchip_device *first)
> {
> struct sbi_irqchip_device *chip;
> - bool found = false;
> + bool found = (first == NULL);
>
> sbi_list_for_each_entry(chip, &irqchip_list, node) {
> if (!found) {
> if (first == chip)
> found = true;
> - else
> - continue;
> + continue;
> }
> if ((chip->caps & caps) == caps)
> return chip;
> --
> 2.43.0
>
--
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-16 5:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-01 18:13 [PATCH] lib: sbi_irqchip: fix device lookup by caps when first is NULL David E. Garcia Porras
2026-07-16 5:59 ` Anup Patel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox