* [PATCH] scripts: coccinelle: kfree with TRACE_RET before ref is ok (resent)
@ 2014-07-22 10:12 Nicholas Mc Guire
2014-07-22 13:51 ` Bjørn Mork
0 siblings, 1 reply; 2+ messages in thread
From: Nicholas Mc Guire @ 2014-07-22 10:12 UTC (permalink / raw)
To: Michal Marek
Cc: Julia Lawall, Gilles Muller, Nicolas Palix, cocci, linux-kernel
kfree.cocci currently triggers on constructs like
(resending with proper CC list and subject line)
drivers/staging/rts5208/spi.c
596 if (retval < 0) {
597 kfree(buf);
598 rtsx_clear_spi_error(chip);
599 spi_set_err_code(chip, SPI_HW_ERR);
600 TRACE_RET(chip, STATUS_FAIL);
601 }
602
603 rtsx_stor_access_xfer_buf(buf, pagelen, srb, &index, &offset,
TO_XFER_BUF);
with:
./drivers/staging/rts5208/spi.c:603:28-31: ERROR: reference preceded
by free on line 597
but this should be fine - so TRACE_RET is added to the list of calls
"protecting" access to freed objects see drivers/staging/rts5208/trace.h
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Nicholas Mc Guire <der.herr@hofr.at>
---
scripts/coccinelle/free/kfree.cocci | 2 ++
1 file changed, 2 insertions(+)
diff --git a/scripts/coccinelle/free/kfree.cocci b/scripts/coccinelle/free/kfree.cocci
index 577b780..04d3f4f 100644
--- a/scripts/coccinelle/free/kfree.cocci
+++ b/scripts/coccinelle/free/kfree.cocci
@@ -101,6 +101,8 @@ kfree@p1(E,...)
|
return_ACPI_STATUS(...)
|
+ TRACE_RET(...)
+|
E@p2 // bad use
)
--
1.7.10.4
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] scripts: coccinelle: kfree with TRACE_RET before ref is ok (resent)
2014-07-22 10:12 [PATCH] scripts: coccinelle: kfree with TRACE_RET before ref is ok (resent) Nicholas Mc Guire
@ 2014-07-22 13:51 ` Bjørn Mork
0 siblings, 0 replies; 2+ messages in thread
From: Bjørn Mork @ 2014-07-22 13:51 UTC (permalink / raw)
To: Nicholas Mc Guire
Cc: Michal Marek, Julia Lawall, Gilles Muller, Nicolas Palix, cocci,
linux-kernel
Nicholas Mc Guire <der.herr@hofr.at> writes:
> kfree.cocci currently triggers on constructs like
> (resending with proper CC list and subject line)
>
> drivers/staging/rts5208/spi.c
> 596 if (retval < 0) {
> 597 kfree(buf);
> 598 rtsx_clear_spi_error(chip);
> 599 spi_set_err_code(chip, SPI_HW_ERR);
> 600 TRACE_RET(chip, STATUS_FAIL);
> 601 }
> 602
> 603 rtsx_stor_access_xfer_buf(buf, pagelen, srb, &index, &offset,
> TO_XFER_BUF);
>
> with:
>
> ./drivers/staging/rts5208/spi.c:603:28-31: ERROR: reference preceded
> by free on line 597
>
> but this should be fine - so TRACE_RET is added to the list of calls
> "protecting" access to freed objects see drivers/staging/rts5208/trace.h
The TRACE_RET macro is a serious coding style violation. Fix that and
the error will go away. Don't change scripts to hide issues with the
code. The code above won't just trigger an error in kfree.cocci but also
in the head of any sane person.
>From Documentation/CodingStyle:
<quote>
Things to avoid when using macros:
1) macros that affect control flow:
#define FOO(x) \
do { \
if (blah(x) < 0) \
return -EBUGGERED; \
} while(0)
is a _very_ bad idea. It looks like a function call but exits the "calling"
function; don't break the internal parsers of those who will read the code.
</quote>
Bjørn
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-07-22 13:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-22 10:12 [PATCH] scripts: coccinelle: kfree with TRACE_RET before ref is ok (resent) Nicholas Mc Guire
2014-07-22 13:51 ` Bjørn Mork
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox