Linux wireless drivers development
 help / color / mirror / Atom feed
From: Jiazi Li <jqqlijiazi@gmail.com>
To: Kees Cook <kees@kernel.org>, Andy Shevchenko <andy@kernel.org>,
	Ping-Ke Shih <pkshih@realtek.com>,
	Julia Lawall <Julia.Lawall@inria.fr>,
	Nicolas Palix <nicolas.palix@imag.fr>
Cc: Jiazi Li <jqqlijiazi@gmail.com>,
	linux-hardening@vger.kernel.org, linux-wireless@vger.kernel.org
Subject: [PATCH v3 3/3] coccinelle: Add rules to find str_alloc_free() replacements
Date: Thu,  7 May 2026 19:04:11 +0800	[thread overview]
Message-ID: <ecd2beefca98bceead680c4bd3c5df684472b69b.1778051552.git.jqqlijiazi@gmail.com> (raw)
In-Reply-To: <cover.1778051552.git.jqqlijiazi@gmail.com>

Add rules for finding places where str_alloc_free()/str_free_alloc
can be used.

Tested-by mingzhu.wang <mingzhu.wang@transsion.com>
Signed-off-by: Jiazi Li <jqqlijiazi@gmail.com>
---
 scripts/coccinelle/api/string_choices.cocci | 38 +++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/scripts/coccinelle/api/string_choices.cocci b/scripts/coccinelle/api/string_choices.cocci
index 7b2b76a42acc..516b30828380 100644
--- a/scripts/coccinelle/api/string_choices.cocci
+++ b/scripts/coccinelle/api/string_choices.cocci
@@ -7,6 +7,44 @@ virtual patch
 virtual context
 virtual report
 
+@str_alloc_free depends on patch disable neg_if_exp@
+expression E;
+@@
+-      ((E) ? "alloc" : "free")
++      str_alloc_free(E)
+
+@str_alloc_free_r depends on !patch disable neg_if_exp@
+expression E;
+position P;
+@@
+*      E@P ? "alloc" : "free"
+
+@script:python depends on report@
+p << str_alloc_free_r.P;
+e << str_alloc_free_r.E;
+@@
+
+coccilib.report.print_report(p[0], "opportunity for str_alloc_free(%s)" % e)
+
+@str_free_alloc depends on patch disable neg_if_exp@
+expression E;
+@@
+-      ((E) ? "free" : "alloc")
++      str_free_alloc(E)
+
+@str_free_alloc_r depends on !patch disable neg_if_exp@
+expression E;
+position P;
+@@
+*      E@P ? "free" : "alloc"
+
+@script:python depends on report@
+p << str_free_alloc_r.P;
+e << str_free_alloc_r.E;
+@@
+
+coccilib.report.print_report(p[0], "opportunity for str_free_alloc(%s)" % e)
+
 @str_enable_disable depends on patch@
 expression E;
 @@
-- 
2.49.0


  parent reply	other threads:[~2026-05-07 11:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-07 11:03 [PATCH v3 0/3] Add str_alloc_free() helper Jiazi Li
2026-05-07 11:03 ` [PATCH v3 1/3] lib/string_choices: " Jiazi Li
2026-05-08  5:18   ` Greg KH
2026-05-07 11:03 ` [PATCH v3 2/3] wifi: rtw89: Make use of str_alloc_free helper Jiazi Li
2026-05-07 11:04 ` Jiazi Li [this message]
2026-05-07 11:10 ` [PATCH v3 0/3] Add str_alloc_free() helper Johannes Berg
2026-05-11 19:31   ` Kees Cook

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=ecd2beefca98bceead680c4bd3c5df684472b69b.1778051552.git.jqqlijiazi@gmail.com \
    --to=jqqlijiazi@gmail.com \
    --cc=Julia.Lawall@inria.fr \
    --cc=andy@kernel.org \
    --cc=kees@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=nicolas.palix@imag.fr \
    --cc=pkshih@realtek.com \
    /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