Commit 26eb3872 authored by Lars-Peter Clausen's avatar Lars-Peter Clausen Committed by Anton Vorontsov

gpio-charger: Fix potential race between irq handler and probe/remove

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: default avatarLars-Peter Clausen <lars@metafoo.de>
Signed-off-by: default avatarAnton Vorontsov <cbouatmailru@gmail.com>
parent 80577b8a
...@@ -98,7 +98,7 @@ static int __devinit gpio_charger_probe(struct platform_device *pdev) ...@@ -98,7 +98,7 @@ static int __devinit gpio_charger_probe(struct platform_device *pdev)
charger->type = pdata->type; charger->type = pdata->type;
charger->properties = gpio_charger_properties; charger->properties = gpio_charger_properties;
charger->num_properties = ARRAY_SIZE(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->supplied_to = pdata->supplied_to;
charger->num_supplicants = pdata->num_supplicants; charger->num_supplicants = pdata->num_supplicants;
...@@ -113,9 +113,18 @@ static int __devinit gpio_charger_probe(struct platform_device *pdev) ...@@ -113,9 +113,18 @@ static int __devinit gpio_charger_probe(struct platform_device *pdev)
goto err_gpio_free; 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); irq = gpio_to_irq(pdata->gpio);
if (irq > 0) { 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, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
dev_name(&pdev->dev), charger); dev_name(&pdev->dev), charger);
if (ret) if (ret)
...@@ -124,21 +133,10 @@ static int __devinit gpio_charger_probe(struct platform_device *pdev) ...@@ -124,21 +133,10 @@ static int __devinit gpio_charger_probe(struct platform_device *pdev)
gpio_charger->irq = irq; 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); platform_set_drvdata(pdev, gpio_charger);
return 0; return 0;
err_irq_free:
if (gpio_charger->irq)
free_irq(gpio_charger->irq, charger);
err_gpio_free: err_gpio_free:
gpio_free(pdata->gpio); gpio_free(pdata->gpio);
err_free: err_free:
...@@ -150,10 +148,11 @@ static int __devexit gpio_charger_remove(struct platform_device *pdev) ...@@ -150,10 +148,11 @@ static int __devexit gpio_charger_remove(struct platform_device *pdev)
{ {
struct gpio_charger *gpio_charger = platform_get_drvdata(pdev); struct gpio_charger *gpio_charger = platform_get_drvdata(pdev);
power_supply_unregister(&gpio_charger->charger);
if (gpio_charger->irq) if (gpio_charger->irq)
free_irq(gpio_charger->irq, &gpio_charger->charger); free_irq(gpio_charger->irq, &gpio_charger->charger);
power_supply_unregister(&gpio_charger->charger);
gpio_free(gpio_charger->pdata->gpio); gpio_free(gpio_charger->pdata->gpio);
platform_set_drvdata(pdev, NULL); platform_set_drvdata(pdev, NULL);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment