irqchip/riscv-imsic: Fix 'imsic' dereferenced before NULL check
Subsystems (3)
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.
--- drivers/irqchip/irq-riscv-imsic-platform.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/irqchip/irq-riscv-imsic-platform.c +6 -5
@@ -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
Quoted 7 lines · Kuan-Wei Chiu
Smatch reported a warning in
imsic_irqdomain_init():
drivers/irqchip/irq-riscv-imsic-platform.c:317imsic_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_infoafter 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