From: Julia Lawall <julia@diku.dk>
To: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org,
linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: [PATCH 2/2] Eliminate double kfree
Date: Thu, 29 May 2008 15:05:07 +0200 (CEST) [thread overview]
Message-ID: <Pine.LNX.4.64.0805291504400.26229@ask.diku.dk> (raw)
From: Julia Lawall <julia@diku.dk>
The variable report is only non-NULL and non-freed in a small region of
code, so it should only be freed in error handling code that comes from
that region.
This was found using the following semantic match.
(http://www.emn.fr/x-info/coccinelle/)
// <smpl>
@r1@
expression E;
position p1,p2;
@@
kfree@p1(E);
...
kfree@p2(E);
@subexps@
expression E1;
position r1.p1,p;
@@
kfree@p1(<+... E1@p ...+>);
@recollect@
position subexps.p;
expression E1;
@@
E1@p
@doublekfree@
position r1.p1,r1.p2;
expression recollect.E1,E2,E;
position p;
statement S;
@@
kfree@p1(E);
<+... E1@p=E2 ...+> // the actual semantic match contains other assignments
kfree@p2(E);
@notdoublekfree@
position r1.p1,r1.p2;
position any doublekfree.p;
expression E,E1,E2;
@@
* kfree@p1(E);
... when != E1@p
when != E1@p = E2 // needed to match a variable decl
* kfree@p2(E);
// </smpl>
Signed-off-by: Julia Lawall <julia@diku.dk>
---
diff -u -p a/drivers/input/tablet/gtco.c b/drivers/input/tablet/gtco.c
--- a/drivers/input/tablet/gtco.c 2008-05-09 16:46:57.000000000 +0200
+++ b/drivers/input/tablet/gtco.c 2008-05-29 14:12:31.000000000 +0200
@@ -926,7 +926,7 @@ static int gtco_probe(struct usb_interfa
err("Failed to get HID Report Descriptor of size: %d",
hid_desc->wDescriptorLength);
error = -EIO;
- goto err_free_urb;
+ goto err_free_report;
}
/* Now we parse the report */
@@ -982,13 +982,14 @@ static int gtco_probe(struct usb_interfa
return 0;
+ err_free_report:
+ kfree(report);
err_free_urb:
usb_free_urb(gtco->urbinfo);
err_free_buf:
usb_buffer_free(gtco->usbdev, REPORT_MAX_SIZE,
gtco->buffer, gtco->buf_dma);
err_free_devs:
- kfree(report);
input_free_device(input_dev);
kfree(gtco);
return error;
next reply other threads:[~2008-05-29 13:05 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-29 13:05 Julia Lawall [this message]
2008-05-29 15:33 ` [PATCH 2/2] Eliminate double kfree Dmitry Torokhov
2008-05-29 15:57 ` Julia Lawall
2008-05-29 16:14 ` Dmitry Torokhov
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=Pine.LNX.4.64.0805291504400.26229@ask.diku.dk \
--to=julia@diku.dk \
--cc=dmitry.torokhov@gmail.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-input@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;
as well as URLs for NNTP newsgroup(s).