[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20231204180226.383745-1-prarit@redhat.com>
Date: Mon, 4 Dec 2023 13:02:26 -0500
From: Prarit Bhargava <prarit@...hat.com>
To: linux-kernel@...r.kernel.org
Cc: Prarit Bhargava <prarit@...hat.com>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org,
"H. Peter Anvin" <hpa@...or.com>,
"Peter Zijlstra (Intel)" <peterz@...radead.org>,
Wei Liu <wei.liu@...nel.org>,
Saurabh Sengar <ssengar@...ux.microsoft.com>,
Johan Hovold <johan+linaro@...nel.org>,
Michael Kelley <mikelley@...rosoft.com>,
David Malcolm <dmalcolm@...hat.com>,
David Arcari <darcari@...hat.com>,
Don Zickus <dzickus@...hat.com>
Subject: [PATCH] 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
Signed-off-by: Prarit Bhargava <prarit@...hat.com>
CC: Thomas Gleixner <tglx@...utronix.de>
CC: Ingo Molnar <mingo@...hat.com>
CC: Borislav Petkov <bp@...en8.de>
CC: Dave Hansen <dave.hansen@...ux.intel.com>
CC: x86@...nel.org
CC: "H. Peter Anvin" <hpa@...or.com>
CC: "Peter Zijlstra (Intel)" <peterz@...radead.org>
CC: Wei Liu <wei.liu@...nel.org>
CC: Prarit Bhargava <prarit@...hat.com>
CC: Saurabh Sengar <ssengar@...ux.microsoft.com>
CC: Johan Hovold <johan+linaro@...nel.org>
CC: Michael Kelley <mikelley@...rosoft.com>
CC: David Malcolm <dmalcolm@...hat.com>
CC: David Arcari <darcari@...hat.com>
CC: Don Zickus <dzickus@...hat.com>
Signed-off-by: Prarit Bhargava <prarit@...hat.com>
---
arch/x86/kernel/apic/io_apic.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
index 00da6cf6b07d..f6f19eee0339 100644
--- a/arch/x86/kernel/apic/io_apic.c
+++ b/arch/x86/kernel/apic/io_apic.c
@@ -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)
--
2.43.0
Powered by blists - more mailing lists