* [PATCH] drivers/i2c/i2c-smbus.c: convert kzalloc to devm_kzalloc
@ 2012-08-04 17:10 Julia Lawall
[not found] ` <1344100248-16238-1-git-send-email-Julia.Lawall-L2FTfq7BK8M@public.gmane.org>
0 siblings, 1 reply; 2+ messages in thread
From: Julia Lawall @ 2012-08-04 17:10 UTC (permalink / raw)
To: Jean Delvare
Cc: kernel-janitors-u79uwXL29TY76Z2rM5mHXA,
Ben Dooks (embedded platforms), Wolfram Sang (embedded platforms),
linux-i2c-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
From: Julia Lawall <Julia.Lawall-L2FTfq7BK8M@public.gmane.org>
Converting kzalloc to devm_kzalloc simplifies the code and ensures that the
result, alert, is freed after the irq allocated by the subsequent
devm_request_irq. This in turn ensures that when an interrupt can be
triggered, the alert structure is still available.
The problem of a free after a devm_request_irq was found using the
following semantic match (http://coccinelle.lip6.fr/)
// <smpl>
@r exists@
expression e1,e2,x,a,b,c,d;
identifier free;
position p1,p2;
@@
devm_request_irq@p1(e1,e2,...,x)
... when any
when != e2 = a
when != x = b
if (...) {
... when != e2 = c
when != x = d
free@p2(...,x,...);
...
return ...;
}
// </smpl>
Signed-off-by: Julia Lawall <Julia.Lawall-L2FTfq7BK8M@public.gmane.org>
---
drivers/i2c/i2c-smbus.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/drivers/i2c/i2c-smbus.c b/drivers/i2c/i2c-smbus.c
index df3e0bf..50a36cf 100644
--- a/drivers/i2c/i2c-smbus.c
+++ b/drivers/i2c/i2c-smbus.c
@@ -142,7 +142,8 @@ static int smbalert_probe(struct i2c_client *ara,
struct i2c_adapter *adapter = ara->adapter;
int res;
- alert = kzalloc(sizeof(struct i2c_smbus_alert), GFP_KERNEL);
+ alert = devm_kzalloc(&ara->dev, sizeof(struct i2c_smbus_alert),
+ GFP_KERNEL);
if (!alert)
return -ENOMEM;
@@ -154,10 +155,8 @@ static int smbalert_probe(struct i2c_client *ara,
if (setup->irq > 0) {
res = devm_request_irq(&ara->dev, setup->irq, smbalert_irq,
0, "smbus_alert", alert);
- if (res) {
- kfree(alert);
+ if (res)
return res;
- }
}
i2c_set_clientdata(ara, alert);
@@ -167,14 +166,12 @@ static int smbalert_probe(struct i2c_client *ara,
return 0;
}
-/* IRQ resource is managed so it is freed automatically */
+/* IRQ resource and alert are managed so they are freed automatically */
static int smbalert_remove(struct i2c_client *ara)
{
struct i2c_smbus_alert *alert = i2c_get_clientdata(ara);
cancel_work_sync(&alert->alert);
-
- kfree(alert);
return 0;
}
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-08-04 19:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-04 17:10 [PATCH] drivers/i2c/i2c-smbus.c: convert kzalloc to devm_kzalloc Julia Lawall
[not found] ` <1344100248-16238-1-git-send-email-Julia.Lawall-L2FTfq7BK8M@public.gmane.org>
2012-08-04 19:43 ` Jean Delvare
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).