Skip to contentSkip to conversation

staging: media: omap1: Switch to managed resources

PATCH New Amitoj Kaur Chawla 1 participant 5 messages Mar 22, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover staging: media: omap1: Switch to managed resources

Switch to managed resource functions that automatically release data when a driver detaches for the media omap1 driver.

Amitoj Kaur Chawla (4):
staging: media: omap1: Replace clk_get with devm_clk_get
staging: media: omap1: Replace kzalloc with devm_kzalloc
staging: media: omap1: Switch to devm_ioremap_resource
staging: media: omap1: Replace request_irq with devm_request_irq

 drivers/staging/media/omap1/omap1_camera.c | 68 +++++++-----------------------
 1 file changed, 16 insertions(+), 52 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/4 staging: media: omap1: Replace clk_get with devm_clk_get

devm_clk_get allocated resources get released when a driver detaches. Replace clk_get with devm_clk_get and remove corresponding data releasing function clk_put from probe and remove functions of a platform device. Also remove an unnecessary label.

This change was made with the help of the following Coccinelle semantic patch:
@platform@
identifier p, probefn, removefn;
@@
struct platform_driver p = {
.probe = probefn,
.remove = removefn,
};

@prb@
identifier platform.probefn, pdev;
expression e;
@@
probefn(struct platform_device *pdev, ...) {
...
e =
- clk_get
+ devm_clk_get
(...);
...
?- clk_put(...);
...
}
@remove depends on prb@
identifier platform.removefn;
@@
removefn(...) {
...
?- clk_put(...);
...
}

---
 drivers/staging/media/omap1/omap1_camera.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
drivers/staging/media/omap1/omap1_camera.c +4 -11
index bd721e3..bd00180 100644
@@ -1576,17 +1576,14 @@ static int omap1_cam_probe(struct platform_device *pdev)
 		goto exit;
 	}
 
-	clk = clk_get(&pdev->dev, "armper_ck");
-	if (IS_ERR(clk)) {
-		err = PTR_ERR(clk);
-		goto exit;
-	}
+	clk = devm_clk_get(&pdev->dev, "armper_ck");
+	if (IS_ERR(clk))
+		return PTR_ERR(clk);
 
 	pcdev = kzalloc(sizeof(*pcdev) + resource_size(res), GFP_KERNEL);
 	if (!pcdev) {
 		dev_err(&pdev->dev, "Could not allocate pcdev\n");
-		err = -ENOMEM;
-		goto exit_put_clk;
+		return -ENOMEM;
 	}
 
 	pcdev->res = res;
@@ -1685,8 +1682,6 @@ exit_release:
 	release_mem_region(res->start, resource_size(res));
 exit_kfree:
 	kfree(pcdev);
-exit_put_clk:
-	clk_put(clk);
 exit:
 	return err;
 }
@@ -1709,8 +1704,6 @@ static int omap1_cam_remove(struct platform_device *pdev)
 	res = pcdev->res;
 	release_mem_region(res->start, resource_size(res));
 
-	clk_put(pcdev->clk);
-
 	kfree(pcdev);
 
 	dev_info(&pdev->dev, "OMAP1 Camera Interface driver unloaded\n");
Signature · 1 line
1.9.1
#2 lore raw

PATCH 2/4 staging: media: omap1: Replace kzalloc with devm_kzalloc

In reply to Amitoj Kaur Chawla

Replace kzalloc with devm_kzalloc and consequently remove kfrees in probe and remove functions of a platform device.

As a result of this change, remove unnecessary out of memory message and an unnecessary label.

---
 drivers/staging/media/omap1/omap1_camera.c | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)
drivers/staging/media/omap1/omap1_camera.c +5 -12
index bd00180..8cc4a0a 100644
@@ -1580,11 +1580,10 @@ static int omap1_cam_probe(struct platform_device *pdev)
 	if (IS_ERR(clk))
 		return PTR_ERR(clk);
 
-	pcdev = kzalloc(sizeof(*pcdev) + resource_size(res), GFP_KERNEL);
-	if (!pcdev) {
-		dev_err(&pdev->dev, "Could not allocate pcdev\n");
+	pcdev = devm_kzalloc(&pdev->dev, sizeof(*pcdev) + resource_size(res),
+			     GFP_KERNEL);
+	if (!pcdev)
 		return -ENOMEM;
-	}
 
 	pcdev->res = res;
 	pcdev->clk = clk;
@@ -1620,10 +1619,8 @@ static int omap1_cam_probe(struct platform_device *pdev)
 	/*
 	 * Request the region.
 	 */
-	if (!request_mem_region(res->start, resource_size(res), DRIVER_NAME)) {
-		err = -EBUSY;
-		goto exit_kfree;
-	}
+	if (!request_mem_region(res->start, resource_size(res), DRIVER_NAME))
+		return -EBUSY;
 
 	base = ioremap(res->start, resource_size(res));
 	if (!base) {
@@ -1680,8 +1677,6 @@ exit_iounmap:
 	iounmap(base);
 exit_release:
 	release_mem_region(res->start, resource_size(res));
-exit_kfree:
-	kfree(pcdev);
 exit:
 	return err;
 }
@@ -1704,8 +1699,6 @@ static int omap1_cam_remove(struct platform_device *pdev)
 	res = pcdev->res;
 	release_mem_region(res->start, resource_size(res));
 
-	kfree(pcdev);
-
 	dev_info(&pdev->dev, "OMAP1 Camera Interface driver unloaded\n");
 
 	return 0;
Signature · 1 line
1.9.1
#3 lore raw

PATCH 3/4 staging: media: omap1: Switch to devm_ioremap_resource

In reply to Amitoj Kaur Chawla

