Commit 7282326b authored by Axel Lin's avatar Axel Lin Committed by Mark Brown

spi: fsl-lib: Fix memory leak of pinfo

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: default avatarAxel Lin <axel.lin@ingics.com>
Signed-off-by: default avatarMark Brown <broonie@linaro.org>
parent f734394d
...@@ -200,7 +200,7 @@ int of_mpc8xxx_spi_probe(struct platform_device *ofdev) ...@@ -200,7 +200,7 @@ int of_mpc8xxx_spi_probe(struct platform_device *ofdev)
const void *prop; const void *prop;
int ret = -ENOMEM; int ret = -ENOMEM;
pinfo = kzalloc(sizeof(*pinfo), GFP_KERNEL); pinfo = devm_kzalloc(&ofdev->dev, sizeof(*pinfo), GFP_KERNEL);
if (!pinfo) if (!pinfo)
return -ENOMEM; return -ENOMEM;
...@@ -215,15 +215,13 @@ int of_mpc8xxx_spi_probe(struct platform_device *ofdev) ...@@ -215,15 +215,13 @@ int of_mpc8xxx_spi_probe(struct platform_device *ofdev)
pdata->sysclk = get_brgfreq(); pdata->sysclk = get_brgfreq();
if (pdata->sysclk == -1) { if (pdata->sysclk == -1) {
pdata->sysclk = fsl_get_sys_freq(); pdata->sysclk = fsl_get_sys_freq();
if (pdata->sysclk == -1) { if (pdata->sysclk == -1)
ret = -ENODEV; return -ENODEV;
goto err;
}
} }
#else #else
ret = of_property_read_u32(np, "clock-frequency", &pdata->sysclk); ret = of_property_read_u32(np, "clock-frequency", &pdata->sysclk);
if (ret) if (ret)
goto err; return ret;
#endif #endif
prop = of_get_property(np, "mode", NULL); prop = of_get_property(np, "mode", NULL);
...@@ -237,8 +235,4 @@ int of_mpc8xxx_spi_probe(struct platform_device *ofdev) ...@@ -237,8 +235,4 @@ int of_mpc8xxx_spi_probe(struct platform_device *ofdev)
pdata->flags = SPI_CPM_MODE | SPI_CPM1; pdata->flags = SPI_CPM_MODE | SPI_CPM1;
return 0; return 0;
err:
kfree(pinfo);
return ret;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment