From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Laxman Dewangan <ldewangan@nvidia.com>
Cc: grant.likely@secretlab.ca, rob.herring@calxeda.com,
swarren@nvidia.com, devicetree-discuss@lists.ozlabs.org,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-input@vger.kernel.org, linux-tegra@vger.kernel.org
Subject: Re: [PATCH v2 2/4] input: keyboard: tegra: use devm_* for resource allocation
Date: Sat, 5 Jan 2013 00:06:58 -0800 [thread overview]
Message-ID: <20130105080658.GA1315@core.coreip.homeip.net> (raw)
In-Reply-To: <1357371910-3164-3-git-send-email-ldewangan@nvidia.com>
Hi Laxman,
On Sat, Jan 05, 2013 at 01:15:08PM +0530, Laxman Dewangan wrote:
> Use devm_* for memory, clock, input device allocation. This reduces
> code for freeing these resources.
>
> Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
> ---
> Changes from V1:
> None
>
> drivers/input/keyboard/tegra-kbc.c | 93 +++++++++++-------------------------
> 1 files changed, 28 insertions(+), 65 deletions(-)
>
> diff --git a/drivers/input/keyboard/tegra-kbc.c b/drivers/input/keyboard/tegra-kbc.c
> index f1d3ba0..c036425 100644
> --- a/drivers/input/keyboard/tegra-kbc.c
> +++ b/drivers/input/keyboard/tegra-kbc.c
> @@ -618,7 +618,7 @@ static struct tegra_kbc_platform_data *tegra_kbc_dt_parse_pdata(
> if (!np)
> return NULL;
>
> - pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
> + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
> if (!pdata)
> return NULL;
>
> @@ -700,33 +700,36 @@ static int tegra_kbc_probe(struct platform_device *pdev)
> if (!pdata)
> pdata = tegra_kbc_dt_parse_pdata(pdev);
>
> - if (!pdata)
> + if (!pdata) {
> + dev_err(&pdev->dev, "Platform data missing\n");
> return -EINVAL;
> -
> - if (!tegra_kbc_check_pin_cfg(pdata, &pdev->dev, &num_rows)) {
> - err = -EINVAL;
> - goto err_free_pdata;
> }
>
> + if (!tegra_kbc_check_pin_cfg(pdata, &pdev->dev, &num_rows))
> + return -EINVAL;
> +
> res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> if (!res) {
> dev_err(&pdev->dev, "failed to get I/O memory\n");
> - err = -ENXIO;
> - goto err_free_pdata;
> + return -ENXIO;
> }
>
> irq = platform_get_irq(pdev, 0);
> if (irq < 0) {
> dev_err(&pdev->dev, "failed to get keyboard IRQ\n");
> - err = -ENXIO;
> - goto err_free_pdata;
> + return -ENXIO;
> + }
> +
> + kbc = devm_kzalloc(&pdev->dev, sizeof(*kbc), GFP_KERNEL);
> + if (!kbc) {
> + dev_err(&pdev->dev, "failed to alloc memory for kbc\n");
> + return -ENOMEM;
> }
>
> - kbc = kzalloc(sizeof(*kbc), GFP_KERNEL);
> - input_dev = input_allocate_device();
> - if (!kbc || !input_dev) {
> - err = -ENOMEM;
> - goto err_free_mem;
> + input_dev = devm_input_allocate_device(&pdev->dev);
> + if (!input_dev) {
> + dev_err(&pdev->dev, "failed to allocate input device\n");
> + return -ENOMEM;
> }
>
> kbc->pdata = pdata;
> @@ -735,25 +738,16 @@ static int tegra_kbc_probe(struct platform_device *pdev)
> spin_lock_init(&kbc->lock);
> setup_timer(&kbc->timer, tegra_kbc_keypress_timer, (unsigned long)kbc);
>
> - res = request_mem_region(res->start, resource_size(res), pdev->name);
> - if (!res) {
> - dev_err(&pdev->dev, "failed to request I/O memory\n");
> - err = -EBUSY;
> - goto err_free_mem;
> - }
> -
> - kbc->mmio = ioremap(res->start, resource_size(res));
> + kbc->mmio = devm_request_and_ioremap(&pdev->dev, res);
> if (!kbc->mmio) {
> - dev_err(&pdev->dev, "failed to remap I/O memory\n");
> - err = -ENXIO;
> - goto err_free_mem_region;
> + dev_err(&pdev->dev, "Cannot request memregion/iomap address\n");
> + return -EADDRNOTAVAIL;
Erm, no, -EBUSY please.
> }
>
> - kbc->clk = clk_get(&pdev->dev, NULL);
> + kbc->clk = devm_clk_get(&pdev->dev, NULL);
> if (IS_ERR(kbc->clk)) {
> dev_err(&pdev->dev, "failed to get keyboard clock\n");
> - err = PTR_ERR(kbc->clk);
> - goto err_iounmap;
> + return PTR_ERR(kbc->clk);
> }
>
> /*
> @@ -778,9 +772,9 @@ static int tegra_kbc_probe(struct platform_device *pdev)
> input_dev->close = tegra_kbc_close;
>
> err = tegra_kbd_setup_keymap(kbc);
> - if (err) {
> + if (err < 0) {
Why is this change? As far as I can see tegra_kbd_setup_keymap() never
returns positive values.
> dev_err(&pdev->dev, "failed to setup keymap\n");
> - goto err_put_clk;
> + return err;
> }
>
> __set_bit(EV_REP, input_dev->evbit);
> @@ -790,15 +784,15 @@ static int tegra_kbc_probe(struct platform_device *pdev)
>
> err = request_irq(kbc->irq, tegra_kbc_isr,
> IRQF_NO_SUSPEND | IRQF_TRIGGER_HIGH, pdev->name, kbc);
> - if (err) {
> + if (err < 0) {
Neither request_irq(). BTW, why not devm_request_irq?
> dev_err(&pdev->dev, "failed to request keyboard IRQ\n");
> - goto err_put_clk;
> + return err;
> }
>
> disable_irq(kbc->irq);
>
> err = input_register_device(kbc->idev);
> - if (err) {
> + if (err < 0) {
Again, input_register_device() returns 0 on success.
> dev_err(&pdev->dev, "failed to register input device\n");
> goto err_free_irq;
> }
> @@ -810,46 +804,15 @@ static int tegra_kbc_probe(struct platform_device *pdev)
>
> err_free_irq:
> free_irq(kbc->irq, pdev);
> -err_put_clk:
> - clk_put(kbc->clk);
> -err_iounmap:
> - iounmap(kbc->mmio);
> -err_free_mem_region:
> - release_mem_region(res->start, resource_size(res));
> -err_free_mem:
> - input_free_device(input_dev);
> - kfree(kbc);
> -err_free_pdata:
> - if (!pdev->dev.platform_data)
> - kfree(pdata);
> -
> return err;
> }
>
> static int tegra_kbc_remove(struct platform_device *pdev)
> {
> struct tegra_kbc *kbc = platform_get_drvdata(pdev);
> - struct resource *res;
> -
> - platform_set_drvdata(pdev, NULL);
>
> free_irq(kbc->irq, pdev);
> - clk_put(kbc->clk);
> -
> input_unregister_device(kbc->idev);
You do not need to call input_unregister_device for managed input
devices, and if you switch request_irq to managed variant you can remove
tegra_kbc_remove() altogether.
> - iounmap(kbc->mmio);
> - res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> - release_mem_region(res->start, resource_size(res));
> -
> - /*
> - * If we do not have platform data attached to the device we
> - * allocated it ourselves and thus need to free it.
> - */
> - if (!pdev->dev.platform_data)
> - kfree(kbc->pdata);
> -
> - kfree(kbc);
> -
> return 0;
> }
>
> --
> 1.7.1.1
>
Thanks.
--
Dmitry
next prev parent reply other threads:[~2013-01-05 8:07 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-05 7:45 [PATCH V2 0/4] input: keyboard: tegra: cleanups and DT supports Laxman Dewangan
[not found] ` <1357371910-3164-1-git-send-email-ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-01-05 7:45 ` [PATCH v2 1/4] input: keyboard: tegra: fix build warning Laxman Dewangan
2013-01-05 7:45 ` [PATCH v2 2/4] input: keyboard: tegra: use devm_* for resource allocation Laxman Dewangan
2013-01-05 8:06 ` Dmitry Torokhov [this message]
2013-01-05 11:20 ` Laxman Dewangan
2013-01-05 23:18 ` Dmitry Torokhov
[not found] ` <20130105231858.GD6475-WlK9ik9hQGAhIp7JRqBPierSzoNAToWh@public.gmane.org>
2013-01-06 11:00 ` Laxman Dewangan
[not found] ` <20130105080658.GA1315-WlK9ik9hQGAhIp7JRqBPierSzoNAToWh@public.gmane.org>
2013-01-06 19:27 ` Thierry Reding
2013-01-06 19:57 ` Dmitry Torokhov
2013-01-09 7:07 ` Thierry Reding
2013-01-09 9:19 ` Dmitry Torokhov
[not found] ` <20130109091939.GA4369-WlK9ik9hQGAhIp7JRqBPierSzoNAToWh@public.gmane.org>
2013-01-09 9:23 ` Thierry Reding
2013-01-14 15:49 ` Thierry Reding
2013-01-14 16:16 ` Greg Kroah-Hartman
2013-01-14 22:15 ` Thierry Reding
[not found] ` <20130114221551.GA30020-RM9K5IK7kjIyiCvfTdI0JKcOhU4Rzj621B7CTYaBSLdn68oJJulU0Q@public.gmane.org>
2013-01-14 22:24 ` Arnd Bergmann
[not found] ` <201301142224.11243.arnd-r2nGTMty4D4@public.gmane.org>
2013-01-15 6:44 ` Thierry Reding
2013-01-15 12:32 ` Wolfram Sang
2013-01-15 13:06 ` Wolfram Sang
[not found] ` <20130115130623.GC2625-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2013-01-15 15:44 ` Thierry Reding
2013-01-16 6:35 ` Wolfram Sang
2013-02-09 9:04 ` Grant Likely
2013-01-05 7:45 ` [PATCH v2] input: keyboard: tegra: add support for rows/cols configuration from dt Laxman Dewangan
2013-01-05 7:45 ` [PATCH v2 4/4] input: keyboard: tegra: remove default key mapping Laxman Dewangan
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=20130105080658.GA1315@core.coreip.homeip.net \
--to=dmitry.torokhov@gmail.com \
--cc=devicetree-discuss@lists.ozlabs.org \
--cc=grant.likely@secretlab.ca \
--cc=ldewangan@nvidia.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=rob.herring@calxeda.com \
--cc=swarren@nvidia.com \
/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;
as well as URLs for NNTP newsgroup(s).