Skip to content

Commit 208baa3

Browse files
ZhongqiuHan-Qcomshuahkh
authored andcommitted
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/[email protected] Signed-off-by: Zhongqiu Han <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent a64dcfb commit 208baa3

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
@@ -121,6 +121,10 @@ FILE *prepare_output(const char *dirname)
121121
struct config *prepare_default_config()
122122
{
123123
struct config *config = malloc(sizeof(struct config));
124+
if (!config) {
125+
perror("malloc");
126+
return NULL;
127+
}
124128

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

0 commit comments

Comments
 (0)