Input: da9034-ts - switch to using managed resources
authorHimangi Saraogi <himangi774@gmail.com>
Wed, 21 May 2014 15:27:06 +0000 (08:27 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Thu, 29 May 2014 06:48:36 +0000 (23:48 -0700)
Let's switch the driver to use managed resources, this will simplify error
handling and allows us to get rid of da9034_touch_remove().

Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/touchscreen/da9034-ts.c

index 8ccf7bb4028a36c437b7c09726e23a9e94a03e8f..cf6f4b31db4d60ac3ade9d290782a507ef019f87 100644 (file)
@@ -301,10 +301,11 @@ static int da9034_touch_probe(struct platform_device *pdev)
        struct da9034_touch_pdata *pdata = dev_get_platdata(&pdev->dev);
        struct da9034_touch *touch;
        struct input_dev *input_dev;
-       int ret;
+       int error;
 
-       touch = kzalloc(sizeof(struct da9034_touch), GFP_KERNEL);
-       if (touch == NULL) {
+       touch = devm_kzalloc(&pdev->dev, sizeof(struct da9034_touch),
+                            GFP_KERNEL);
+       if (!touch) {
                dev_err(&pdev->dev, "failed to allocate driver data\n");
                return -ENOMEM;
        }
@@ -315,18 +316,18 @@ static int da9034_touch_probe(struct platform_device *pdev)
                touch->interval_ms      = pdata->interval_ms;
                touch->x_inverted       = pdata->x_inverted;
                touch->y_inverted       = pdata->y_inverted;
-       } else
+       } else {
                /* fallback into default */
                touch->interval_ms      = 10;
+       }
 
        INIT_DELAYED_WORK(&touch->tsi_work, da9034_tsi_work);
        touch->notifier.notifier_call = da9034_touch_notifier;
 
-       input_dev = input_allocate_device();
+       input_dev = devm_input_allocate_device(&pdev->dev);
        if (!input_dev) {
                dev_err(&pdev->dev, "failed to allocate input device\n");
-               ret = -ENOMEM;
-               goto err_free_touch;
+               return -ENOMEM;
        }
 
        input_dev->name         = pdev->name;
@@ -346,26 +347,9 @@ static int da9034_touch_probe(struct platform_device *pdev)
        touch->input_dev = input_dev;
        input_set_drvdata(input_dev, touch);
 
-       ret = input_register_device(input_dev);
-       if (ret)
-               goto err_free_input;
-
-       platform_set_drvdata(pdev, touch);
-       return 0;
-
-err_free_input:
-       input_free_device(input_dev);
-err_free_touch:
-       kfree(touch);
-       return ret;
-}
-
-static int da9034_touch_remove(struct platform_device *pdev)
-{
-       struct da9034_touch *touch = platform_get_drvdata(pdev);
-
-       input_unregister_device(touch->input_dev);
-       kfree(touch);
+       error = input_register_device(input_dev);
+       if (error)
+               return error;
 
        return 0;
 }
@@ -376,7 +360,6 @@ static struct platform_driver da9034_touch_driver = {
                .owner  = THIS_MODULE,
        },
        .probe          = da9034_touch_probe,
-       .remove         = da9034_touch_remove,
 };
 module_platform_driver(da9034_touch_driver);