From: Tomasz Figa <t.figa@samsung.com>
To: Manish Badarkhe <badarkhe.manish@gmail.com>
Cc: linux-tegra@vger.kernel.org, linux-samsung-soc@vger.kernel.org,
dmitry.torokhov@gmail.com
Subject: Re: [PATCH] Input: gpio-keys - update to devm_* API
Date: Tue, 17 Sep 2013 13:19:39 +0200 [thread overview]
Message-ID: <4083416.Q4nm27K4Qq@amdc1227> (raw)
In-Reply-To: <1379188343-18904-1-git-send-email-badarkhe.manish@gmail.com>
Hi Manish,
Thanks for the patch. I have few comments inline, though.
On Sunday 15 of September 2013 01:22:23 Manish Badarkhe wrote:
> Update the code to use devm_* API so that driver core will manage
> resources.
>
> Signed-off-by: Manish Badarkhe <badarkhe.manish@gmail.com>
> ---
>
> :100644 100644 440ce32... b4db721... M drivers/input/keyboard/gpio_keys.c
>
> drivers/input/keyboard/gpio_keys.c | 18 ++++++------------
> 1 file changed, 6 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/input/keyboard/gpio_keys.c
> b/drivers/input/keyboard/gpio_keys.c index 440ce32..b4db721 100644
> --- a/drivers/input/keyboard/gpio_keys.c
> +++ b/drivers/input/keyboard/gpio_keys.c
> @@ -588,7 +588,7 @@ gpio_keys_get_devtree_pdata(struct device *dev)
> goto err_out;
> }
>
> - pdata = kzalloc(sizeof(*pdata) + nbuttons * (sizeof *button),
> + pdata = devm_kzalloc(dev, sizeof(*pdata) + nbuttons *
> (sizeof(*button)), GFP_KERNEL);
> if (!pdata) {
> error = -ENOMEM;
> @@ -618,7 +618,7 @@ gpio_keys_get_devtree_pdata(struct device *dev)
> dev_err(dev,
> "Failed to get gpio flags, error: %d\n",
> error);
> - goto err_free_pdata;
> + goto err_out;
Since the only thing done after err_out label is returning the error, you
can simply return the error here.
> }
>
> button = &pdata->buttons[i++];
> @@ -630,7 +630,7 @@ gpio_keys_get_devtree_pdata(struct device *dev)
> dev_err(dev, "Button without keycode: 0x%x\n",
> button->gpio);
> error = -EINVAL;
> - goto err_free_pdata;
> + goto err_out;
Ditto.
> }
>
> button->desc = of_get_property(pp, "label", NULL);
> @@ -647,13 +647,11 @@ gpio_keys_get_devtree_pdata(struct device *dev)
>
> if (pdata->nbuttons == 0) {
> error = -EINVAL;
> - goto err_free_pdata;
> + goto err_out;
Ditto.
> }
>
> return pdata;
>
> -err_free_pdata:
> - kfree(pdata);
> err_out:
> return ERR_PTR(error);
Then the whole error path here can be dropped.
> }
> @@ -699,10 +697,10 @@ static int gpio_keys_probe(struct platform_device
> *pdev) return PTR_ERR(pdata);
> }
>
> - ddata = kzalloc(sizeof(struct gpio_keys_drvdata) +
> + ddata = devm_kzalloc(&pdev->dev, sizeof(struct gpio_keys_drvdata) +
> pdata->nbuttons * sizeof(struct gpio_button_data),
> GFP_KERNEL);
> - input = input_allocate_device();
> + input = devm_input_allocate_device(&pdev->dev);
> if (!ddata || !input) {
> dev_err(dev, "failed to allocate state\n");
> error = -ENOMEM;
> @@ -768,8 +766,6 @@ static int gpio_keys_probe(struct platform_device
> *pdev) gpio_remove_key(&ddata->data[i]);
>
> fail1:
> - input_free_device(input);
> - kfree(ddata);
> /* If we have no platform data, we allocated pdata dynamically. */
> if (!dev_get_platdata(&pdev->dev))
> kfree(pdata);
This is incorrect and unnecessary. Since pdata was allocated using devm_
helper it will be freed automatically. As a side note, if you want to
explicitly free memory allocated using devm_ helpers, you need to do it
using their devm_ free counterparts, not directly.
> @@ -796,8 +792,6 @@ static int gpio_keys_remove(struct platform_device
> *pdev) if (!dev_get_platdata(&pdev->dev))
> kfree(ddata->pdata);
Same here.
Best regards,
Tomasz
next prev parent reply other threads:[~2013-09-17 11:19 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-14 19:52 [PATCH] Input: gpio-keys - update to devm_* API Manish Badarkhe
2013-09-17 11:19 ` Tomasz Figa [this message]
2013-09-17 18:32 ` Manish Badarkhe
[not found] ` <1379188343-18904-1-git-send-email-badarkhe.manish-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2013-09-17 18:52 ` Dmitry Torokhov
[not found] ` <20130917185259.GA6894-WlK9ik9hQGAhIp7JRqBPierSzoNAToWh@public.gmane.org>
2013-09-17 19:11 ` Manish Badarkhe
[not found] ` <CAKDJKT5fvf=cCqU0ULs0o6NO10aDM73ewx=-sVG9Rzm-cKkECg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-09-19 21:22 ` Dmitry Torokhov
[not found] ` <20130919212253.GA16015-WlK9ik9hQGAhIp7JRqBPierSzoNAToWh@public.gmane.org>
2013-09-20 2:24 ` Manish Badarkhe
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=4083416.Q4nm27K4Qq@amdc1227 \
--to=t.figa@samsung.com \
--cc=badarkhe.manish@gmail.com \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=linux-tegra@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