All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] staging: most: hdm-dim2: Use devm_* functions
@ 2016-02-18 14:41 Amitoj Kaur Chawla
  2016-02-18 14:41 ` [PATCH 1/4] staging: most: hdm-dim2: Replace kzalloc with devm_kzalloc Amitoj Kaur Chawla
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Amitoj Kaur Chawla @ 2016-02-18 14:41 UTC (permalink / raw)
  To: outreachy-kernel

Devm_ functions allocate memory that is released when a driver
detaches. Replace kzalloc, ioremap and request_irq with their devm_*
counterparts in the probe function of a platform device which were
originally freed in the remove function.

Also, unnecessary labels have been removed, an unnecessary
platform_set_drvdata has been removed as well as switching from pr_err
to dev_err.

Amitoj Kaur Chawla (4):
  staging: most: hdm-dim2: Replace kzalloc with devm_kzalloc
  staging: most: hdm-dim2: Switch to devm_ioremap_resource()
  staging: most: hdm-dim2: Replace request_irq with devm_request_irq
  staging: most: hdm-dim2: Replace pr_err with dev_err

 drivers/staging/most/hdm-dim2/dim2_hdm.c | 58 +++++++-------------------------
 1 file changed, 12 insertions(+), 46 deletions(-)

-- 
1.9.1



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] staging: most: hdm-dim2: Replace kzalloc with devm_kzalloc
  2016-02-18 14:41 [PATCH 0/4] staging: most: hdm-dim2: Use devm_* functions Amitoj Kaur Chawla
@ 2016-02-18 14:41 ` Amitoj Kaur Chawla
  2016-02-18 14:41 ` [PATCH 2/4] staging: most: hdm-dim2: Switch to devm_ioremap_resource() Amitoj Kaur Chawla
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Amitoj Kaur Chawla @ 2016-02-18 14:41 UTC (permalink / raw)
  To: outreachy-kernel

Devm_ functions allocate memory that is released when a driver detaches. 
Replace kzalloc with devm_kzalloc and remove corresponding
kfrees from probe and remove functions of a platform
device.

Also, an unnecessary label has been removed.

Signed-off-by: Amitoj Kaur Chawla <amitoj1606@gmail.com>
---
 drivers/staging/most/hdm-dim2/dim2_hdm.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/most/hdm-dim2/dim2_hdm.c b/drivers/staging/most/hdm-dim2/dim2_hdm.c
index 6296aa5..97db334 100644
--- a/drivers/staging/most/hdm-dim2/dim2_hdm.c
+++ b/drivers/staging/most/hdm-dim2/dim2_hdm.c
@@ -736,7 +736,7 @@ static int dim2_probe(struct platform_device *pdev)
 	int ret, i;
 	struct kobject *kobj;
 
-	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+	dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
 	if (!dev)
 		return -ENOMEM;
 
@@ -750,13 +750,13 @@ static int dim2_probe(struct platform_device *pdev)
 	if (!res) {
 		pr_err("no memory region defined\n");
 		ret = -ENOENT;
-		goto err_free_dev;
+		return ret;
 	}
 
 	if (!request_mem_region(res->start, resource_size(res), pdev->name)) {
 		pr_err("failed to request mem region\n");
 		ret = -EBUSY;
-		goto err_free_dev;
+		return ret;
 	}
 
 	dev->io_base = ioremap(res->start, resource_size(res));
@@ -862,9 +862,7 @@ err_unmap_io:
 	iounmap(dev->io_base);
 err_release_mem:
 	release_mem_region(res->start, resource_size(res));
-err_free_dev:
 #endif
-	kfree(dev);
 
 	return ret;
 }
@@ -897,7 +895,6 @@ static int dim2_remove(struct platform_device *pdev)
 	iounmap(dev->io_base);
 	release_mem_region(res->start, resource_size(res));
 #endif
-	kfree(dev);
 	platform_set_drvdata(pdev, NULL);
 
 	/*
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/4] staging: most: hdm-dim2: Switch to devm_ioremap_resource()
  2016-02-18 14:41 [PATCH 0/4] staging: most: hdm-dim2: Use devm_* functions Amitoj Kaur Chawla
  2016-02-18 14:41 ` [PATCH 1/4] staging: most: hdm-dim2: Replace kzalloc with devm_kzalloc Amitoj Kaur Chawla
