From: Malaya Kumar Rout <mrout@redhat.com>
To: lukasz.luba@arm.com
Cc: mrout@redhat.com, malayarout91@gmail.com,
"Rafael J. Wysocki" <rafael@kernel.org>,
Len Brown <lenb@kernel.org>, Pavel Machek <pavel@kernel.org>,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] PM: EM: Fix NULL pointer dereference in em_create_pd()
Date: Thu, 15 Jan 2026 16:07:00 +0530 [thread overview]
Message-ID: <20260115103700.177997-1-mrout@redhat.com> (raw)
The get_cpu_device() function can return NULL if the CPU device is
not registered. However, the code in em_create_pd() dereferences the
returned pointer without checking for NULL, which can lead to a kernel
panic during energy model initialization.
Add a NULL check before dereferencing cpu_dev. If get_cpu_device()
returns NULL, return -ENODEV and properly clean up allocated resources
through the existing error path.
This issue was found by code inspection. The same function is correctly
handled with NULL checking in em_cpu_get() at line 555-557.
Fixes: 1bc138c62295 ("PM / EM: add support for other devices than CPUs in Energy Model")
Signed-off-by: Malaya Kumar Rout <mrout@redhat.com>
---
kernel/power/energy_model.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c
index 11af9f64aa82..3971743d7e67 100644
--- a/kernel/power/energy_model.c
+++ b/kernel/power/energy_model.c
@@ -466,6 +466,10 @@ static int em_create_pd(struct device *dev, int nr_states,
if (_is_cpu_device(dev))
for_each_cpu(cpu, cpus) {
cpu_dev = get_cpu_device(cpu);
+ if (!cpu_dev) {
+ ret = -ENODEV;
+ goto free_pd_table;
+ }
cpu_dev->em_pd = pd;
}
--
2.52.0
next reply other threads:[~2026-01-15 10:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-15 10:37 Malaya Kumar Rout [this message]
2026-01-15 20:30 ` Rafael J. Wysocki
2026-01-21 12:22 ` Lukasz Luba
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=20260115103700.177997-1-mrout@redhat.com \
--to=mrout@redhat.com \
--cc=lenb@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lukasz.luba@arm.com \
--cc=malayarout91@gmail.com \
--cc=pavel@kernel.org \
--cc=rafael@kernel.org \
/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®