Skip to content

Commit cda9c0d

Browse files
ATRiiXmpe
authored andcommitted
powerpc/pseries: Fix potential memleak in papr_get_attr()
`buf` is allocated in papr_get_attr(), and krealloc() of `buf` could fail. We need to free the original `buf` in the case of failure. Fixes: 3c14b73 ("powerpc/pseries: Interface to represent PAPR firmware attributes") Signed-off-by: Qiheng Lin <linqiheng@huawei.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://msgid.link/20221208133449.16284-1-linqiheng@huawei.com
1 parent 6035e7e commit cda9c0d

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

arch/powerpc/platforms/pseries/papr_platform_attributes.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,12 @@ static int papr_get_attr(u64 id, struct energy_scale_attribute *esi)
101101
esi_buf_size = ESI_HDR_SIZE + (CURR_MAX_ESI_ATTRS * max_esi_attrs);
102102

103103
temp_buf = krealloc(buf, esi_buf_size, GFP_KERNEL);
104-
if (temp_buf)
104+
if (temp_buf) {
105105
buf = temp_buf;
106-
else
107-
return -ENOMEM;
106+
} else {
107+
ret = -ENOMEM;
108+
goto out_buf;
109+
}
108110

109111
goto retry;
110112
}

0 commit comments

Comments
 (0)