[PATCH] Input: da9052_onkey: convert to use devm_*

From: Kiran Padwal
Date: Fri Aug 08 2014 - 03:21:34 EST


Converting to devm functions can make the code smaller and cleaner.

Signed-off-by: Kiran Padwal <kiran.padwal@xxxxxxxxxxxxxxx>
---
drivers/input/misc/da9052_onkey.c | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/drivers/input/misc/da9052_onkey.c b/drivers/input/misc/da9052_onkey.c
index 184c8f2..909441e 100644
--- a/drivers/input/misc/da9052_onkey.c
+++ b/drivers/input/misc/da9052_onkey.c
@@ -84,12 +84,14 @@ static int da9052_onkey_probe(struct platform_device *pdev)
return -EINVAL;
}

- onkey = kzalloc(sizeof(*onkey), GFP_KERNEL);
- input_dev = input_allocate_device();
- if (!onkey || !input_dev) {
- dev_err(&pdev->dev, "Failed to allocate memory\n");
- error = -ENOMEM;
- goto err_free_mem;
+ onkey = devm_kzalloc(&pdev->dev, sizeof(*onkey), GFP_KERNEL);
+ if (!onkey)
+ return -ENOMEM;
+
+ input_dev = devm_input_allocate_device(&pdev->dev);
+ if (!input_dev) {
+ dev_err(&pdev->dev, "Failed to allocate input device\n");
+ return -ENOMEM;
}

onkey->input = input_dev;
@@ -108,7 +110,7 @@ static int da9052_onkey_probe(struct platform_device *pdev)
if (error < 0) {
dev_err(onkey->da9052->dev,
"Failed to register ONKEY IRQ: %d\n", error);
- goto err_free_mem;
+ return error;
}

error = input_register_device(onkey->input);
@@ -124,9 +126,6 @@ static int da9052_onkey_probe(struct platform_device *pdev)
err_free_irq:
da9052_free_irq(onkey->da9052, DA9052_IRQ_NONKEY, onkey);
cancel_delayed_work_sync(&onkey->work);
-err_free_mem:
- input_free_device(input_dev);
- kfree(onkey);

return error;
}
@@ -139,7 +138,6 @@ static int da9052_onkey_remove(struct platform_device *pdev)
cancel_delayed_work_sync(&onkey->work);

input_unregister_device(onkey->input);
- kfree(onkey);

return 0;
}
--
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/