Skip to content

Commit d9bcff4

Browse files
Zhongqiu Hanjfvogel
authored andcommitted
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/[email protected] Signed-off-by: Zhongqiu Han <[email protected]> Signed-off-by: Shuah Khan <[email protected]> Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit f8d28fa305b78c5d1073b63f26db265ba8291ae1) Signed-off-by: Jack Vogel <[email protected]>
1 parent 89156d9 commit d9bcff4

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

tools/power/cpupower/bench/parse.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ FILE *prepare_output(const char *dirname)
120120
struct config *prepare_default_config()
121121
{
122122
struct config *config = malloc(sizeof(struct config));
123+
if (!config) {
124+
perror("malloc");
125+
return NULL;
126+
}
123127

124128
dprintf("loading defaults\n");
125129

0 commit comments

Comments
 (0)