irqdomain: Check virq for 0 before use in irq_dispose_mapping()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Fri, 5 Apr 2024 19:01:05 +0000 (22:01 +0300)
committerThomas Gleixner <tglx@linutronix.de>
Mon, 8 Apr 2024 10:08:58 +0000 (12:08 +0200)
It's a bit hard to read the logic since the virq is used before checking it
for 0. Rearrange the code to make it better to understand.

This, in particular, should clearly answer the question whether the caller
needs to perform this check or not, and there are plenty of places for both
variants, confirming a confusion.

Fun fact that the new code is shorter:

  Function                                     old     new   delta
  irq_dispose_mapping                          278     271      -7
  Total: Before=11625, After=11618, chg -0.06%

when compiled by GCC on Debian for x86_64.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20240405190105.3932034-1-andriy.shevchenko@linux.intel.com
kernel/irq/irqdomain.c

index 3dd1c871e0910f4c15f287122862c10e2aa5a4e4..aadc8891cc166f40632556f4903b35c940b12f33 100644 (file)
@@ -909,10 +909,11 @@ EXPORT_SYMBOL_GPL(irq_create_of_mapping);
  */
 void irq_dispose_mapping(unsigned int virq)
 {
-       struct irq_data *irq_data = irq_get_irq_data(virq);
+       struct irq_data *irq_data;
        struct irq_domain *domain;
 
-       if (!virq || !irq_data)
+       irq_data = virq ? irq_get_irq_data(virq) : NULL;
+       if (!irq_data)
                return;
 
        domain = irq_data->domain;