Skip to content

Commit f8d28fa

Browse files
ZhongqiuHan-Qcomgregkh
authored andcommitted
pm: cpupower: bench: Prevent NULL dereference on malloc failure
[ 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>
1 parent 67e85cf commit f8d28fa

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)