staging: unisys: visorchannel: Improved cleanup code
kfree on NULL pointer is a no-op. This patch used the following semantic patch to find an instance where NULL check is present before kfree // <smpl> @@ expression E; @@ - if (E != NULL) { kfree(E); } + kfree(E); @@ expression E; @@ - if (E != NULL) { kfree(E); E = NULL; } + kfree(E); + E = NULL; // </smpl> Code is made more simpler by breaking up of sequence of kmallocs and adding some more exit labels. Removed unnecessary initialization of buf and fmtbuf to NULL as they are local variables. Suggested-by: Arnd Bergmann <arnd@arndb.de> Suggested-by: Julia Lawall <julia.lawall@lip6.fr> Signed-off-by: Tapasweni Pathak <tapaswenipathak@gmail.com> Acked-by: Julia Lawall <julia.lawall@lip6.fr> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
a707edd236
commit
be40a5e29e
1 changed files with 9 additions and 12 deletions
|
@ -650,15 +650,17 @@ visorchannel_dump_section(VISORCHANNEL *chan, char *s,
|
|||
|
||||
fmtbufsize = 100 * COVQ(len, 16);
|
||||
buf = kmalloc(len, GFP_KERNEL|__GFP_NORETRY);
|
||||
if (!buf)
|
||||
return;
|
||||
fmtbuf = kmalloc(fmtbufsize, GFP_KERNEL|__GFP_NORETRY);
|
||||
if (buf == NULL || fmtbuf == NULL)
|
||||
goto Away;
|
||||
if (!fmtbuf)
|
||||
goto fmt_failed;
|
||||
|
||||
errcode = visorchannel_read(chan, off, buf, len);
|
||||
if (errcode < 0) {
|
||||
ERRDRV("%s failed to read %s from channel errcode=%d",
|
||||
s, __func__, errcode);
|
||||
goto Away;
|
||||
goto read_failed;
|
||||
}
|
||||
seq_printf(seq, "channel %s:\n", s);
|
||||
tbuf = buf;
|
||||
|
@ -670,14 +672,9 @@ visorchannel_dump_section(VISORCHANNEL *chan, char *s,
|
|||
len -= 16;
|
||||
}
|
||||
|
||||
Away:
|
||||
if (buf != NULL) {
|
||||
kfree(buf);
|
||||
buf = NULL;
|
||||
}
|
||||
if (fmtbuf != NULL) {
|
||||
kfree(fmtbuf);
|
||||
fmtbuf = NULL;
|
||||
}
|
||||
read_failed:
|
||||
kfree(fmtbuf);
|
||||
fmt_failed:
|
||||
kfree(buf);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(visorchannel_dump_section);
|
||||
|
|
Loading…
Reference in a new issue