From: Lad Prabhakar Date: Wed, 4 Mar 2026 11:33:14 +0000 (+0000) Subject: irqchip/renesas-rzv2h: Clarify IRQ range definitions and tighten TINT validation X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9dc4335758c983045ab38871e2411fa1ae7e438d;p=thirdparty%2Flinux.git irqchip/renesas-rzv2h: Clarify IRQ range definitions and tighten TINT validation Introduce ICU_IRQ_LAST and ICU_TINT_LAST macros to make range boundaries explicit and reduce the chance of off-by-one errors. Extract the TINT information up front in rzv2h_icu_alloc() and validate the resulting hardware IRQ against the full TINT range [ICU_TINT_START, ICU_TINT_LAST]. [ tglx: Convert the hard to parse inverse conditions to use a simple helper macro hwirq_within() which is easy to read, less error prone and avoids a lot of typing ] Signed-off-by: Lad Prabhakar Signed-off-by: Thomas Gleixner Link: https://patch.msgid.link/20260304113317.129339-5-prabhakar.mahadev-lad.rj@bp.renesas.com --- diff --git a/drivers/irqchip/irq-renesas-rzv2h.c b/drivers/irqchip/irq-renesas-rzv2h.c index 444da7804f15b..7ebc0f9801d7b 100644 --- a/drivers/irqchip/irq-renesas-rzv2h.c +++ b/drivers/irqchip/irq-renesas-rzv2h.c @@ -25,9 +25,11 @@ /* DT "interrupts" indexes */ #define ICU_IRQ_START 1 #define ICU_IRQ_COUNT 16 -#define ICU_TINT_START (ICU_IRQ_START + ICU_IRQ_COUNT) +#define ICU_IRQ_LAST (ICU_IRQ_START + ICU_IRQ_COUNT - 1) +#define ICU_TINT_START (ICU_IRQ_LAST + 1) #define ICU_TINT_COUNT 32 -#define ICU_NUM_IRQ (ICU_TINT_START + ICU_TINT_COUNT) +#define ICU_TINT_LAST (ICU_TINT_START + ICU_TINT_COUNT - 1) +#define ICU_NUM_IRQ (ICU_TINT_LAST + 1) /* Registers */ #define ICU_NSCNT 0x00 @@ -489,6 +491,8 @@ static const struct irq_chip rzv2h_icu_chip = { IRQCHIP_SKIP_SET_WAKE, }; +#define hwirq_within(hwirq, which) ((hwirq) >= which##_START && (hwirq) <= which##_LAST) + static int rzv2h_icu_alloc(struct irq_domain *domain, unsigned int virq, unsigned int nr_irqs, void *arg) { @@ -508,11 +512,11 @@ static int rzv2h_icu_alloc(struct irq_domain *domain, unsigned int virq, unsigne * hwirq is embedded in bits 0-15. * TINT is embedded in bits 16-31. */ - if (hwirq >= ICU_TINT_START) { - tint = ICU_TINT_EXTRACT_GPIOINT(hwirq); + tint = ICU_TINT_EXTRACT_GPIOINT(hwirq); + if (tint || hwirq_within(hwirq, ICU_TINT)) { hwirq = ICU_TINT_EXTRACT_HWIRQ(hwirq); - if (hwirq < ICU_TINT_START) + if (!hwirq_within(hwirq, ICU_TINT)) return -EINVAL; }