summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhongqiu Han <quic_zhonhan@quicinc.com>2025-02-19 20:27:15 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-04-20 10:15:10 +0200
commitf8d28fa305b78c5d1073b63f26db265ba8291ae1 (patch)
tree4b61e7f8adbaddcb42a1f476a3d22d3ccad24dda
parent67e85cfa951cb074dabd9ec5ef11b74e78cb5a06 (diff)
pm: cpupower: bench: Prevent NULL dereference on malloc failure
[ Upstream commit 208baa3ec9043a664d9acfb8174b332e6b17fb69 ] If malloc returns NULL due to low memory, 'config' pointer can be NULL. Add a check to prevent NULL dereference. Link: https://lore.kernel.org/r/20250219122715.3892223-1-quic_zhonhan@quicinc.com Signed-off-by: Zhongqiu Han <quic_zhonhan@quicinc.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--tools/power/cpupower/bench/parse.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/tools/power/cpupower/bench/parse.c b/tools/power/cpupower/bench/parse.c
index e63dc11fa3a5..48e25be6e163 100644
--- a/tools/power/cpupower/bench/parse.c
+++ b/tools/power/cpupower/bench/parse.c
@@ -120,6 +120,10 @@ out_dir:
struct config *prepare_default_config()
{
struct config *config = malloc(sizeof(struct config));
+ if (!config) {
+ perror("malloc");
+ return NULL;
+ }
dprintf("loading defaults\n");