Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pm: cpupower: bench: Prevent NULL dereference on malloc failure

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>

authored by

Zhongqiu Han and committed by
Shuah Khan
208baa3e a64dcfb4

+4
+4
tools/power/cpupower/bench/parse.c
··· 121 121 struct config *prepare_default_config() 122 122 { 123 123 struct config *config = malloc(sizeof(struct config)); 124 + if (!config) { 125 + perror("malloc"); 126 + return NULL; 127 + } 124 128 125 129 dprintf("loading defaults\n"); 126 130