linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Input: da9052_onkey: convert to use devm_*
@ 2014-08-08  7:18 Kiran Padwal
  2014-08-08 16:26 ` Dmitry Torokhov
  0 siblings, 1 reply; 2+ messages in thread
From: Kiran Padwal @ 2014-08-08  7:18 UTC (permalink / raw)
  To: support.opensource, dmitry.torokhov
  Cc: anthony.olech.opensource, david.chen, kiran.padwal21, linux-input,
	linux-kernel, Kiran Padwal

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

Signed-off-by: Kiran Padwal <kiran.padwal@smartplayin.com>
---
 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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Input: da9052_onkey: convert to use devm_*
  2014-08-08  7:18 [PATCH] Input: da9052_onkey: convert to use devm_* Kiran Padwal
@ 2014-08-08 16:26 ` Dmitry Torokhov
  0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Torokhov @ 2014-08-08 16:26 UTC (permalink / raw)
  To: Kiran Padwal
  Cc: support.opensource, anthony.olech.opensource, david.chen,
	kiran.padwal21, linux-input, linux-kernel

Hi Kiran,

On Fri, Aug 08, 2014 at 12:48:44PM +0530, Kiran Padwal wrote:
> Converting to devm functions can make the code smaller and cleaner.

I'd rather not mix use of managed and non-managed resources in one
driver.

Thanks.

> 
> Signed-off-by: Kiran Padwal <kiran.padwal@smartplayin.com>
> ---
>  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
> 

-- 
Dmitry

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-08-08 16:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-08  7:18 [PATCH] Input: da9052_onkey: convert to use devm_* Kiran Padwal
2014-08-08 16:26 ` Dmitry Torokhov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).