]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
pm: cpupower: bench: Prevent NULL dereference on malloc failure
authorZhongqiu Han <quic_zhonhan@quicinc.com>
Wed, 19 Feb 2025 12:27:15 +0000 (20:27 +0800)
committerShuah Khan <skhan@linuxfoundation.org>
Wed, 19 Feb 2025 20:48:08 +0000 (13:48 -0700)
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>
tools/power/cpupower/bench/parse.c

index 080678d9d74e2585533f9781392fb5eddb8f2187..bd67c758b33ac3972e3c14cfba30ea7cdbaf0794 100644 (file)
@@ -121,6 +121,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");