From: Lars-Peter Clausen <lars@metafoo.de>
To: Anton Vorontsov <cbouatmailru@gmail.com>
Cc: linux-kernel@vger.kernel.org, Lars-Peter Clausen <lars@metafoo.de>
Subject: [PATCH] POWER: gpio-charger: Fix potential race between irq handler and probe/remove function
Date: Thu, 18 Nov 2010 23:08:38 +0100 [thread overview]
Message-ID: <1290118119-16468-2-git-send-email-lars@metafoo.de> (raw)
In-Reply-To: <1290118119-16468-1-git-send-email-lars@metafoo.de>
This patch fixes a potential race between the irq handler and the probe and
remove functions.
The irq should not be requested before the chargers power_supply has been
registered and has to be freed before the power_supply is unregistered,
otherwise it is possible that the irq fires while the power_supply is not
initialized yet or has already been freed.
While we are at it replace request_irq with request_any_context_irq.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
drivers/power/gpio-charger.c | 28 +++++++++++++---------------
1 files changed, 13 insertions(+), 15 deletions(-)
diff --git a/drivers/power/gpio-charger.c b/drivers/power/gpio-charger.c
index 8458caf..016d5c0 100644
--- a/drivers/power/gpio-charger.c
+++ b/drivers/power/gpio-charger.c
@@ -98,7 +98,7 @@ static int __devinit gpio_charger_probe(struct platform_device *pdev)
charger->type = pdata->type;
charger->properties = gpio_charger_properties;
charger->num_properties = ARRAY_SIZE(gpio_charger_properties);
- charger->get_property = gpio_charger_get_property;
+ charger->get_property = gpio_charger_get_property;
charger->supplied_to = pdata->supplied_to;
charger->num_supplicants = pdata->num_supplicants;
@@ -113,9 +113,17 @@ static int __devinit gpio_charger_probe(struct platform_device *pdev)
goto err_gpio_free;
}
+ gpio_charger->pdata = pdata;
+
+ ret = power_supply_register(&pdev->dev, charger);
+ if (ret < 0) {
+ dev_err(&pdev->dev, "Failed to register power supply: %d\n", ret);
+ goto err_gpio_free;
+ }
+
irq = gpio_to_irq(pdata->gpio);
if (irq > 0) {
- ret = request_irq(irq, gpio_charger_irq,
+ ret = request_any_context_irq(irq, gpio_charger_irq,
IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
dev_name(&pdev->dev), charger);
if (ret)
@@ -124,21 +132,10 @@ static int __devinit gpio_charger_probe(struct platform_device *pdev)
gpio_charger->irq = irq;
}
- gpio_charger->pdata = pdata;
-
- ret = power_supply_register(&pdev->dev, charger);
- if (ret < 0) {
- dev_err(&pdev->dev, "Failed to register power supply: %d\n", ret);
- goto err_irq_free;
- }
-
platform_set_drvdata(pdev, gpio_charger);
return 0;
-err_irq_free:
- if (gpio_charger->irq)
- free_irq(gpio_charger->irq, charger);
err_gpio_free:
gpio_free(pdata->gpio);
err_free:
@@ -150,10 +147,11 @@ static int __devexit gpio_charger_remove(struct platform_device *pdev)
{
struct gpio_charger *gpio_charger = platform_get_drvdata(pdev);
- power_supply_unregister(&gpio_charger->charger);
-
if (gpio_charger->irq)
free_irq(gpio_charger->irq, &gpio_charger->charger);
+
+ power_supply_unregister(&gpio_charger->charger);
+
gpio_free(gpio_charger->pdata->gpio);
platform_set_drvdata(pdev, NULL);
--
1.5.6.5
next prev parent reply other threads:[~2010-11-18 22:09 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-18 22:08 [PATCH] POWER: gpio-charger: Check result of kzalloc Lars-Peter Clausen
2010-11-18 22:08 ` Lars-Peter Clausen [this message]
2010-12-22 0:05 ` [PATCH] POWER: gpio-charger: Fix potential race between irq handler and probe/remove function Anton Vorontsov
2010-11-18 22:08 ` [PATCH] POWER: gpio-chager: Provide default name for the power_supply Lars-Peter Clausen
2010-12-22 0:04 ` Anton Vorontsov
2010-12-22 0:03 ` [PATCH] POWER: gpio-charger: Check result of kzalloc Anton Vorontsov
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=1290118119-16468-2-git-send-email-lars@metafoo.de \
--to=lars@metafoo.de \
--cc=cbouatmailru@gmail.com \
--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
Powered by JetHome