mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] pm: cpupower: bench: Prevent NULL dereference on malloc failure
@ 2025-02-19 12:27 Zhongqiu Han
  2025-02-19 20:51 ` Shuah Khan
  0 siblings, 1 reply; 2+ messages in thread
From: Zhongqiu Han @ 2025-02-19 12:27 UTC (permalink / raw)
  To: trenn, shuah, jwyatt, jkacur, peng.fan
  Cc: linux-pm, linux-kernel, quic_zhonhan

If malloc returns NULL due to low memory, 'config' pointer can be NULL.
Add a check to prevent NULL dereference.

Signed-off-by: Zhongqiu Han <quic_zhonhan@quicinc.com>
---
 tools/power/cpupower/bench/parse.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/power/cpupower/bench/parse.c b/tools/power/cpupower/bench/parse.c
index 080678d9d74e..bd67c758b33a 100644
--- a/tools/power/cpupower/bench/parse.c
+++ b/tools/power/cpupower/bench/parse.c
@@ -121,6 +121,10 @@ FILE *prepare_output(const char *dirname)
 struct config *prepare_default_config()
 {
 	struct config *config = malloc(sizeof(struct config));
+	if (!config) {
+		perror("malloc");
+		return NULL;
+	}
 
 	dprintf("loading defaults\n");
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-02-19 20:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-19 12:27 [PATCH] pm: cpupower: bench: Prevent NULL dereference on malloc failure Zhongqiu Han
2025-02-19 20:51 ` Shuah Khan

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®