Input: dm355evm_keys - switch to using managed resources
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Wed, 8 Mar 2017 17:36:23 +0000 (09:36 -0800)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Thu, 9 Mar 2017 18:06:19 +0000 (10:06 -0800)
Using devm_* APIs simpifies error handling and device teardown.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/misc/dm355evm_keys.c

index 5db493dfe509a940b527fb5aa939b946ab3d1fc9..bab256ef32b9b3f367bdcd4b4283ba7d034a5847 100644 (file)
@@ -32,7 +32,6 @@
 struct dm355evm_keys {
        struct input_dev        *input;
        struct device           *dev;
-       int                     irq;
 };
 
 /* These initial keycodes can be remapped */
@@ -176,71 +175,49 @@ static int dm355evm_keys_probe(struct platform_device *pdev)
 {
        struct dm355evm_keys    *keys;
        struct input_dev        *input;
-       int                     status;
+       int                     irq;
+       int                     error;
 
-       /* allocate instance struct and input dev */
-       keys = kzalloc(sizeof *keys, GFP_KERNEL);
-       input = input_allocate_device();
-       if (!keys || !input) {
-               status = -ENOMEM;
-               goto fail1;
-       }
+       keys = devm_kzalloc(&pdev->dev, sizeof (*keys), GFP_KERNEL);
+       if (!keys)
+               return -ENOMEM;
+
+       input = devm_input_allocate_device(&pdev->dev);
+       if (!input)
+               return -ENOMEM;
 
        keys->dev = &pdev->dev;
        keys->input = input;
 
-       /* set up "threaded IRQ handler" */
-       status = platform_get_irq(pdev, 0);
-       if (status < 0)
-               goto fail1;
-       keys->irq = status;
-
        input->name = "DM355 EVM Controls";
        input->phys = "dm355evm/input0";
-       input->dev.parent = &pdev->dev;
 
        input->id.bustype = BUS_I2C;
        input->id.product = 0x0355;
        input->id.version = dm355evm_msp_read(DM355EVM_MSP_FIRMREV);
 
-       status = sparse_keymap_setup(input, dm355evm_keys, NULL);
-       if (status)
-               goto fail1;
+       error = sparse_keymap_setup(input, dm355evm_keys, NULL);
+       if (error)
+               return error;
 
        /* REVISIT:  flush the event queue? */
 
-       status = request_threaded_irq(keys->irq, NULL, dm355evm_keys_irq,
-                                     IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
-                                     dev_name(&pdev->dev), keys);
-       if (status < 0)
-               goto fail1;
-
-       /* register */
-       status = input_register_device(input);
-       if (status < 0)
-               goto fail2;
-
-       platform_set_drvdata(pdev, keys);
-
-       return 0;
-
-fail2:
-       free_irq(keys->irq, keys);
-fail1:
-       input_free_device(input);
-       kfree(keys);
-       dev_err(&pdev->dev, "can't register, err %d\n", status);
-
-       return status;
-}
+       /* set up "threaded IRQ handler" */
+       irq = platform_get_irq(pdev, 0);
+       if (irq < 0)
+               return irq;
 
-static int dm355evm_keys_remove(struct platform_device *pdev)
-{
-       struct dm355evm_keys    *keys = platform_get_drvdata(pdev);
+       error = devm_request_threaded_irq(&pdev->dev, irq,
+                                         NULL, dm355evm_keys_irq,
+                                         IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
+                                         dev_name(&pdev->dev), keys);
+       if (error)
+               return error;
 
-       free_irq(keys->irq, keys);
-       input_unregister_device(keys->input);
-       kfree(keys);
+       /* register */
+       error = input_register_device(input);
+       if (error)
+               return error;
 
        return 0;
 }
@@ -256,7 +233,6 @@ static int dm355evm_keys_remove(struct platform_device *pdev)
  */
 static struct platform_driver dm355evm_keys_driver = {
        .probe          = dm355evm_keys_probe,
-       .remove         = dm355evm_keys_remove,
        .driver         = {
                .name   = "dm355evm_keys",
        },