git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 0/4] add and apply a rule to find "unused" init+free

From
Jeff King <peff@peff.net>
Date
Jul 1, 2022, 18:09 UTC
Message-ID
<Yr84aglgBwIvnwC7@coredump.intra.peff.net>
In-Reply-To
<cover-v3-0.4-00000000000-20220701T102506Z-avarab@gmail.com>
On Fri, Jul 01, 2022 at 12:30:55PM +0200, Ævar Arnfjörð Bjarmason wrote:
Show 5 quoted lines
> This series adds a coccinelle rule to find and remove code where the
> only reference to a variable in a given function is to malloc() &
> free() it, where "malloc" and "free" also match
> "strbuf_init/strbuf_release", and then later in the series anything
> that looks like a init/free pattern.
Overall, I hated this much less than I expected to. ;)

My main concern was that we'd have a jumble of init/release rules for every data type, but the regex matching on identifier names lets us do things broadly. And for data types that don't match our usual naming conventions, that seems like a good opportunity to consider changing their names.

I'm not too concerned about false positives here, since there are humans in the loop. The resulting diffs are pretty obvious to review, and a compiler would obviously catch any case where the variable really did get used in between.

I do wish we could do it with the compiler and not coccinelle, just because the latter has been such a source of frustration in terms of performance issues and head-scratching "why didn't it catch this one" cases. But this is IMHO much better than nothing, as shown by the cleanups it already found.

-Peff
Previous: Eric SunshineNext: Ævar Arnfjörð Bjarmason
Message 14 of 24 in “cocci: add and apply a rule to find "unused" variables”
  1. cocci: add and apply a rule to find "unused" variablesÆvar Arnfjörð Bjarmason, May 20, 2022
  2. 0/2 add and apply a rule to find "unused" init+freeÆvar Arnfjörð Bjarmason, Jun 21, 2022
  3. 1/2 cocci: add and apply a rule to find "unused" variablesÆvar Arnfjörð Bjarmason, Jun 21, 2022
  4. Junio C HamanoJun 22, 2022
  5. 2/2 cocci: remove "when strict" from unused.cocciÆvar Arnfjörð Bjarmason, Jun 21, 2022
  6. 0/4 add and apply a rule to find "unused" init+freeÆvar Arnfjörð Bjarmason, Jul 1, 2022
  7. 1/4 cocci: add and apply a rule to find "unused" strbufsÆvar Arnfjörð Bjarmason, Jul 1, 2022
  8. Jeff KingJul 1, 2022
  9. Eric SunshineJul 1, 2022
  10. 2/4 cocci: catch unused "strbuf" using an xmalloc() patternÆvar Arnfjörð Bjarmason, Jul 1, 2022
  11. 4/4 cocci: generalize "unused" rule to cover more than "strbuf"Ævar Arnfjörð Bjarmason, Jul 1, 2022
  12. 3/4 cocci: remove "when strict" from unused.cocciÆvar Arnfjörð Bjarmason, Jul 1, 2022
  13. Eric SunshineJul 1, 2022
  14. Jeff KingJul 1, 2022
  15. 0/6 add and apply a rule to find "unused" init+freeÆvar Arnfjörð Bjarmason, Jul 5, 2022
  16. 2/6 Makefile & .gitignore: ignore & clean "git.res", not "*.res"Ævar Arnfjörð Bjarmason, Jul 5, 2022
  17. 1/6 Makefile: remove mandatory "spatch" arguments from SPATCH_FLAGSÆvar Arnfjörð Bjarmason, Jul 5, 2022
  18. 3/6 cocci: add a "coccicheck-test" target and test *.cocci rulesÆvar Arnfjörð Bjarmason, Jul 5, 2022
  19. 4/6 cocci: have "coccicheck{,-pending}" depend on "coccicheck-test"Ævar Arnfjörð Bjarmason, Jul 5, 2022
  20. 5/6 cocci: add and apply a rule to find "unused" strbufsÆvar Arnfjörð Bjarmason, Jul 5, 2022
  21. 6/6 cocci: generalize "unused" rule to cover more than "strbuf"Ævar Arnfjörð Bjarmason, Jul 5, 2022
  22. Junio C HamanoJul 6, 2022
  23. Jeff KingJul 11, 2022
  24. Ævar Arnfjörð BjarmasonJul 11, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.