From: Kuan-Wei Chiu <visitorckw@gmail.com>
To: anup@brainfault.org, tglx@linutronix.de,
paul.walmsley@sifive.com, palmer@dabbelt.com,
aou@eecs.berkeley.edu, alex@ghiti.fr, maz@kernel.org
Cc: jserv@ccns.ncku.edu.tw, linux-riscv@lists.infradead.org,
linux-kernel@vger.kernel.org,
Kuan-Wei Chiu <visitorckw@gmail.com>,
kernel test robot <lkp@intel.com>,
Dan Carpenter <error27@gmail.com>
Subject: [PATCH] irqchip/riscv-imsic: Fix 'imsic' dereferenced before NULL check
Date: Sat, 2 Aug 2025 01:24:59 +0800 [thread overview]
Message-ID: <20250801172459.94708-1-visitorckw@gmail.com> (raw)
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
next reply other threads:[~2025-08-01 17:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-01 17:24 Kuan-Wei Chiu [this message]
2025-08-02 22:19 ` Thomas Gleixner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250801172459.94708-1-visitorckw@gmail.com \
--to=visitorckw@gmail.com \
--cc=alex@ghiti.fr \
--cc=anup@brainfault.org \
--cc=aou@eecs.berkeley.edu \
--cc=error27@gmail.com \
--cc=jserv@ccns.ncku.edu.tw \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=lkp@intel.com \
--cc=maz@kernel.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®