Replace calls to request_mem_region and ioremap with a direct call to devm_ioremap_resource instead and modify error handling.
Move the call to platform_get_resource adjacent to the call to devm_ioremap_resource to make the connection between them more clear.

Also remove unnecessary labels, variable initialisations and release_mem_region iounmap from probe and remove functions.

---
 drivers/staging/media/omap1/omap1_camera.c | 31 ++++++------------------------
 1 file changed, 6 insertions(+), 25 deletions(-)
drivers/staging/media/omap1/omap1_camera.c +6 -25
index 8cc4a0a..c4450b4 100644
@@ -1569,9 +1569,8 @@ static int omap1_cam_probe(struct platform_device *pdev)
 	unsigned int irq;
 	int err = 0;
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	irq = platform_get_irq(pdev, 0);
-	if (!res || (int)irq <= 0) {
+	if ((int)irq <= 0) {
 		err = -ENODEV;
 		goto exit;
 	}
@@ -1585,7 +1584,6 @@ static int omap1_cam_probe(struct platform_device *pdev)
 	if (!pcdev)
 		return -ENOMEM;
 
-	pcdev->res = res;
 	pcdev->clk = clk;
 
 	pcdev->pdata = pdev->dev.platform_data;
@@ -1616,17 +1614,11 @@ static int omap1_cam_probe(struct platform_device *pdev)
 	INIT_LIST_HEAD(&pcdev->capture);
 	spin_lock_init(&pcdev->lock);
 
-	/*
-	 * Request the region.
-	 */
-	if (!request_mem_region(res->start, resource_size(res), DRIVER_NAME))
-		return -EBUSY;
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	base = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(base))
+		return PTR_ERR(base);
 
-	base = ioremap(res->start, resource_size(res));
-	if (!base) {
-		err = -ENOMEM;
-		goto exit_release;
-	}
 	pcdev->irq = irq;
 	pcdev->base = base;
 
@@ -1636,8 +1628,7 @@ static int omap1_cam_probe(struct platform_device *pdev)
 			dma_isr, (void *)pcdev, &pcdev->dma_ch);
 	if (err < 0) {
 		dev_err(&pdev->dev, "Can't request DMA for OMAP1 Camera\n");
-		err = -EBUSY;
-		goto exit_iounmap;
+		return -EBUSY;
 	}
 	dev_dbg(&pdev->dev, "got DMA channel %d\n", pcdev->dma_ch);
 
@@ -1673,10 +1664,6 @@ exit_free_irq:
 	free_irq(pcdev->irq, pcdev);
 exit_free_dma:
 	omap_free_dma(pcdev->dma_ch);
-exit_iounmap:
-	iounmap(base);
-exit_release:
-	release_mem_region(res->start, resource_size(res));
 exit:
 	return err;
 }
@@ -1686,7 +1673,6 @@ static int omap1_cam_remove(struct platform_device *pdev)
 	struct soc_camera_host *soc_host = to_soc_camera_host(&pdev->dev);
 	struct omap1_cam_dev *pcdev = container_of(soc_host,
 					struct omap1_cam_dev, soc_host);
-	struct resource *res;
 
 	free_irq(pcdev->irq, pcdev);
 
@@ -1694,11 +1680,6 @@ static int omap1_cam_remove(struct platform_device *pdev)
 
 	soc_camera_host_unregister(soc_host);
 
-	iounmap(pcdev->base);
-
-	res = pcdev->res;
-	release_mem_region(res->start, resource_size(res));
-
 	dev_info(&pdev->dev, "OMAP1 Camera Interface driver unloaded\n");
 
 	return 0;
Signature · 1 line
1.9.1
#4 lore raw

PATCH 4/4 staging: media: omap1: Replace request_irq with devm_request_irq

In reply to Amitoj Kaur Chawla

Replace request_irq with devm_request_irq to get the interrupt for device which is automatically freed on exit. Remove corresponding free_irq from probe and remove functions of a platform device.

Also, remove an unnecessary label.

---
 drivers/staging/media/omap1/omap1_camera.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/staging/media/omap1/omap1_camera.c +3 -6
index c4450b4..54b8dd2 100644
@@ -1640,7 +1640,8 @@ static int omap1_cam_probe(struct platform_device *pdev)
 	/* setup DMA autoinitialization */
 	omap_dma_link_lch(pcdev->dma_ch, pcdev->dma_ch);
 
-	err = request_irq(pcdev->irq, cam_isr, 0, DRIVER_NAME, pcdev);
+	err = devm_request_irq(&pdev->dev, pcdev->irq, cam_isr, 0, DRIVER_NAME,
+			       pcdev);
 	if (err) {
 		dev_err(&pdev->dev, "Camera interrupt register failed\n");
 		goto exit_free_dma;
@@ -1654,14 +1655,12 @@ static int omap1_cam_probe(struct platform_device *pdev)
 
 	err = soc_camera_host_register(&pcdev->soc_host);
 	if (err)
-		goto exit_free_irq;
+		return err;
 
 	dev_info(&pdev->dev, "OMAP1 Camera Interface driver loaded\n");
 
 	return 0;
 
-exit_free_irq:
-	free_irq(pcdev->irq, pcdev);
 exit_free_dma:
 	omap_free_dma(pcdev->dma_ch);
 exit:
@@ -1674,8 +1673,6 @@ static int omap1_cam_remove(struct platform_device *pdev)
 	struct omap1_cam_dev *pcdev = container_of(soc_host,
 					struct omap1_cam_dev, soc_host);
 
-	free_irq(pcdev->irq, pcdev);
-
 	omap_free_dma(pcdev->dma_ch);
 
 	soc_camera_host_unregister(soc_host);
Signature · 1 line
1.9.1