* [PATCH] irqchip/riscv-imsic: Fix 'imsic' dereferenced before NULL check
@ 2025-08-01 17:24 Kuan-Wei Chiu
2025-08-02 22:19 ` Thomas Gleixner
0 siblings, 1 reply; 2+ messages in thread
From: Kuan-Wei Chiu @ 2025-08-01 17:24 UTC (permalink / raw)
To: anup, tglx, paul.walmsley, palmer, aou, alex, maz
Cc: jserv, linux-riscv, linux-kernel, Kuan-Wei Chiu,
kernel test robot, Dan Carpenter
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")
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <error27@gmail.com>
Closes: https://lore.kernel.org/r/202507311953.NFVZkr0a-lkp@intel.com/
Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
---
drivers/irqchip/irq-riscv-imsic-platform.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/drivers/irqchip/irq-riscv-imsic-platform.c b/drivers/irqchip/irq-riscv-imsic-platform.c
index 74a2a28f9403..04037653f274 100644
--- a/drivers/irqchip/irq-riscv-imsic-platform.c
+++ b/drivers/irqchip/irq-riscv-imsic-platform.c
@@ -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) {
--
2.34.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] irqchip/riscv-imsic: Fix 'imsic' dereferenced before NULL check
2025-08-01 17:24 [PATCH] irqchip/riscv-imsic: Fix 'imsic' dereferenced before NULL check Kuan-Wei Chiu
@ 2025-08-02 22:19 ` Thomas Gleixner
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Gleixner @ 2025-08-02 22:19 UTC (permalink / raw)
To: Kuan-Wei Chiu, anup, paul.walmsley, palmer, aou, alex, maz
Cc: jserv, linux-riscv, linux-kernel, Kuan-Wei Chiu,
kernel test robot, Dan Carpenter
On Sat, Aug 02 2025 at 01:24, Kuan-Wei Chiu wrote:
> 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
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-08-02 22:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-01 17:24 [PATCH] irqchip/riscv-imsic: Fix 'imsic' dereferenced before NULL check Kuan-Wei Chiu
2025-08-02 22:19 ` Thomas Gleixner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).