lib: sbi_irqchip: fix MSI EIID gap and tail allocation logic in register_msi

Fix sbi_irqchip_register_msi() that prevented contiguous EIID allocation:

- Gap check condition was inverted: the original `h->first_hwirq -
  hwirq < num_hwirq` incorrectly set `found = true` when the gap was
  too small to fit num_hwirq entries. Correct to `>= num_hwirq` so
  allocation only proceeds when sufficient space exists between
  registered handlers.

- Tail-space check `!found && !hwirq` never triggered after iteration
  Replace with `(chip->num_hwirq - hwirq) >= num_hwirq` to correctly
  allocate if handler list is empty.

Fixes: 79e63bc834 ("irqchip: add sbi_irqchip_register_msi support")

Signed-off-by: Oza Pawandeep <pawandeep.oza@oss.qualcomm.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20260721214833.687361-7-pawandeep.oza@oss.qualcomm.com
Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
Pawandeep Oza
2026-07-22 13:20:22 +05:30
committed by Anup Patel
parent b2ead3b037
commit 7a90f41fb9
+2 -2
View File
@@ -392,7 +392,7 @@ int sbi_irqchip_register_msi(struct sbi_irqchip_device *chip, u32 num_hwirq,
if (h->first_hwirq <= hwirq && hwirq < (h->first_hwirq + h->num_hwirq)) { if (h->first_hwirq <= hwirq && hwirq < (h->first_hwirq + h->num_hwirq)) {
hwirq = h->first_hwirq + h->num_hwirq; hwirq = h->first_hwirq + h->num_hwirq;
} else if (hwirq < h->first_hwirq) { } else if (hwirq < h->first_hwirq) {
if (h->first_hwirq - hwirq < num_hwirq) { if (h->first_hwirq - hwirq >= num_hwirq) {
found = true; found = true;
break; break;
} else { } else {
@@ -400,7 +400,7 @@ int sbi_irqchip_register_msi(struct sbi_irqchip_device *chip, u32 num_hwirq,
} }
} }
} }
if (!found && !hwirq) if (!found && (chip->num_hwirq - hwirq) >= num_hwirq)
found = true; found = true;
if (!found) if (!found)
return SBI_ENOSPC; return SBI_ENOSPC;