From: Julia Lawall <julia.lawall@lip6.fr>
To: Anton Vorontsov <anton@enomsg.org>
Cc: kernel-janitors@vger.kernel.org,
David Woodhouse <dwmw2@infradead.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH] drivers/power/88pm860x_battery.c: eliminate possible references to released resources
Date: Sun, 6 Jan 2013 09:43:10 +0100 (CET) [thread overview]
Message-ID: <alpine.DEB.2.02.1301060941400.2070@localhost6.localdomain6> (raw)
In-Reply-To: <20130106050953.GH6919@lizard.sbx05280.losalca.wayport.net>
From: Julia Lawall <Julia.Lawall@lip6.fr>
devm_kzalloc should not be followed by kfree, as this results in a double
free. The problem was found using the following semantic match
(http://coccinelle.lip6.fr/):
// <smpl>
@@
expression x,e;
@@
x = devm_kzalloc(...)
... when != x = e
?-kfree(x,...);
// </smpl>
Furthermore, in the remove function, the calls to free_irq are moved up to
prevent a possible reference in the interrupt handler to resources freed by
power_supply_unregister.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
---
V2, moving up the calls to free_irq, instead of removing them and using
devm_request_threaded_irq.
drivers/power/88pm860x_battery.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/drivers/power/88pm860x_battery.c b/drivers/power/88pm860x_battery.c
index 8bc80b0..d338c1c 100644
--- a/drivers/power/88pm860x_battery.c
+++ b/drivers/power/88pm860x_battery.c
@@ -915,15 +915,13 @@ static int pm860x_battery_probe(struct platform_device *pdev)
info->irq_cc = platform_get_irq(pdev, 0);
if (info->irq_cc <= 0) {
dev_err(&pdev->dev, "No IRQ resource!\n");
- ret = -EINVAL;
- goto out;
+ return -EINVAL;
}
info->irq_batt = platform_get_irq(pdev, 1);
if (info->irq_batt <= 0) {
dev_err(&pdev->dev, "No IRQ resource!\n");
- ret = -EINVAL;
- goto out;
+ return -EINVAL;
}
info->chip = chip;
@@ -957,7 +955,7 @@ static int pm860x_battery_probe(struct platform_device *pdev)
ret = power_supply_register(&pdev->dev, &info->battery);
if (ret)
- goto out;
+ return ret;
info->battery.dev->parent = &pdev->dev;
ret = request_threaded_irq(info->irq_cc, NULL,
@@ -984,8 +982,6 @@ out_coulomb:
free_irq(info->irq_cc, info);
out_reg:
power_supply_unregister(&info->battery);
-out:
- kfree(info);
return ret;
}
@@ -993,10 +989,9 @@ static int pm860x_battery_remove(struct platform_device *pdev)
{
struct pm860x_battery_info *info = platform_get_drvdata(pdev);
- power_supply_unregister(&info->battery);
free_irq(info->irq_batt, info);
free_irq(info->irq_cc, info);
- kfree(info);
+ power_supply_unregister(&info->battery);
platform_set_drvdata(pdev, NULL);
return 0;
}
next prev parent reply other threads:[~2013-01-06 8:43 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-08 17:16 [PATCH] drivers/power/88pm860x_battery.c: use devm_request_threaded_irq Julia Lawall
2013-01-06 5:09 ` Anton Vorontsov
2013-01-06 8:41 ` Julia Lawall
2013-01-06 8:43 ` Julia Lawall [this message]
2013-01-06 21:16 ` [PATCH] drivers/power/88pm860x_battery.c: eliminate possible references to released resources Anton Vorontsov
2013-01-07 6:42 ` Dan Carpenter
2013-01-07 6:48 ` Julia Lawall
2013-01-07 6:53 ` Anton Vorontsov
2013-01-07 7:09 ` Dan Carpenter
2013-01-07 8:00 ` Julia Lawall
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=alpine.DEB.2.02.1301060941400.2070@localhost6.localdomain6 \
--to=julia.lawall@lip6.fr \
--cc=anton@enomsg.org \
--cc=dwmw2@infradead.org \
--cc=kernel-janitors@vger.kernel.org \
--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
all inboxes | Powered by JetHome®