@ 2016-02-18 14:41 ` Amitoj Kaur Chawla
  2016-02-18 14:42 ` [PATCH 3/4] staging: most: hdm-dim2: Replace request_irq with devm_request_irq Amitoj Kaur Chawla
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Amitoj Kaur Chawla @ 2016-02-18 14:41 UTC (permalink / raw)
  To: outreachy-kernel

Devm_ functions allocate memory that is released when a driver
detaches. Replace request_mem_region and ioremap with 
devm_ioremap_resource and remove corresponding freeing functions
release_mem_region and iounmap from probe and remove functions of a
platform device.

Also, an unnecessary platform_set_drvdata() has been removed since the
driver core clears the driver data to NULL after device release or on
probe failure. There is no need to manually clear the device driver
data to NULL.

Lastly, unnecessary labels have been removed.

Signed-off-by: Amitoj Kaur Chawla <amitoj1606@gmail.com>
---
 drivers/staging/most/hdm-dim2/dim2_hdm.c | 33 +++++---------------------------
 1 file changed, 5 insertions(+), 28 deletions(-)

diff --git a/drivers/staging/most/hdm-dim2/dim2_hdm.c b/drivers/staging/most/hdm-dim2/dim2_hdm.c
index 97db334..708b998 100644
--- a/drivers/staging/most/hdm-dim2/dim2_hdm.c
+++ b/drivers/staging/most/hdm-dim2/dim2_hdm.c
@@ -747,29 +747,14 @@ static int dim2_probe(struct platform_device *pdev)
 	test_dev = dev;
 #else
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res) {
-		pr_err("no memory region defined\n");
-		ret = -ENOENT;
-		return ret;
-	}
-
-	if (!request_mem_region(res->start, resource_size(res), pdev->name)) {
-		pr_err("failed to request mem region\n");
-		ret = -EBUSY;
-		return ret;
-	}
-
-	dev->io_base = ioremap(res->start, resource_size(res));
-	if (!dev->io_base) {
-		pr_err("failed to ioremap\n");
-		ret = -ENOMEM;
-		goto err_release_mem;
-	}
+	dev->io_base = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(dev->io_base))
+		return PTR_ERR(dev->io_base);
 
 	ret = platform_get_irq(pdev, 0);
 	if (ret < 0) {
 		pr_err("failed to get irq\n");
-		goto err_unmap_io;
+		return -ENODEV;
 	}
 	dev->irq_ahb0 = ret;
 
@@ -777,7 +762,7 @@ static int dim2_probe(struct platform_device *pdev)
 	if (ret) {
 		pr_err("failed to request IRQ: %d, err: %d\n",
 		       dev->irq_ahb0, ret);
-		goto err_unmap_io;
+		return ret;
 	}
 #endif
 	init_waitqueue_head(&dev->netinfo_waitq);
@@ -858,10 +843,6 @@ err_stop_thread:
 err_free_irq:
 #if !defined(ENABLE_HDM_TEST)
 	free_irq(dev->irq_ahb0, dev);
-err_unmap_io:
-	iounmap(dev->io_base);
-err_release_mem:
-	release_mem_region(res->start, resource_size(res));
 #endif
 
 	return ret;
