From: Guennadi Liakhovetski Date: Sat, 3 May 2014 16:05:08 +0000 (-0300) Subject: [media] V4L: soc-camera: explicitly free allocated managed memory on error X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=057c2a2ef576a21968e838194b8b9d3b6b106769;p=GitHub%2FLineageOS%2FG12%2Fandroid_kernel_amlogic_linux-4.9.git [media] V4L: soc-camera: explicitly free allocated managed memory on error devm_kzalloc() allocations are freed when the device is unbound. But if a certain path fails and the allocated memory cannot be used anyway it is better to free it explicitly immediately. This patch does exactly this if asynchronous group probing in scan_async_group() fails after memory has been allocated. Signed-off-by: Guennadi Liakhovetski Signed-off-by: Mauro Carvalho Chehab --- diff --git a/drivers/media/platform/soc_camera/soc_camera.c b/drivers/media/platform/soc_camera/soc_camera.c index 7fec8cdaf095..dc626b9a177d 100644 --- a/drivers/media/platform/soc_camera/soc_camera.c +++ b/drivers/media/platform/soc_camera/soc_camera.c @@ -1524,14 +1524,14 @@ static int scan_async_group(struct soc_camera_host *ici, ret = soc_camera_dyn_pdev(&sdesc, sasc); if (ret < 0) - return ret; + goto eallocpdev; sasc->sensor = &sasd->asd; icd = soc_camera_add_pdev(sasc); if (!icd) { - platform_device_put(sasc->pdev); - return -ENOMEM; + ret = -ENOMEM; + goto eaddpdev; } sasc->notifier.subdevs = asd; @@ -1559,7 +1559,11 @@ static int scan_async_group(struct soc_camera_host *ici, v4l2_clk_unregister(icd->clk); eclkreg: icd->clk = NULL; - platform_device_unregister(sasc->pdev); + platform_device_del(sasc->pdev); +eaddpdev: + platform_device_put(sasc->pdev); +eallocpdev: + devm_kfree(ici->v4l2_dev.dev, sasc); dev_err(ici->v4l2_dev.dev, "group probe failed: %d\n", ret); return ret;