Skip to content

Commit

Permalink
spi: fsl-lib: Fix memory leak of pinfo
Browse files Browse the repository at this point in the history
of_mpc8xxx_spi_probe() allocates memory for pinfo but the memory is not freed
anywhere. of_mpc8xxx_spi_probe() is called in .probe() and pinfo should be
freed in .remove(), so convert kzalloc to devm_kzalloc to fix the memory leak.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
  • Loading branch information
Axel Lin authored and Mark Brown committed Mar 21, 2014
1 parent f734394 commit 7282326
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions drivers/spi/spi-fsl-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ int of_mpc8xxx_spi_probe(struct platform_device *ofdev)
const void *prop;
int ret = -ENOMEM;

pinfo = kzalloc(sizeof(*pinfo), GFP_KERNEL);
pinfo = devm_kzalloc(&ofdev->dev, sizeof(*pinfo), GFP_KERNEL);
if (!pinfo)
return -ENOMEM;

Expand All @@ -215,15 +215,13 @@ int of_mpc8xxx_spi_probe(struct platform_device *ofdev)
pdata->sysclk = get_brgfreq();
if (pdata->sysclk == -1) {
pdata->sysclk = fsl_get_sys_freq();
if (pdata->sysclk == -1) {
ret = -ENODEV;
goto err;
}
if (pdata->sysclk == -1)
return -ENODEV;
}
#else
ret = of_property_read_u32(np, "clock-frequency", &pdata->sysclk);
if (ret)
goto err;
return ret;
#endif

prop = of_get_property(np, "mode", NULL);
Expand All @@ -237,8 +235,4 @@ int of_mpc8xxx_spi_probe(struct platform_device *ofdev)
pdata->flags = SPI_CPM_MODE | SPI_CPM1;

return 0;

err:
kfree(pinfo);
return ret;
}

0 comments on commit 7282326

Please sign in to comment.