]> git.ipfire.org Git - thirdparty/kernel/stable.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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 2 May 2025 05:40:47 +0000 (07:40 +0200)
[ 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>
tools/power/cpupower/bench/parse.c

index e63dc11fa3a533efbe805b519831d65d55a56e3d..48e25be6e16356db34f5b633e0a07b68236828aa 100644 (file)
@@ -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");