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
[ Upstream commit 208baa3 ]

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>
  • Loading branch information
Zhongqiu Han authored and Greg Kroah-Hartman committed Apr 20, 2025
1 parent 67e85cf commit f8d28fa
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 @@ -120,6 +120,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 f8d28fa

Please sign in to comment.