Skip to content

Commit

Permalink
pm: cpupower: bench: Prevent NULL dereference on malloc failure
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Zhongqiu Han authored and Shuah Khan committed Feb 19, 2025
1 parent a64dcfb commit 208baa3
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tools/power/cpupower/bench/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ FILE *prepare_output(const char *dirname)
struct config *prepare_default_config()
{
struct config *config = malloc(sizeof(struct config));
if (!config) {
perror("malloc");
return NULL;
}

dprintf("loading defaults\n");

Expand Down

0 comments on commit 208baa3

Please sign in to comment.