Skip to contentSkip to conversation

x86/ioapic: io_apic fix null dereference check

PATCH New Prarit Bhargava 1 participant 1 message Dec 4, 2023 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/ioapic: io_apic fix null dereference check

The gcc plugin -fanalyzer [1] tries to detect various patterns of incorrect behaviour. The tool reports

arch/x86/kernel/apic/io_apic.c: In function ‘ioapic_destroy_irqdomain’:
arch/x86/kernel/apic/io_apic.c:2390:12: warning: check of ‘ioapics[idx].irqdomain’ for NULL after already dereferencing it [-Wanalyzer-deref-before-check]

    |
    | 2388 |         struct fwnode_handle *fn = ioapics[idx].irqdomain->fwnode;
    |      |                               ^~
    |      |                               |
    |      |                               (1) pointer ‘ioapics[idx].irqdomain’ is dereferenced here
    | 2389 |
    | 2390 |         if (ioapics[idx].irqdomain) {
    |      |            ~
    |      |            |
    |      |            (2) pointer ‘ioapics[idx].irqdomain’ is checked for NULL here but it was already dereferenced at (1)
    |

Fix the null dereference check in ioapic_destroy_irqdomain().

[1] https://gcc.gnu.org/onlinedocs/gcc-10.1.0/gcc/Static-Analyzer-Options.html

CC Thomas Gleixner <[email protected]>
CC Ingo Molnar <[email protected]>
CC Borislav Petkov <[email protected]>
CC Dave Hansen <[email protected]>
CC "H. Peter Anvin" <[email protected]>
CC "Peter Zijlstra (Intel)" <[email protected]>
CC Wei Liu <[email protected]>
CC Prarit Bhargava <[email protected]>
CC Saurabh Sengar <[email protected]>
CC Johan Hovold <[email protected]>
CC Michael Kelley <[email protected]>
CC David Malcolm <[email protected]>
CC David Arcari <[email protected]>
CC Don Zickus <[email protected]>
---
 arch/x86/kernel/apic/io_apic.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
arch/x86/kernel/apic/io_apic.c +7 -7
index 00da6cf6b07d..f6f19eee0339 100644
@@ -2381,14 +2381,14 @@ static int mp_irqdomain_create(int ioapic)
 static void ioapic_destroy_irqdomain(int idx)
 {
 	struct ioapic_domain_cfg *cfg = &ioapics[idx].irqdomain_cfg;
-	struct fwnode_handle *fn = ioapics[idx].irqdomain->fwnode;
 
-	if (ioapics[idx].irqdomain) {
-		irq_domain_remove(ioapics[idx].irqdomain);
-		if (!cfg->dev)
-			irq_domain_free_fwnode(fn);
-		ioapics[idx].irqdomain = NULL;
-	}
+	if (!ioapics[idx].irqdomain)
+		return;
+
+	irq_domain_remove(ioapics[idx].irqdomain);
+	if (!cfg->dev)
+		irq_domain_free_fwnode(ioapics[idx].irqdomain->fwnode);
+	ioapics[idx].irqdomain = NULL;
 }
 
 void __init setup_IO_APIC(void)
Signature · 1 line
2.43.0