drivers/isdn/gigaset/common.c: Remove useless kfree
Subsystems (3)
PATCH 9/9 drivers/isdn/gigaset/common.c: Remove useless kfree
From: Peter Senna Tschudin <[email protected]>
Remove useless kfree() and clean up code related to the removal.
The semantic patch that finds this problem is as follows:
(http://coccinelle.lip6.fr/)
// <smpl>
@r exists@
position p1,p2;
expression x;
@@
if (x@p1 = NULL) { ... kfree@p2(x); ... return ...; }
@unchanged exists@
position r.p1,r.p2;
expression e <= r.x,x,e1;
iterator I;
statement S;
@@
if (x@p1 = NULL) { ... when != I(x,...) S
when != e = e1
when != e += e1
when != e -= e1
when != ++e
when != --e
when != e++
when != e--
when != &ekfree@p2(x); ... return ...; }
@ok depends on unchanged exists@
position any r.p1;
position r.p2;
expression x;
@@
... when != true x@p1 = NULL
kfree@p2(x);
@depends on !ok && unchanged@
position r.p2;
expression x;
@@
*kfree@p2(x);
// </smpl>
--- drivers/isdn/gigaset/common.c | 1 - 1 file changed, 1 deletion(-)
drivers/isdn/gigaset/common.c +0 -1
@@ -1123,7 +1123,6 @@ struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,return drv; error: -kfree (drv->cs);kfree (drv);return NULL ; }
Quoted 1 line
Remove useless
kfree()and clean up code related to the removal.
...
drivers/isdn/gigaset/common.c struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors, · line 1128
Quoted 13 lines
drivers/isdn/gigaset/common.c +0
-1@@ -1123,7 +1123,6 @@ struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,return drv; error: -kfree (drv->cs);kfree (drv);return NULL ; }
Seems to me that (assuming kfree(NULL) is ok) the kfree() is best left in - just in case some other error path is added after drv->cs is assigned.
Better safe than a memory leak.
David
Quoted 9 lines · David Laight
Quoted 1 line
Remove useless
kfree()and clean up code related to the removal....
Quoted 7 lines
drivers/isdn/gigaset/common.c +0
-0@@ -1123,7 +1123,6 @@ struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,return drv;
Quoted 11 lines
drivers/isdn/gigaset/common.c struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors, · line 1128
Quoted 6 lines
drivers/isdn/gigaset/common.c +0
-1error: -kfree (drv->cs);kfree (drv);return NULL ; }Seems to me that (assuming kfree(NULL) is ok) the
kfree()is best left in - just in case some other error path is added afterdrv->csis assigned.
Better safe than a memory leak.
No. Delete vestigial code. There are all kinds of no-ops we could add to the unwind bits of code if we wanted to so why is "drv->cs" better than anything else.
First of all, no one is going to change the ISDN code to add an allocation, but if they did then they have to make sure they don't leak memory. That's how it always works. They can't just assume that there is going to be a forgotten kfree() hanging off to the side which is going to take care of it.
regards,
dan carpenter
Quoted 4 lines
Seems to me that (assuming kfree(NULL) is ok) the
kfree()is best left in - just in case some other error path is added afterdrv->csis assigned.
Better safe than a memory leak.
I'm not sure if I got your point. Now the label "error:" is only reached if drv->cs is NULL. There is not other way to move to error:
unless drv->cs is NULL. Why wouldn't be safe to remove the kfree(drv->cs) when drv->cs is NULL?
Signature · 1 line
Peter
Am 12.09.2012 17:06, schrieb Peter Senna Tschudin:
Quoted 5 lines
From: Peter Senna Tschudin <[email protected]>
Remove useless
kfree()and clean up code related to the removal.The semantic patch that finds this problem is as follows:
[...]
Quoted 2 lines
Signed-off-by Peter Senna Tschudin <[email protected]>
Quoted 9 lines
--- drivers/isdn/gigaset/common.c | 1 - 1 file changed, 1 deletion(-)drivers/isdn/gigaset/common.c +0
-0
drivers/isdn/gigaset/common.c struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors, · line 1128
Quoted 7 lines
drivers/isdn/gigaset/common.c +0
-1@@ -1123,7 +1123,6 @@ struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,return drv; error: -kfree (drv->cs);kfree (drv);return NULL ; }
This is indeed vestigial code, left in when another error path that needed it was removed. Though innocuous, it's better to remove it.
Thanks,
Tilman
Signature · 4 lines
Tilman Schmidt E-Mail: [email protected] Bonn, Germany Diese Nachricht besteht zu 100% aus wiederverwerteten Bits. Ungeöffnet mindestens haltbar bis: (siehe Rückseite)
From: Tilman Schmidt <[email protected]>
Date: Thu, 13 Sep 2012 11:52:27 +0200
Quoted 11 lines
Am 12.09.2012 17:06, schrieb Peter Senna Tschudin:
Quoted 5 lines
From: Peter Senna Tschudin <[email protected]>
Remove useless
kfree()and clean up code related to the removal.The semantic patch that finds this problem is as follows:
[...]
Quoted 2 lines
Signed-off-by Peter Senna Tschudin <[email protected]>Acked-by Tilman Schmidt <[email protected]>
Applied to net-next, thanks.