Skip to content

Commit

Permalink
pstore/ram: Avoid allocation and leak of platform data
Browse files Browse the repository at this point in the history
Yue Hu noticed that when parsing device tree the allocated platform data
was never freed. Since it's not used beyond the function scope, this
switches to using a stack variable instead.

Reported-by: Yue Hu <[email protected]>
Fixes: 35da609 ("pstore/ram: add Device Tree bindings")
Cc: [email protected]
Signed-off-by: Kees Cook <[email protected]>
  • Loading branch information
kees committed Jan 20, 2019
1 parent 6a4c9ab commit 5631e85
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions fs/pstore/ram.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,18 +710,15 @@ static int ramoops_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct ramoops_platform_data *pdata = dev->platform_data;
struct ramoops_platform_data pdata_local;
struct ramoops_context *cxt = &oops_cxt;
size_t dump_mem_sz;
phys_addr_t paddr;
int err = -EINVAL;

if (dev_of_node(dev) && !pdata) {
pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata) {
pr_err("cannot allocate platform data buffer\n");
err = -ENOMEM;
goto fail_out;
}
pdata = &pdata_local;
memset(pdata, 0, sizeof(*pdata));

err = ramoops_parse_dt(pdev, pdata);
if (err < 0)
Expand Down

0 comments on commit 5631e85

Please sign in to comment.