diff mbox

[1/3] tps6507x-ts: update to devm_* API

Message ID 1487950946-18590-2-git-send-email-yegorslists@googlemail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Yegor Yefremov Feb. 24, 2017, 3:42 p.m. UTC
From: Yegor Yefremov <yegorslists@googlemail.com>

Update the code to use devm_* API so that driver
core will manage resources.

Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
---
 drivers/input/touchscreen/tps6507x-ts.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

Comments

Dmitry Torokhov Feb. 28, 2017, 6:57 p.m. UTC | #1
On Fri, Feb 24, 2017 at 04:42:24PM +0100, yegorslists@googlemail.com wrote:
> From: Yegor Yefremov <yegorslists@googlemail.com>
> 
> Update the code to use devm_* API so that driver
> core will manage resources.
> 
> Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
> ---
>  drivers/input/touchscreen/tps6507x-ts.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/input/touchscreen/tps6507x-ts.c b/drivers/input/touchscreen/tps6507x-ts.c
> index a340bfc..5bf1ec6 100644
> --- a/drivers/input/touchscreen/tps6507x-ts.c
> +++ b/drivers/input/touchscreen/tps6507x-ts.c
> @@ -226,7 +226,7 @@ static int tps6507x_ts_probe(struct platform_device *pdev)
>  	 */
>  	init_data = tps_board->tps6507x_ts_init_data;
>  
> -	tsc = kzalloc(sizeof(struct tps6507x_ts), GFP_KERNEL);
> +	tsc = devm_kzalloc(&pdev->dev, sizeof(struct tps6507x_ts), GFP_KERNEL);

If you do this, why not use devm_input_allocate_polled_device() as well?
Then you can get rid of tps6507x_ts_remove().

Thanks.
Yegor Yefremov March 1, 2017, 8:13 a.m. UTC | #2
On Tue, Feb 28, 2017 at 7:57 PM, Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
> On Fri, Feb 24, 2017 at 04:42:24PM +0100, yegorslists@googlemail.com wrote:
>> From: Yegor Yefremov <yegorslists@googlemail.com>
>>
>> Update the code to use devm_* API so that driver
>> core will manage resources.
>>
>> Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
>> ---
>>  drivers/input/touchscreen/tps6507x-ts.c | 9 +++------
>>  1 file changed, 3 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/input/touchscreen/tps6507x-ts.c b/drivers/input/touchscreen/tps6507x-ts.c
>> index a340bfc..5bf1ec6 100644
>> --- a/drivers/input/touchscreen/tps6507x-ts.c
>> +++ b/drivers/input/touchscreen/tps6507x-ts.c
>> @@ -226,7 +226,7 @@ static int tps6507x_ts_probe(struct platform_device *pdev)
>>        */
>>       init_data = tps_board->tps6507x_ts_init_data;
>>
>> -     tsc = kzalloc(sizeof(struct tps6507x_ts), GFP_KERNEL);
>> +     tsc = devm_kzalloc(&pdev->dev, sizeof(struct tps6507x_ts), GFP_KERNEL);
>
> If you do this, why not use devm_input_allocate_polled_device() as well?
> Then you can get rid of tps6507x_ts_remove().

Will do. The less code the better.

Yegor
--
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
diff mbox

Patch

diff --git a/drivers/input/touchscreen/tps6507x-ts.c b/drivers/input/touchscreen/tps6507x-ts.c
index a340bfc..5bf1ec6 100644
--- a/drivers/input/touchscreen/tps6507x-ts.c
+++ b/drivers/input/touchscreen/tps6507x-ts.c
@@ -226,7 +226,7 @@  static int tps6507x_ts_probe(struct platform_device *pdev)
 	 */
 	init_data = tps_board->tps6507x_ts_init_data;
 
-	tsc = kzalloc(sizeof(struct tps6507x_ts), GFP_KERNEL);
+	tsc = devm_kzalloc(&pdev->dev, sizeof(struct tps6507x_ts), GFP_KERNEL);
 	if (!tsc) {
 		dev_err(tps6507x_dev->dev, "failed to allocate driver data\n");
 		return -ENOMEM;
@@ -244,7 +244,7 @@  static int tps6507x_ts_probe(struct platform_device *pdev)
 	if (!poll_dev) {
 		dev_err(tsc->dev, "Failed to allocate polled input device.\n");
 		error = -ENOMEM;
-		goto err_free_mem;
+		goto err;
 	}
 
 	tsc->poll_dev = poll_dev;
@@ -286,8 +286,7 @@  static int tps6507x_ts_probe(struct platform_device *pdev)
 
 err_free_polled_dev:
 	input_free_polled_device(poll_dev);
-err_free_mem:
-	kfree(tsc);
+err:
 	return error;
 }
 
@@ -299,8 +298,6 @@  static int tps6507x_ts_remove(struct platform_device *pdev)
 	input_unregister_polled_device(poll_dev);
 	input_free_polled_device(poll_dev);
 
-	kfree(tsc);
-
 	return 0;
 }