From 5f0be50f3f17738aa767984f0fd1d19e06c7e188 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Mon, 27 Aug 2018 17:27:17 +0200 Subject: soc: fix memory leak in probe The consumer of nvmem_cell_read() is supposed to free the returned buffer. Use the SoC id early to simplify cleanup. Signed-off-by: Stefan Agner Acked-by: Marcel Ziswiler --- drivers/soc/fsl/soc-vf610.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/soc/fsl/soc-vf610.c b/drivers/soc/fsl/soc-vf610.c index 864bf5688f56..1db42c7442f6 100644 --- a/drivers/soc/fsl/soc-vf610.c +++ b/drivers/soc/fsl/soc-vf610.c @@ -46,6 +46,7 @@ static int vf610_soc_probe(struct platform_device *pdev) u32 rom_rev; u8 *socid1; u8 *socid2; + char *socid; int ret; info = devm_kzalloc(dev, sizeof(struct vf610_soc), GFP_KERNEL); @@ -72,11 +73,21 @@ static int vf610_soc_probe(struct platform_device *pdev) if (IS_ERR(socid2)) { dev_err(dev, "Could not read nvmem cell %ld\n", PTR_ERR(socid2)); + kfree(socid1); return PTR_ERR(socid2); } add_device_randomness(socid1, id1_len); add_device_randomness(socid2, id2_len); + socid = devm_kasprintf(dev, GFP_KERNEL, + "%02x%02x%02x%02x%02x%02x%02x%02x", + socid1[3], socid1[2], socid1[1], socid1[0], + socid2[3], socid2[2], socid2[1], socid2[0]); + + kfree(socid1); + kfree(socid2); + + soc_node = of_find_node_by_path("/soc"); if (soc_node == NULL) return -ENODEV; @@ -114,12 +125,7 @@ static int vf610_soc_probe(struct platform_device *pdev) info->soc_dev_attr->machine = devm_kasprintf(dev, GFP_KERNEL, "Freescale Vybrid"); - info->soc_dev_attr->soc_id = devm_kasprintf(dev, - GFP_KERNEL, - "%02x%02x%02x%02x%02x%02x%02x%02x", - socid1[3], socid1[2], socid1[1], - socid1[0], socid2[3], socid2[2], - socid2[1], socid2[0]); + info->soc_dev_attr->soc_id = socid; info->soc_dev_attr->family = devm_kasprintf(&pdev->dev, GFP_KERNEL, "Freescale Vybrid VF%s", soc_type); -- cgit v1.2.3