powerpc/pseries: Fix potential memleak in papr_get_attr()

BugLink: https://bugs.launchpad.net/bugs/2060097

[ Upstream commit cda9c0d556283e2d4adaa9960b2dc19b16156bae ]

`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: 3c14b73454 ("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
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit d0647c3e81eff62b66d46fd4e475318cb8cb3610)
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
This commit is contained in:
Qiheng Lin
2022-12-08 21:34:49 +08:00
committed by Roxana Nicolescu
parent 7047572e8d
commit 9e6deae530
@@ -101,10 +101,12 @@ retry:
esi_buf_size = ESI_HDR_SIZE + (CURR_MAX_ESI_ATTRS * max_esi_attrs);
temp_buf = krealloc(buf, esi_buf_size, GFP_KERNEL);
if (temp_buf)
if (temp_buf) {
buf = temp_buf;
else
return -ENOMEM;
} else {
ret = -ENOMEM;
goto out_buf;
}
goto retry;
}