]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
Input: tc3589x-keypad - switch to using managed resources
authorHimangi Saraogi <himangi774@gmail.com>
Mon, 26 May 2014 05:33:13 +0000 (22:33 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Fri, 24 Jul 2015 00:34:03 +0000 (17:34 -0700)
Let's switch the driver to use managed resources, this will simplify
error handling and driver unbinding logic.

Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/keyboard/tc3589x-keypad.c

index 565805e1ff94d26529981215be286301f75c9410..e92dfd8889c2d337545997f788a55881e8e8b94f 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/i2c.h>
 #include <linux/slab.h>
 #include <linux/mfd/tc3589x.h>
+#include <linux/device.h>
 
 /* Maximum supported keypad matrix row/columns size */
 #define TC3589x_MAX_KPROW               8
@@ -389,12 +390,15 @@ static int tc3589x_keypad_probe(struct platform_device *pdev)
        if (irq < 0)
                return irq;
 
-       keypad = kzalloc(sizeof(struct tc_keypad), GFP_KERNEL);
-       input = input_allocate_device();
-       if (!keypad || !input) {
-               dev_err(&pdev->dev, "failed to allocate keypad memory\n");
-               error = -ENOMEM;
-               goto err_free_mem;
+       keypad = devm_kzalloc(&pdev->dev, sizeof(struct tc_keypad),
+                             GFP_KERNEL);
+       if (!keypad)
+               return -ENOMEM;
+
+       input = devm_input_allocate_device(&pdev->dev);
+       if (!input) {
+               dev_err(&pdev->dev, "failed to allocate input device\n");
+               return -ENOMEM;
        }
 
        keypad->board = plat;
@@ -413,7 +417,7 @@ static int tc3589x_keypad_probe(struct platform_device *pdev)
                                           NULL, input);
        if (error) {
                dev_err(&pdev->dev, "Failed to build keymap\n");
-               goto err_free_mem;
+               return error;
        }
 
        keypad->keymap = input->keycode;
@@ -424,20 +428,23 @@ static int tc3589x_keypad_probe(struct platform_device *pdev)
 
        input_set_drvdata(input, keypad);
 
-       error = request_threaded_irq(irq, NULL, tc3589x_keypad_irq,
-                                    plat->irqtype | IRQF_ONESHOT,
-                                    "tc3589x-keypad", keypad);
-       if (error < 0) {
+       tc3589x_keypad_disable(keypad);
+
+       error = devm_request_threaded_irq(&pdev->dev, irq,
+                                         NULL, tc3589x_keypad_irq,
+                                         plat->irqtype | IRQF_ONESHOT,
+                                         "tc3589x-keypad", keypad);
+       if (error) {
                dev_err(&pdev->dev,
                                "Could not allocate irq %d,error %d\n",
                                irq, error);
-               goto err_free_mem;
+               return error;
        }
 
        error = input_register_device(input);
        if (error) {
                dev_err(&pdev->dev, "Could not register input device\n");
-               goto err_free_irq;
+               return error;
        }
 
        /* let platform decide if keypad is a wakeup source or not */
@@ -446,30 +453,6 @@ static int tc3589x_keypad_probe(struct platform_device *pdev)
 
        platform_set_drvdata(pdev, keypad);
 
-       return 0;
-
-err_free_irq:
-       free_irq(irq, keypad);
-err_free_mem:
-       input_free_device(input);
-       kfree(keypad);
-       return error;
-}
-
-static int tc3589x_keypad_remove(struct platform_device *pdev)
-{
-       struct tc_keypad *keypad = platform_get_drvdata(pdev);
-       int irq = platform_get_irq(pdev, 0);
-
-       if (!keypad->keypad_stopped)
-               tc3589x_keypad_disable(keypad);
-
-       free_irq(irq, keypad);
-
-       input_unregister_device(keypad->input);
-
-       kfree(keypad);
-
        return 0;
 }
 
@@ -521,7 +504,6 @@ static struct platform_driver tc3589x_keypad_driver = {
                .pm     = &tc3589x_keypad_dev_pm_ops,
        },
        .probe  = tc3589x_keypad_probe,
-       .remove = tc3589x_keypad_remove,
 };
 module_platform_driver(tc3589x_keypad_driver);