]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
irqchip/renesas-rzv2h: Clarify IRQ range definitions and tighten TINT validation
authorLad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Wed, 4 Mar 2026 11:33:14 +0000 (11:33 +0000)
committerThomas Gleixner <tglx@kernel.org>
Tue, 10 Mar 2026 17:34:51 +0000 (18:34 +0100)
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 <prabhakar.mahadev-lad.rj@bp.renesas.com>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Link: https://patch.msgid.link/20260304113317.129339-5-prabhakar.mahadev-lad.rj@bp.renesas.com
drivers/irqchip/irq-renesas-rzv2h.c

index 444da7804f15bdf80cb5e3c894ec8e8afb7b4878..7ebc0f9801d7b8ccb95e650279e9373fe34450af 100644 (file)
 /* 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;
        }