Skip to content

Commit

Permalink
powerpc/pseries: Fix potential memleak in papr_get_attr()
Browse files Browse the repository at this point in the history
`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 <[email protected]>
Signed-off-by: Michael Ellerman <[email protected]>
Link: https://msgid.link/[email protected]
  • Loading branch information
ATRiiX authored and mpe committed Mar 3, 2024
1 parent 6035e7e commit cda9c0d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions arch/powerpc/platforms/pseries/papr_platform_attributes.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,12 @@ static int papr_get_attr(u64 id, struct energy_scale_attribute *esi)
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;
}
Expand Down

0 comments on commit cda9c0d

Please sign in to comment.