@@ -876,7 +857,6 @@ err_release_mem:
 static int dim2_remove(struct platform_device *pdev)
 {
 	struct dim2_hdm *dev = platform_get_drvdata(pdev);
-	struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	struct dim2_platform_data *pdata = pdev->dev.platform_data;
 	unsigned long flags;
 
@@ -892,10 +872,7 @@ static int dim2_remove(struct platform_device *pdev)
 	kthread_stop(dev->netinfo_task);
 #if !defined(ENABLE_HDM_TEST)
 	free_irq(dev->irq_ahb0, dev);
-	iounmap(dev->io_base);
-	release_mem_region(res->start, resource_size(res));
 #endif
-	platform_set_drvdata(pdev, NULL);
 
 	/*
 	 * break link to local platform_device_id struct
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/4] staging: most: hdm-dim2: Replace request_irq with devm_request_irq
  2016-02-18 14:41 [PATCH 0/4] staging: most: hdm-dim2: Use devm_* functions Amitoj Kaur Chawla
  2016-02-18 14:41 ` [PATCH 1/4] staging: most: hdm-dim2: Replace kzalloc with devm_kzalloc Amitoj Kaur Chawla
  2016-02-18 14:41 ` [PATCH 2/4] staging: most: hdm-dim2: Switch to devm_ioremap_resource() Amitoj Kaur Chawla
@ 2016-02-18 14:42 ` Amitoj Kaur Chawla
  2016-02-18 14:42 ` [PATCH 4/4] staging: most: hdm-dim2: Replace pr_err with dev_err Amitoj Kaur Chawla
  2016-02-28 13:44 ` [Outreachy kernel] [PATCH 0/4] staging: most: hdm-dim2: Use devm_* functions Tejun Heo
  4 siblings, 0 replies; 6+ messages in thread
From: Amitoj Kaur Chawla @ 2016-02-18 14:42 UTC (permalink / raw)
  To: outreachy-kernel

Devm_ functions allocate memory that is released when a driver
detaches. 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.

Signed-off-by: Amitoj Kaur Chawla <amitoj1606@gmail.com>
---
 drivers/staging/most/hdm-dim2/dim2_hdm.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/most/hdm-dim2/dim2_hdm.c b/drivers/staging/most/hdm-dim2/dim2_hdm.c
index 708b998..c9cc9c1 100644
--- a/drivers/staging/most/hdm-dim2/dim2_hdm.c
+++ b/drivers/staging/most/hdm-dim2/dim2_hdm.c
@@ -758,7 +758,8 @@ static int dim2_probe(struct platform_device *pdev)
 	}
 	dev->irq_ahb0 = ret;
 
-	ret = request_irq(dev->irq_ahb0, dim2_ahb_isr, 0, "mlb_ahb0", dev);
+	ret = devm_request_irq(&pdev->dev, dev->irq_ahb0, dim2_ahb_isr, 0,
+			       "mlb_ahb0", dev);
 	if (ret) {
 		pr_err("failed to request IRQ: %d, err: %d\n",
 		       dev->irq_ahb0, ret);
@@ -769,10 +770,8 @@ static int dim2_probe(struct platform_device *pdev)
 	dev->deliver_netinfo = 0;
 	dev->netinfo_task = kthread_run(&deliver_netinfo_thread, (void *)dev,
 					"dim2_netinfo");
-	if (IS_ERR(dev->netinfo_task)) {
+	if (IS_ERR(dev->netinfo_task))
 		ret = PTR_ERR(dev->netinfo_task);
-		goto err_free_irq;
-	}
 
 	for (i = 0; i < DMA_CHANNELS; i++) {
 		struct most_channel_capability *cap = dev->capabilities + i;
@@ -840,10 +839,6 @@ err_unreg_iface:
 	most_deregister_interface(&dev->most_iface);
 err_stop_thread:
 	kthread_stop(dev->netinfo_task);
-err_free_irq:
-#if !defined(ENABLE_HDM_TEST)
-	free_irq(dev->irq_ahb0, dev);
-#endif
 
 	return ret;
 }
@@ -870,9 +865,6 @@ static int dim2_remove(struct platform_device *pdev)
 	dim2_sysfs_destroy(&dev->bus);
 	most_deregister_interface(&dev->most_iface);
 	kthread_stop(dev->netinfo_task);
-#if !defined(ENABLE_HDM_TEST)
-	free_irq(dev->irq_ahb0, dev);
-#endif
 
 	/*
 	 * break link to local platform_device_id struct
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/4] staging: most: hdm-dim2: Replace pr_err with dev_err
  2016-02-18 14:41 [PATCH 0/4] staging: most: hdm-dim2: Use devm_* functions Amitoj Kaur Chawla
                   ` (2 preceding siblings ...)
  2016-02-18 14:42 ` [PATCH 3/4] staging: most: hdm-dim2: Replace request_irq with devm_request_irq Amitoj Kaur Chawla
@ 2016-02-18 14:42 ` Amitoj Kaur Chawla
  2016-02-28 13:44 ` [Outreachy kernel] [PATCH 0/4] staging: most: hdm-dim2: Use devm_* functions Tejun Heo
  4 siblings, 0 replies; 6+ messages in thread
From: Amitoj Kaur Chawla @ 2016-02-18 14:42 UTC (permalink / raw)
  To: outreachy-kernel

Replace pr_err with dev_err when a appropriate device structure is
present.

Signed-off-by: Amitoj Kaur Chawla <amitoj1606@gmail.com>
---
 drivers/staging/most/hdm-dim2/dim2_hdm.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/most/hdm-dim2/dim2_hdm.c b/drivers/staging/most/hdm-dim2/dim2_hdm.c
index c9cc9c1..c736310 100644
--- a/drivers/staging/most/hdm-dim2/dim2_hdm.c
+++ b/drivers/staging/most/hdm-dim2/dim2_hdm.c
@@ -753,7 +753,7 @@ static int dim2_probe(struct platform_device *pdev)
 
 	ret = platform_get_irq(pdev, 0);
 	if (ret < 0) {
-		pr_err("failed to get irq\n");
+		dev_err(&pdev->dev, "failed to get irq\n");
 		return -ENODEV;
 	}
 	dev->irq_ahb0 = ret;
@@ -761,8 +761,8 @@ static int dim2_probe(struct platform_device *pdev)
 	ret = devm_request_irq(&pdev->dev, dev->irq_ahb0, dim2_ahb_isr, 0,
 			       "mlb_ahb0", dev);
 	if (ret) {
-		pr_err("failed to request IRQ: %d, err: %d\n",
-		       dev->irq_ahb0, ret);
+		dev_err(&pdev->dev, "failed to request IRQ: %d, err: %d\n",
+			dev->irq_ahb0, ret);
 		return ret;
 	}
 #endif
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [Outreachy kernel] [PATCH 0/4] staging: most: hdm-dim2: Use devm_* functions
  2016-02-18 14:41 [PATCH 0/4] staging: most: hdm-dim2: Use devm_* functions Amitoj Kaur Chawla
                   ` (3 preceding siblings ...)
  2016-02-18 14:42 ` [PATCH 4/4] staging: most: hdm-dim2: Replace pr_err with dev_err Amitoj Kaur Chawla
@ 2016-02-28 13:44 ` Tejun Heo
  4 siblings, 0 replies; 6+ messages in thread
From: Tejun Heo @ 2016-02-28 13:44 UTC (permalink / raw)
  To: Amitoj Kaur Chawla; +Cc: outreachy-kernel

On Thu, Feb 18, 2016 at 08:11:16PM +0530, Amitoj Kaur Chawla wrote:
> Devm_ functions allocate memory that is released when a driver
> detaches. Replace kzalloc, ioremap and request_irq with their devm_*
> counterparts in the probe function of a platform device which were
> originally freed in the remove function.
> 
> Also, unnecessary labels have been removed, an unnecessary
> platform_set_drvdata has been removed as well as switching from pr_err
> to dev_err.
> 
> Amitoj Kaur Chawla (4):
>   staging: most: hdm-dim2: Replace kzalloc with devm_kzalloc
>   staging: most: hdm-dim2: Switch to devm_ioremap_resource()
>   staging: most: hdm-dim2: Replace request_irq with devm_request_irq
>   staging: most: hdm-dim2: Replace pr_err with dev_err

For the patchset,

Acked-by: Tejun Heo <tj@kernel.org>

Thanks.

-- 
tejun


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-02-28 13:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-18 14:41 [PATCH 0/4] staging: most: hdm-dim2: Use devm_* functions Amitoj Kaur Chawla
2016-02-18 14:41 ` [PATCH 1/4] staging: most: hdm-dim2: Replace kzalloc with devm_kzalloc Amitoj Kaur Chawla
2016-02-18 14:41 ` [PATCH 2/4] staging: most: hdm-dim2: Switch to devm_ioremap_resource() Amitoj Kaur Chawla
2016-02-18 14:42 ` [PATCH 3/4] staging: most: hdm-dim2: Replace request_irq with devm_request_irq Amitoj Kaur Chawla
2016-02-18 14:42 ` [PATCH 4/4] staging: most: hdm-dim2: Replace pr_err with dev_err Amitoj Kaur Chawla
2016-02-28 13:44 ` [Outreachy kernel] [PATCH 0/4] staging: most: hdm-dim2: Use devm_* functions Tejun Heo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.