From: Markus Elfring <Markus.Elfring@web.de>
To: Kees Cook <kees@kernel.org>, cocci@inria.fr
Subject: Re: [cocci] __free() attribute inhibits matching?
Date: Tue, 18 Mar 2025 18:43:33 +0100 [thread overview]
Message-ID: <d8c968f9-db1e-4127-86dc-e9c42abf0806@web.de> (raw)
In-Reply-To: <202503171135.B1CCC51FA@keescook>
> It seems that the mere presence of the "__free" attribute breaks matching:
>
> $ cat test.c
> static void why(void)
> {
> u64 *rates_64 __free(kfree) = NULL;
> rates_64 = kcalloc(count, sizeof(*rates_64), GFP_KERNEL);
> }
Questionable test result (with the software combination “Coccinelle 1.3-00083-g4093aad2d”):
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> spatch --parse-c example_by_Kees_Cook-20250317.c
…
BAD:!!!!! u64 *rates_64 __free(kfree) = NULL;
…
maybe 10 most problematic tokens
…
NB total files = 1; perfect = 0; pbs = 1; timeout = 0; =========> 0%
nb good = 0, nb passed = 1 =========> 12.50% passed
nb good = 0, nb bad = 7 =========> 12.50% good or passed
> $ cat match.cocci
> @replace@
> expression THING, COUNT;
> expression GFP;
> @@
>
> - kcalloc(COUNT, sizeof(*THING), GFP)
> + kzalloc_objs(*THING, COUNT, GFP)
Would another SmPL code variant be occasionally helpful?
@replacement@
expression THING, COUNT, GFP;
@@
-kcalloc
+kzalloc_objs
(
-COUNT,
-sizeof(
*THING
- )
+, COUNT
, GFP
)
Regards,
Markus
next prev parent reply other threads:[~2025-03-18 17:43 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-17 18:44 [cocci] __free() attribute inhibits matching? Kees Cook
2025-03-17 20:59 ` Julia Lawall
2025-03-17 23:02 ` Kees Cook
2025-03-17 23:13 ` Julia Lawall
2025-03-18 15:39 ` Kees Cook
2025-03-18 15:43 ` Julia Lawall
2025-03-18 16:30 ` Kees Cook
2025-03-18 17:56 ` Julia Lawall
2025-03-19 3:31 ` Kees Cook
2025-03-19 5:55 ` Julia Lawall
2025-03-19 7:20 ` [cocci] Checking the determination of type information? Markus Elfring
2025-03-19 7:44 ` [cocci] __free() attribute inhibits matching? Julia Lawall
2025-03-19 20:06 ` Kees Cook
2025-03-19 21:30 ` Kees Cook
2025-03-19 23:25 ` Julia Lawall
2025-03-21 13:52 ` Markus Elfring
2025-03-19 10:24 ` Markus Elfring
2025-03-19 10:57 ` Markus Elfring
2025-03-18 17:43 ` Markus Elfring [this message]
2025-03-18 18:02 ` Kees Cook
2025-03-18 19:18 ` Markus Elfring
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=d8c968f9-db1e-4127-86dc-e9c42abf0806@web.de \
--to=markus.elfring@web.de \
--cc=cocci@inria.fr \
--cc=kees@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 read-only IMAP folder(s) and NNTP newsgroup(s).