diff mbox

[1/1] Input: mms114: Use devm_* APIs

Message ID 1357639508-15645-1-git-send-email-sachin.kamat@linaro.org (mailing list archive)
State New, archived
Headers show

Commit Message

Sachin Kamat Jan. 8, 2013, 10:05 a.m. UTC
devm_* APIs are device managed and make the exit and clean up code
simpler.

Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
Cc: Joonyoung Shim <jy0922.shim@samsung.com>
---
Compile tested against linux-next tree (20130108).
---
 drivers/input/touchscreen/mms114.c |   41 +++++++++++------------------------
 1 files changed, 13 insertions(+), 28 deletions(-)

Comments

Laxman Dewangan Jan. 8, 2013, 11:08 a.m. UTC | #1
On Tuesday 08 January 2013 03:35 PM, Sachin Kamat wrote:
> devm_* APIs are device managed and make the exit and clean up code
> simpler.
>
> Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
> Cc: Joonyoung Shim <jy0922.shim@samsung.com>
> ---
> Compile tested against linux-next tree (20130108).
> ---
>   drivers/input/touchscreen/mms114.c |   41 +++++++++++------------------------
>   1 files changed, 13 insertions(+), 28 deletions(-)

>   static int mms114_remove(struct i2c_client *client)
>   {
>   	struct mms114_data *data = i2c_get_clientdata(client);
>   
> -	free_irq(client->irq, data);
> -	regulator_put(data->io_reg);
> -	regulator_put(data->core_reg);
>   	input_unregister_device(data->input_dev);

Because you are using devm_input_allocate_device() for allocating input 
device, you need not to have the input_unregister_device() and so you 
can get rid of remove() callback at all.
This is what I learnt from Dmitry on similar patch for Tegra KBC.

Thanks,
Laxman

-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information.  Any unauthorized review, use, disclosure or distribution
is prohibited.  If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Sachin Kamat Jan. 8, 2013, 11:38 a.m. UTC | #2
Hi Laxman,

Thank you for your suggestion.

On 8 January 2013 16:38, Laxman Dewangan <ldewangan@nvidia.com> wrote:
> On Tuesday 08 January 2013 03:35 PM, Sachin Kamat wrote:
>>
>> devm_* APIs are device managed and make the exit and clean up code
>> simpler.
>>
>> Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
>> Cc: Joonyoung Shim <jy0922.shim@samsung.com>
>> ---
>> Compile tested against linux-next tree (20130108).
>> ---
>>   drivers/input/touchscreen/mms114.c |   41
>> +++++++++++------------------------
>>   1 files changed, 13 insertions(+), 28 deletions(-)
>
>
>>   static int mms114_remove(struct i2c_client *client)
>>   {
>>         struct mms114_data *data = i2c_get_clientdata(client);
>>   -     free_irq(client->irq, data);
>> -       regulator_put(data->io_reg);
>> -       regulator_put(data->core_reg);
>>         input_unregister_device(data->input_dev);
>
>
> Because you are using devm_input_allocate_device() for allocating input
> device, you need not to have the input_unregister_device() and so you can
> get rid of remove() callback at all.
> This is what I learnt from Dmitry on similar patch for Tegra KBC.

input_free_device() is the one which is not required when you use
devm_input_allocate_device().
Unregister call, AFAIK, is required since we are registering using
input_register_device().

Dmitry, please let me know if my understanding is right.

>
> Thanks,
> Laxman
diff mbox

Patch

diff --git a/drivers/input/touchscreen/mms114.c b/drivers/input/touchscreen/mms114.c
index 98841d8..22295ec 100644
--- a/drivers/input/touchscreen/mms114.c
+++ b/drivers/input/touchscreen/mms114.c
@@ -429,12 +429,12 @@  static int mms114_probe(struct i2c_client *client,
 		return -ENODEV;
 	}
 
-	data = kzalloc(sizeof(struct mms114_data), GFP_KERNEL);
-	input_dev = input_allocate_device();
+	data = devm_kzalloc(&client->dev, sizeof(struct mms114_data),
+			    GFP_KERNEL);
+	input_dev = devm_input_allocate_device(&client->dev);
 	if (!data || !input_dev) {
 		dev_err(&client->dev, "Failed to allocate memory\n");
-		error = -ENOMEM;
-		goto err_free_mem;
+		return -ENOMEM;
 	}
 
 	data->client = client;
@@ -466,58 +466,43 @@  static int mms114_probe(struct i2c_client *client,
 	input_set_drvdata(input_dev, data);
 	i2c_set_clientdata(client, data);
 
-	data->core_reg = regulator_get(&client->dev, "avdd");
+	data->core_reg = devm_regulator_get(&client->dev, "avdd");
 	if (IS_ERR(data->core_reg)) {
 		error = PTR_ERR(data->core_reg);
 		dev_err(&client->dev,
 			"Unable to get the Core regulator (%d)\n", error);
-		goto err_free_mem;
+		return error;
 	}
 
-	data->io_reg = regulator_get(&client->dev, "vdd");
+	data->io_reg = devm_regulator_get(&client->dev, "vdd");
 	if (IS_ERR(data->io_reg)) {
 		error = PTR_ERR(data->io_reg);
 		dev_err(&client->dev,
 			"Unable to get the IO regulator (%d)\n", error);
-		goto err_core_reg;
+		return error;
 	}
 
-	error = request_threaded_irq(client->irq, NULL, mms114_interrupt,
-			IRQF_TRIGGER_FALLING | IRQF_ONESHOT, "mms114", data);
+	error = devm_request_threaded_irq(&client->dev, client->irq, NULL,
+			mms114_interrupt, IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
+			"mms114", data);
 	if (error) {
 		dev_err(&client->dev, "Failed to register interrupt\n");
-		goto err_io_reg;
+		return error;
 	}
 	disable_irq(client->irq);
 
 	error = input_register_device(data->input_dev);
 	if (error)
-		goto err_free_irq;
+		return error;
 
 	return 0;
-
-err_free_irq:
-	free_irq(client->irq, data);
-err_io_reg:
-	regulator_put(data->io_reg);
-err_core_reg:
-	regulator_put(data->core_reg);
-err_free_mem:
-	input_free_device(input_dev);
-	kfree(data);
-	return error;
 }
 
 static int mms114_remove(struct i2c_client *client)
 {
 	struct mms114_data *data = i2c_get_clientdata(client);
 
-	free_irq(client->irq, data);
-	regulator_put(data->io_reg);
-	regulator_put(data->core_reg);
 	input_unregister_device(data->input_dev);
-	kfree(data);
-
 	return 0;
 }