Skip to contentSkip to conversation

irqdomain: Check virq for 0 before use in irq_dispose_mapping()

PATCH Superseded Andy Shevchenko 1 participant 2 messages Aug 22, 2023 – Sep 19, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 irqdomain: Check virq for 0 before use in irq_dispose_mapping()

It's a bit hard to read the logic since we use virq before checking it for 0. Rearrange the code to make it better to understand.

This, in particular, should clearly answer the question whether caller need to perform this check or not, and we have plenty 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.

---
 kernel/irq/irqdomain.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/irq/irqdomain.c +3 -2
index 0bdef4fe925b..26f1be63d622 100644
@@ -903,10 +903,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;
Signature · 1 line
2.40.0.1.gaa8946217a0b
#1 lore raw
Quoted 7 lines · Andy Shevchenko

It's a bit hard to read the logic since we use virq before checking it for 0. Rearrange the code to make it better to understand.

This, in particular, should clearly answer the question whether caller need to perform this check or not, and we have plenty places for both variants, confirming a confusion.

Quoted 7 lines

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.

Any comment on this?

Signature · 2 lines
With Best Regards,
Andy Shevchenko