mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Himangi Saraogi <himangi774@gmail.com>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	julia.lawall@lip6.fr
Subject: Re: [PATCH] Input: 88pm860x_onkey : Introduce the use of the managed version of  kzalloc
Date: Thu, 29 May 2014 00:25:38 -0700	[thread overview]
Message-ID: <20140529072538.GG11817@core.coreip.homeip.net> (raw)
In-Reply-To: <20140528200123.GA9946@himangi-Dell>

On Thu, May 29, 2014 at 01:31:23AM +0530, Himangi Saraogi wrote:
> This patch moves most data allocated in the probe function from
> unmanaged interfaces to managed interfaces. The kfrees and error
> handling code is done away with. Also, the unnecesary labels are
> removed and the function pm860x_onkey_remove is removed as it becomes
> empty after removing the no longer required function calls. Also,
> linux/device.h include is added to make sure the devm_*() routine
> declarations are unambiguously available.
> 
> The following Coccinelle semantic patch was used for making a part of
> the change:
> 
> @platform@
> identifier p, probefn, removefn;
> @@
> struct platform_driver p = {
>   .probe = probefn,
>   .remove = removefn,
> };
> 
> @prb@
> identifier platform.probefn, pdev;
> expression e, e1, e2;
> @@
> probefn(struct platform_device *pdev, ...) {
>   <+...
> - e = kzalloc(e1, e2)
> + e = devm_kzalloc(&pdev->dev, e1, e2)
>   ...
> ?-kfree(e);
>   ...+>
> }
> 
> @rem depends on prb@
> identifier platform.removefn;
> expression e;
> @@
> removefn(...) {
>   <...
> - kfree(e);
>   ...>
> }
> 
> Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
> Acked-by: Julia Lawall <julia.lawall@lip6.fr>

Applied, thank you.

> ---
>  drivers/input/misc/88pm860x_onkey.c | 40 ++++++++++---------------------------
>  1 file changed, 10 insertions(+), 30 deletions(-)
> 
> diff --git a/drivers/input/misc/88pm860x_onkey.c b/drivers/input/misc/88pm860x_onkey.c
> index abd8453..220ce0f 100644
> --- a/drivers/input/misc/88pm860x_onkey.c
> +++ b/drivers/input/misc/88pm860x_onkey.c
> @@ -26,6 +26,7 @@
>  #include <linux/interrupt.h>
>  #include <linux/mfd/88pm860x.h>
>  #include <linux/slab.h>
> +#include <linux/device.h>
>  
>  #define PM8607_WAKEUP		0x0b
>  
> @@ -68,7 +69,8 @@ static int pm860x_onkey_probe(struct platform_device *pdev)
>  		return -EINVAL;
>  	}
>  
> -	info = kzalloc(sizeof(struct pm860x_onkey_info), GFP_KERNEL);
> +	info = devm_kzalloc(&pdev->dev, sizeof(struct pm860x_onkey_info),
> +			    GFP_KERNEL);
>  	if (!info)
>  		return -ENOMEM;
>  	info->chip = chip;
> @@ -76,11 +78,10 @@ static int pm860x_onkey_probe(struct platform_device *pdev)
>  	info->dev = &pdev->dev;
>  	info->irq = irq;
>  
> -	info->idev = input_allocate_device();
> +	info->idev = devm_input_allocate_device(&pdev->dev);
>  	if (!info->idev) {
>  		dev_err(chip->dev, "Failed to allocate input dev\n");
> -		ret = -ENOMEM;
> -		goto out;
> +		return -ENOMEM;
>  	}
>  
>  	info->idev->name = "88pm860x_on";
> @@ -93,42 +94,22 @@ static int pm860x_onkey_probe(struct platform_device *pdev)
>  	ret = input_register_device(info->idev);
>  	if (ret) {
>  		dev_err(chip->dev, "Can't register input device: %d\n", ret);
> -		goto out_reg;
> +		return ret;
>  	}
>  
> -	ret = request_threaded_irq(info->irq, NULL, pm860x_onkey_handler,
> -				   IRQF_ONESHOT, "onkey", info);
> +	ret = devm_request_threaded_irq(&pdev->dev, info->irq, NULL,
> +					pm860x_onkey_handler, IRQF_ONESHOT,
> +					"onkey", info);
>  	if (ret < 0) {
>  		dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n",
>  			info->irq, ret);
> -		goto out_irq;
> +		return ret;
>  	}
>  
>  	platform_set_drvdata(pdev, info);
>  	device_init_wakeup(&pdev->dev, 1);
>  
>  	return 0;
> -
> -out_irq:
> -	input_unregister_device(info->idev);
> -	kfree(info);
> -	return ret;
> -
> -out_reg:
> -	input_free_device(info->idev);
> -out:
> -	kfree(info);
> -	return ret;
> -}
> -
> -static int pm860x_onkey_remove(struct platform_device *pdev)
> -{
> -	struct pm860x_onkey_info *info = platform_get_drvdata(pdev);
> -
> -	free_irq(info->irq, info);
> -	input_unregister_device(info->idev);
> -	kfree(info);
> -	return 0;
>  }
>  
>  #ifdef CONFIG_PM_SLEEP
> @@ -161,7 +142,6 @@ static struct platform_driver pm860x_onkey_driver = {
>  		.pm	= &pm860x_onkey_pm_ops,
>  	},
>  	.probe		= pm860x_onkey_probe,
> -	.remove		= pm860x_onkey_remove,
>  };
>  module_platform_driver(pm860x_onkey_driver);
>  
> -- 
> 1.9.1
> 

-- 
Dmitry

      reply	other threads:[~2014-05-29  7:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-28 20:01 Himangi Saraogi
2014-05-29  7:25 ` Dmitry Torokhov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140529072538.GG11817@core.coreip.homeip.net \
    --to=dmitry.torokhov@gmail.com \
    --cc=himangi774@gmail.com \
    --cc=julia.lawall@lip6.fr \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®