linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Input: mc13783-pwrbutton: Allocate resources using managed interfaces
@ 2014-05-25 10:14 Himangi Saraogi
  2014-05-26  5:32 ` Dmitry Torokhov
  0 siblings, 1 reply; 2+ messages in thread
From: Himangi Saraogi @ 2014-05-25 10:14 UTC (permalink / raw)
  To: Dmitry Torokhov, linux-input, linux-kernel; +Cc: julia.lawall

This patch moves most data allocated in the probe function from
unmanaged interfaces to managed interfaces. The kfrees and error
handling code is done away with. The unnecesary labels are
removed. Also, linux/device.h is added to make sure the devm_*()
routine declarations are unambiguously available. The name of label
free_priv is changed to unlock as it does not free priv anymore.

The following Coccinelle semantic patch was used for making a part of
the change:

@platform@
identifier p, probefn, removefn;
@@
struct platform_driver p = {
  .probe = probefn,
  .remove = removefn,
};

@prb@
identifier platform.probefn, pdev;
expression e, e1, e2;
@@
probefn(struct platform_device *pdev, ...) {
  <+...
- e = kzalloc(e1, e2)
+ e = devm_kzalloc(&pdev->dev, e1, e2)
  ...
?-kfree(e);
  ...+>
}

@rem depends on prb@
identifier platform.removefn;
expression e;
@@
removefn(...) {
  <...
- kfree(e);
  ...>
}

Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
---
Not compiled due to incompatible architecture.

mc13xxx_irq_request is not devm'd, and doing so looks complicated due to
the locks around the frees.  Is there some way to resolve this issue?

To send to: Dmitry Torokhov <dmitry.torokhov@gmail.com>,linux-input@vger.kernel.org,linux-kernel@vger.kernel.org
 drivers/input/misc/mc13783-pwrbutton.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/drivers/input/misc/mc13783-pwrbutton.c b/drivers/input/misc/mc13783-pwrbutton.c
index 0df6e8d..6afea1a 100644
--- a/drivers/input/misc/mc13783-pwrbutton.c
+++ b/drivers/input/misc/mc13783-pwrbutton.c
@@ -28,6 +28,7 @@
 #include <linux/mfd/mc13783.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
+#include <linux/device.h>
 
 struct mc13783_pwrb {
 	struct input_dev *pwr;
@@ -103,17 +104,16 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
 		return -ENODEV;
 	}
 
-	pwr = input_allocate_device();
+	pwr = devm_input_allocate_device(&pdev->dev);
 	if (!pwr) {
 		dev_dbg(&pdev->dev, "Can't allocate power button\n");
 		return -ENOMEM;
 	}
 
-	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
 	if (!priv) {
-		err = -ENOMEM;
 		dev_dbg(&pdev->dev, "Can't allocate power button\n");
-		goto free_input_dev;
+		return -ENOMEM;
 	}
 
 	reg |= (pdata->b1on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON1BDBNC;
@@ -140,7 +140,7 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
 					  button_irq, "b1on", priv);
 		if (err) {
 			dev_dbg(&pdev->dev, "Can't request irq\n");
-			goto free_priv;
+			goto unlock;
 		}
 	}
 
@@ -219,12 +219,8 @@ free_irq_b1:
 	if (pdata->b1on_flags & MC13783_BUTTON_ENABLE)
 		mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD1, priv);
 
-free_priv:
+unlock:
 	mc13xxx_unlock(mc13783);
-	kfree(priv);
-
-free_input_dev:
-	input_free_device(pwr);
 
 	return err;
 }
@@ -247,9 +243,6 @@ static int mc13783_pwrbutton_remove(struct platform_device *pdev)
 
 	mc13xxx_unlock(priv->mc13783);
 
-	input_unregister_device(priv->pwr);
-	kfree(priv);
-
 	return 0;
 }
 
-- 
1.9.1


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

* Re: [PATCH] Input: mc13783-pwrbutton: Allocate resources using managed interfaces
  2014-05-25 10:14 [PATCH] Input: mc13783-pwrbutton: Allocate resources using managed interfaces Himangi Saraogi
@ 2014-05-26  5:32 ` Dmitry Torokhov
  0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Torokhov @ 2014-05-26  5:32 UTC (permalink / raw)
  To: Himangi Saraogi; +Cc: linux-input, linux-kernel, julia.lawall

On Sun, May 25, 2014 at 03:44:01PM +0530, Himangi Saraogi wrote:
> This patch moves most data allocated in the probe function from
> unmanaged interfaces to managed interfaces. The kfrees and error
> handling code is done away with. The unnecesary labels are
> removed. Also, linux/device.h is added to make sure the devm_*()
> routine declarations are unambiguously available. The name of label
> free_priv is changed to unlock as it does not free priv anymore.
> 
> The following Coccinelle semantic patch was used for making a part of
> the change:
> 
> @platform@
> identifier p, probefn, removefn;
> @@
> struct platform_driver p = {
>   .probe = probefn,
>   .remove = removefn,
> };
> 
> @prb@
> identifier platform.probefn, pdev;
> expression e, e1, e2;
> @@
> probefn(struct platform_device *pdev, ...) {
>   <+...
> - e = kzalloc(e1, e2)
> + e = devm_kzalloc(&pdev->dev, e1, e2)
>   ...
> ?-kfree(e);
>   ...+>
> }
> 
> @rem depends on prb@
> identifier platform.removefn;
> expression e;
> @@
> removefn(...) {
>   <...
> - kfree(e);
>   ...>
> }
> 
> Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
> Acked-by: Julia Lawall <julia.lawall@lip6.fr>
> ---
> Not compiled due to incompatible architecture.
> 
> mc13xxx_irq_request is not devm'd, and doing so looks complicated due to
> the locks around the frees.  Is there some way to resolve this issue?

Yes there us - let's leave the driver as is so we are not mixing the 2
styles.

Thanks.

-- 
Dmitry

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

end of thread, other threads:[~2014-05-26  5:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-25 10:14 [PATCH] Input: mc13783-pwrbutton: Allocate resources using managed interfaces Himangi Saraogi
2014-05-26  5:32 ` Dmitry Torokhov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).