diff mbox

[2/2] Input: da9055_onkey: convert to use devm_*

Message ID 1407482212-17669-1-git-send-email-kiran.padwal@smartplayin.com (mailing list archive)
State New, archived
Headers show

Commit Message

kiran.padwal@smartplayin.com Aug. 8, 2014, 7:16 a.m. UTC
Converting to devm functions can make the code smaller and cleaner.

Signed-off-by: Kiran Padwal <kiran.padwal@smartplayin.com>
---
 drivers/input/misc/da9055_onkey.c |   22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)

Comments

Dmitry Torokhov Aug. 8, 2014, 7:42 a.m. UTC | #1
Hi Kiran,

On Fri, Aug 08, 2014 at 12:46:52PM +0530, Kiran Padwal wrote:
> Converting to devm functions can make the code smaller and cleaner.

Unfortunately it also makes it incorrect. As presented this conversion
introduces race on driver removal. Before doing any more devm conversions
please try to spot it or ping me back in a couple of days if you'd like it
explained.

Thanks.
diff mbox

Patch

diff --git a/drivers/input/misc/da9055_onkey.c b/drivers/input/misc/da9055_onkey.c
index ed6eaa9..1a1e760 100644
--- a/drivers/input/misc/da9055_onkey.c
+++ b/drivers/input/misc/da9055_onkey.c
@@ -90,9 +90,9 @@  static int da9055_onkey_probe(struct platform_device *pdev)
 	if (!onkey)
 		return -ENOMEM;
 
-	input_dev = input_allocate_device();
+	input_dev = devm_input_allocate_device(&pdev->dev);
 	if (!input_dev) {
-		dev_err(&pdev->dev, "Failed to allocate memory\n");
+		dev_err(&pdev->dev, "Failed to allocate input device\n");
 		return -ENOMEM;
 	}
 
@@ -107,43 +107,33 @@  static int da9055_onkey_probe(struct platform_device *pdev)
 
 	INIT_DELAYED_WORK(&onkey->work, da9055_onkey_work);
 
-	err = request_threaded_irq(irq, NULL, da9055_onkey_irq,
+	err = devm_request_threaded_irq(&pdev->dev, irq, NULL, da9055_onkey_irq,
 				   IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
 				   "ONKEY", onkey);
 	if (err < 0) {
 		dev_err(&pdev->dev,
 			"Failed to register ONKEY IRQ %d, error = %d\n",
 			irq, err);
-		goto err_free_input;
+		return err;
 	}
 
 	err = input_register_device(input_dev);
 	if (err) {
 		dev_err(&pdev->dev, "Unable to register input device, %d\n",
 			err);
-		goto err_free_irq;
+		cancel_delayed_work_sync(&onkey->work);
+		return err;
 	}
 
 	platform_set_drvdata(pdev, onkey);
 
 	return 0;
-
-err_free_irq:
-	free_irq(irq, onkey);
-	cancel_delayed_work_sync(&onkey->work);
-err_free_input:
-	input_free_device(input_dev);
-
-	return err;
 }
 
 static int da9055_onkey_remove(struct platform_device *pdev)
 {
 	struct da9055_onkey *onkey = platform_get_drvdata(pdev);
-	int irq = platform_get_irq_byname(pdev, "ONKEY");
 
-	irq = regmap_irq_get_virq(onkey->da9055->irq_data, irq);
-	free_irq(irq, onkey);
 	cancel_delayed_work_sync(&onkey->work);
 	input_unregister_device(onkey->input);