Skip to contentSkip to conversation

irqchip/riscv-imsic: Fix 'imsic' dereferenced before NULL check

PATCH In review Kuan-Wei Chiu 2 participants 2 messages Aug 1, 2025 – Aug 2, 2025

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

PATCH 1/1 irqchip/riscv-imsic: Fix 'imsic' dereferenced before NULL check

Smatch reported a warning in imsic_irqdomain_init():

drivers/irqchip/irq-riscv-imsic-platform.c:317 imsic_irqdomain_init() warn: variable dereferenced before check 'imsic' (see line 311)

The variable imsic was dereferenced before being checked for NULL. To fix this, move the initialization of struct irq_domain_info after the NULL check to avoid accessing imsic prematurely.

Fixes 59422904dd98 ("irqchip/riscv-imsic: Convert to msi_create_parent_irq_domain() helper")
---
 drivers/irqchip/irq-riscv-imsic-platform.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/irqchip/irq-riscv-imsic-platform.c +6 -5
index 74a2a28f9403..04037653f274 100644
@@ -307,11 +307,6 @@ static const struct msi_parent_ops imsic_msi_parent_ops = {
 
 int imsic_irqdomain_init(void)
 {
-	struct irq_domain_info info = {
-		.fwnode		= imsic->fwnode,
-		.ops		= &imsic_base_domain_ops,
-		.host_data	= imsic,
-	};
 	struct imsic_global_config *global;
 
 	if (!imsic || !imsic->fwnode) {
@@ -324,6 +319,12 @@ int imsic_irqdomain_init(void)
 		return -ENODEV;
 	}
 
+	struct irq_domain_info info = {
+		.fwnode		= imsic->fwnode,
+		.ops		= &imsic_base_domain_ops,
+		.host_data	= imsic,
+	};
+
 	/* Create Base IRQ domain */
 	imsic->base_domain = msi_create_parent_irq_domain(&info, &imsic_msi_parent_ops);
 	if (!imsic->base_domain) {
Signature · 1 line
2.34.1
#1 lore raw
Quoted 7 lines · Kuan-Wei Chiu

Smatch reported a warning in imsic_irqdomain_init():

drivers/irqchip/irq-riscv-imsic-platform.c:317 imsic_irqdomain_init() warn: variable dereferenced before check 'imsic' (see line 311)

The variable imsic was dereferenced before being checked for NULL. To fix this, move the initialization of struct irq_domain_info after the NULL check to avoid accessing imsic prematurely.

It's fixed already w/o moving the struct into the middle of the code:

https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?h=irq/urgent

But thanks a lot for caring!

Thanks,

tglx