From: Lars-Peter Clausen <lars@metafoo.de>
To: Marcos Paulo de Souza <marcos.souza.org@gmail.com>
Cc: cbou@mail.ru, dwmw2@infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/4] Use devm_request_irq to avoid some checks
Date: Fri, 19 Oct 2012 11:44:50 +0200 [thread overview]
Message-ID: <50812112.2020709@metafoo.de> (raw)
In-Reply-To: <1350603664-18148-4-git-send-email-marcos.souza.org@gmail.com>
On 10/19/2012 01:41 AM, Marcos Paulo de Souza wrote:
> With this we can remove a lot of checks.
>
> Signed-off-by: Marcos Paulo de Souza <marcos.souza.org@gmail.com>
This one is a bit more tricky and the driver currently gets it (partially
wrong). The issue is that since the power supply is referenced in the
interrupt handler, the IRQs should be requested after the power supply has
been registered and be freed before the power supply is unregistered.
So devm can't really be used here. But as I said the current driver already
gets it wrong.
- Lars
> ---
> drivers/power/jz4740-battery.c | 25 ++++++++-----------------
> 1 file changed, 8 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/power/jz4740-battery.c b/drivers/power/jz4740-battery.c
> index 9d9b2a8..b80f7ed 100644
> --- a/drivers/power/jz4740-battery.c
> +++ b/drivers/power/jz4740-battery.c
> @@ -307,8 +307,8 @@ static int __devinit jz_battery_probe(struct platform_device *pdev)
>
> INIT_DELAYED_WORK(&jz_battery->work, jz_battery_work);
>
> - ret = request_irq(jz_battery->irq, jz_battery_irq_handler, 0, pdev->name,
> - jz_battery);
> + ret = devm_request_irq(&pdev->dev, jz_battery->irq, jz_battery_irq_handler,
> + 0, pdev->name, jz_battery);
> if (ret) {
> dev_err(&pdev->dev, "Failed to request irq %d\n", ret);
> goto err;
> @@ -319,7 +319,7 @@ static int __devinit jz_battery_probe(struct platform_device *pdev)
> ret = gpio_request(pdata->gpio_charge, dev_name(&pdev->dev));
> if (ret) {
> dev_err(&pdev->dev, "charger state gpio request failed.\n");
> - goto err_free_irq;
> + goto err;
> }
> ret = gpio_direction_input(pdata->gpio_charge);
> if (ret) {
> @@ -330,7 +330,8 @@ static int __devinit jz_battery_probe(struct platform_device *pdev)
> jz_battery->charge_irq = gpio_to_irq(pdata->gpio_charge);
>
> if (jz_battery->charge_irq >= 0) {
> - ret = request_irq(jz_battery->charge_irq,
> + ret = devm_request_irq(&pdev->dev,
> + jz_battery->charge_irq,
> jz_battery_charge_irq,
> IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
> dev_name(&pdev->dev), jz_battery);
> @@ -352,7 +353,7 @@ static int __devinit jz_battery_probe(struct platform_device *pdev)
> ret = power_supply_register(&pdev->dev, &jz_battery->battery);
> if (ret) {
> dev_err(&pdev->dev, "power supply battery register failed.\n");
> - goto err_free_charge_irq;
> + goto err_free_gpio;
> }
>
> platform_set_drvdata(pdev, jz_battery);
> @@ -360,16 +361,11 @@ static int __devinit jz_battery_probe(struct platform_device *pdev)
>
> return 0;
>
> -err_free_charge_irq:
> - if (jz_battery->charge_irq >= 0)
> - free_irq(jz_battery->charge_irq, jz_battery);
> err_free_gpio:
> if (gpio_is_valid(pdata->gpio_charge))
> gpio_free(jz_battery->pdata->gpio_charge);
> -err_free_irq:
> - free_irq(jz_battery->irq, jz_battery);
> - platform_set_drvdata(pdev, NULL);
> err:
> + platform_set_drvdata(pdev, NULL);
> return ret;
> }
>
> @@ -379,16 +375,11 @@ static int __devexit jz_battery_remove(struct platform_device *pdev)
>
> cancel_delayed_work_sync(&jz_battery->work);
>
> - if (gpio_is_valid(jz_battery->pdata->gpio_charge)) {
> - if (jz_battery->charge_irq >= 0)
> - free_irq(jz_battery->charge_irq, jz_battery);
> + if (gpio_is_valid(jz_battery->pdata->gpio_charge))
> gpio_free(jz_battery->pdata->gpio_charge);
> - }
>
> power_supply_unregister(&jz_battery->battery);
>
> - free_irq(jz_battery->irq, jz_battery);
> -
> return 0;
> }
>
next prev parent reply other threads:[~2012-10-19 9:43 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-18 23:41 [PATCH 0/4] driver/power/jz4740-battery: driver cleanup Marcos Paulo de Souza
2012-10-18 23:41 ` [PATCH 1/4] Use devm_kzalloc instead of kzalloc/kfree Marcos Paulo de Souza
2012-10-19 9:21 ` Lars-Peter Clausen
2012-10-18 23:41 ` [PATCH 2/4] Use devm_* for request_mem_region and ioremap Marcos Paulo de Souza
2012-10-19 9:25 ` Lars-Peter Clausen
2012-10-18 23:41 ` [PATCH 3/4] Use devm_request_irq to avoid some checks Marcos Paulo de Souza
2012-10-19 9:44 ` Lars-Peter Clausen [this message]
2012-10-19 14:44 ` Marcos Souza
2012-10-19 16:05 ` Lars-Peter Clausen
2012-10-18 23:41 ` [PATCH 4/4] power/jz4740.c: Simplify exit of function Marcos Paulo de Souza
2012-10-19 12:15 ` Lars-Peter Clausen
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=50812112.2020709@metafoo.de \
--to=lars@metafoo.de \
--cc=cbou@mail.ru \
--cc=dwmw2@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcos.souza.org@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.