aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuennadi Liakhovetski <g.liakhovetski@gmx.de>2012-10-10 04:18:51 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-12-20 11:35:17 -0500
commita500a185462d08f63ec3c8a0ba3185d1b84cb85d (patch)
tree05bb91a7dc144fe24c7ea7d5d36628ff76337b5c
parentf8cabc3628f047fc45c62f0c4a38a88febbf8383 (diff)
[media] sh_mobile_ceu_camera: use managed memory and resource allocations
Use managed allocations to simplify error handling and clean up paths. Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r--drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c32
1 files changed, 9 insertions, 23 deletions
diff --git a/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c b/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
index bf66cb4b63e0..27eeca15bbf0 100644
--- a/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
+++ b/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
@@ -2088,15 +2088,13 @@ static int __devinit sh_mobile_ceu_probe(struct platform_device *pdev)
2088 irq = platform_get_irq(pdev, 0); 2088 irq = platform_get_irq(pdev, 0);
2089 if (!res || (int)irq <= 0) { 2089 if (!res || (int)irq <= 0) {
2090 dev_err(&pdev->dev, "Not enough CEU platform resources.\n"); 2090 dev_err(&pdev->dev, "Not enough CEU platform resources.\n");
2091 err = -ENODEV; 2091 return -ENODEV;
2092 goto exit;
2093 } 2092 }
2094 2093
2095 pcdev = kzalloc(sizeof(*pcdev), GFP_KERNEL); 2094 pcdev = devm_kzalloc(&pdev->dev, sizeof(*pcdev), GFP_KERNEL);
2096 if (!pcdev) { 2095 if (!pcdev) {
2097 dev_err(&pdev->dev, "Could not allocate pcdev\n"); 2096 dev_err(&pdev->dev, "Could not allocate pcdev\n");
2098 err = -ENOMEM; 2097 return -ENOMEM;
2099 goto exit;
2100 } 2098 }
2101 2099
2102 INIT_LIST_HEAD(&pcdev->capture); 2100 INIT_LIST_HEAD(&pcdev->capture);
@@ -2105,19 +2103,17 @@ static int __devinit sh_mobile_ceu_probe(struct platform_device *pdev)
2105 2103
2106 pcdev->pdata = pdev->dev.platform_data; 2104 pcdev->pdata = pdev->dev.platform_data;
2107 if (!pcdev->pdata) { 2105 if (!pcdev->pdata) {
2108 err = -EINVAL;
2109 dev_err(&pdev->dev, "CEU platform data not set.\n"); 2106 dev_err(&pdev->dev, "CEU platform data not set.\n");
2110 goto exit_kfree; 2107 return -EINVAL;
2111 } 2108 }
2112 2109
2113 pcdev->max_width = pcdev->pdata->max_width ? : 2560; 2110 pcdev->max_width = pcdev->pdata->max_width ? : 2560;
2114 pcdev->max_height = pcdev->pdata->max_height ? : 1920; 2111 pcdev->max_height = pcdev->pdata->max_height ? : 1920;
2115 2112
2116 base = ioremap_nocache(res->start, resource_size(res)); 2113 base = devm_request_and_ioremap(&pdev->dev, res);
2117 if (!base) { 2114 if (!base) {
2118 err = -ENXIO;
2119 dev_err(&pdev->dev, "Unable to ioremap CEU registers.\n"); 2115 dev_err(&pdev->dev, "Unable to ioremap CEU registers.\n");
2120 goto exit_kfree; 2116 return -ENXIO;
2121 } 2117 }
2122 2118
2123 pcdev->irq = irq; 2119 pcdev->irq = irq;
@@ -2133,16 +2129,15 @@ static int __devinit sh_mobile_ceu_probe(struct platform_device *pdev)
2133 DMA_MEMORY_EXCLUSIVE); 2129 DMA_MEMORY_EXCLUSIVE);
2134 if (!err) { 2130 if (!err) {
2135 dev_err(&pdev->dev, "Unable to declare CEU memory.\n"); 2131 dev_err(&pdev->dev, "Unable to declare CEU memory.\n");
2136 err = -ENXIO; 2132 return -ENXIO;
2137 goto exit_iounmap;
2138 } 2133 }
2139 2134
2140 pcdev->video_limit = resource_size(res); 2135 pcdev->video_limit = resource_size(res);
2141 } 2136 }
2142 2137
2143 /* request irq */ 2138 /* request irq */
2144 err = request_irq(pcdev->irq, sh_mobile_ceu_irq, IRQF_DISABLED, 2139 err = devm_request_irq(&pdev->dev, pcdev->irq, sh_mobile_ceu_irq,
2145 dev_name(&pdev->dev), pcdev); 2140 IRQF_DISABLED, dev_name(&pdev->dev), pcdev);
2146 if (err) { 2141 if (err) {
2147 dev_err(&pdev->dev, "Unable to register CEU interrupt.\n"); 2142 dev_err(&pdev->dev, "Unable to register CEU interrupt.\n");
2148 goto exit_release_mem; 2143 goto exit_release_mem;
@@ -2246,15 +2241,9 @@ exit_free_ctx:
2246 vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx); 2241 vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx);
2247exit_free_clk: 2242exit_free_clk:
2248 pm_runtime_disable(&pdev->dev); 2243 pm_runtime_disable(&pdev->dev);
2249 free_irq(pcdev->irq, pcdev);
2250exit_release_mem: 2244exit_release_mem:
2251 if (platform_get_resource(pdev, IORESOURCE_MEM, 1)) 2245 if (platform_get_resource(pdev, IORESOURCE_MEM, 1))
2252 dma_release_declared_memory(&pdev->dev); 2246 dma_release_declared_memory(&pdev->dev);
2253exit_iounmap:
2254 iounmap(base);
2255exit_kfree:
2256 kfree(pcdev);
2257exit:
2258 return err; 2247 return err;
2259} 2248}
2260 2249
@@ -2267,10 +2256,8 @@ static int __devexit sh_mobile_ceu_remove(struct platform_device *pdev)
2267 2256
2268 soc_camera_host_unregister(soc_host); 2257 soc_camera_host_unregister(soc_host);
2269 pm_runtime_disable(&pdev->dev); 2258 pm_runtime_disable(&pdev->dev);
2270 free_irq(pcdev->irq, pcdev);
2271 if (platform_get_resource(pdev, IORESOURCE_MEM, 1)) 2259 if (platform_get_resource(pdev, IORESOURCE_MEM, 1))
2272 dma_release_declared_memory(&pdev->dev); 2260 dma_release_declared_memory(&pdev->dev);
2273 iounmap(pcdev->base);
2274 vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx); 2261 vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx);
2275 if (csi2_pdev && csi2_pdev->dev.driver) { 2262 if (csi2_pdev && csi2_pdev->dev.driver) {
2276 struct module *csi2_drv = csi2_pdev->dev.driver->owner; 2263 struct module *csi2_drv = csi2_pdev->dev.driver->owner;
@@ -2279,7 +2266,6 @@ static int __devexit sh_mobile_ceu_remove(struct platform_device *pdev)
2279 platform_device_put(csi2_pdev); 2266 platform_device_put(csi2_pdev);
2280 module_put(csi2_drv); 2267 module_put(csi2_drv);
2281 } 2268 }
2282 kfree(pcdev);
2283 2269
2284 return 0; 2270 return 0;
2285} 2271}