From 255df5d8022ada847e81bc68a81e0828e693f6ba Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Thu, 23 Apr 2026 10:53:35 +0530 Subject: [PATCH] lib: sbi_irqchip: Keep the handler list in sorted order for irqchip Let's keep the handler list in sorted order for irqchip so that it is easier to allocate unused hardware interrupts based on the sorted list. Signed-off-by: Anup Patel Link: https://lore.kernel.org/r/20260423052339.356900-3-anup.patel@oss.qualcomm.com Signed-off-by: Anup Patel --- lib/sbi/sbi_irqchip.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/sbi/sbi_irqchip.c b/lib/sbi/sbi_irqchip.c index 503958e1..f9e2eb5a 100644 --- a/lib/sbi/sbi_irqchip.c +++ b/lib/sbi/sbi_irqchip.c @@ -139,7 +139,7 @@ int sbi_irqchip_register_handler(struct sbi_irqchip_device *chip, u32 first_hwirq, u32 num_hwirq, int (*callback)(u32 hwirq, void *opaque), void *priv) { - struct sbi_irqchip_handler *h; + struct sbi_irqchip_handler *h, *th, *nh; u32 i, j; int rc; @@ -162,7 +162,18 @@ int sbi_irqchip_register_handler(struct sbi_irqchip_device *chip, h->num_hwirq = num_hwirq; h->callback = callback; h->priv = priv; - sbi_list_add_tail(&h->node, &chip->handler_list); + + nh = NULL; + sbi_list_for_each_entry(th, &chip->handler_list, node) { + if (h->first_hwirq < th->first_hwirq) { + nh = th; + break; + } + } + if (nh) + sbi_list_add(&h->node, &nh->node); + else + sbi_list_add_tail(&h->node, &chip->handler_list); if (chip->hwirq_setup) { for (i = 0; i < h->num_hwirq; i++) {