From: Markus Elfring <Markus.Elfring@web.de>
To: cocci@inria.fr, kernel-janitors@vger.kernel.org,
Julia Lawall <Julia.Lawall@inria.fr>,
Nicolas Palix <nicolas.palix@imag.fr>
Cc: LKML <linux-kernel@vger.kernel.org>, Kunwu Chan <chentao@kylinos.cn>
Subject: [PATCH v2] Coccinelle: api: Add SmPL script “use_KMEM_CACHE.cocci”
Date: Fri, 2 Feb 2024 10:12:11 +0100 [thread overview]
Message-ID: <b08603d6-cac1-4876-a56c-30c680d5dc52@web.de> (raw)
In-Reply-To: <8d53ac92-9693-4ff9-948c-29b7fb252b89@web.de>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 2 Feb 2024 09:48:11 +0100
A wrapper macro is available since the commit 0a31bd5f2bbb6473ef9d24f0063ca91cfa678b64
("KMEM_CACHE(): simplify slab cache creation").
Provide design options for the adjustment of affected source code
by the means of the semantic patch language (Coccinelle software).
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
v2:
* The reference for the previous commit was adjusted in
the patch description.
* A constraint was added for the metavariable “text”
also based on information in a hint by Julia Lawall from 2018-02-17.
[Cocci] Clarification for scripted SmPL constraints
https://lore.kernel.org/cocci/alpine.DEB.2.20.1802171531330.2205@hadrien/
scripts/coccinelle/api/use_KMEM_CACHE.cocci | 53 +++++++++++++++++++++
1 file changed, 53 insertions(+)
create mode 100644 scripts/coccinelle/api/use_KMEM_CACHE.cocci
diff --git a/scripts/coccinelle/api/use_KMEM_CACHE.cocci b/scripts/coccinelle/api/use_KMEM_CACHE.cocci
new file mode 100644
index 000000000000..e158e4c7c1d1
--- /dev/null
+++ b/scripts/coccinelle/api/use_KMEM_CACHE.cocci
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0
+/// Simplify a function call by using a known wrapper macro.
+//
+// Keywords: wrapper macro conversion cache creation
+// Confidence: High
+// Options: --no-includes --include-headers
+
+virtual context, patch, report, org
+
+@initialize:python@
+@@
+def is_equal(text, id):
+ return True if text[1:-1] == id else False
+
+@depends on context disable sizeof_type_expr@
+expression alignment, flags;
+identifier id;
+constant char[] text: script:python(id) { is_equal(text, id) };
+@@
+*kmem_cache_create(text, sizeof(struct id), alignment, flags, NULL)
+
+@depends on patch disable sizeof_type_expr@
+expression alignment, flags;
+identifier id;
+constant char[] text: script:python(id) { is_equal(text, id) };
+@@
+-kmem_cache_create
++KMEM_CACHE
+ (
+-text, sizeof(struct
+ id
+-), alignment
+ , flags
+-, NULL
+ )
+
+@x depends on org || report disable sizeof_type_expr@
+expression alignment, flags;
+identifier id;
+constant char[] text: script:python(id) { is_equal(text, id) };
+position p;
+@@
+ kmem_cache_create@p(text, sizeof(struct id), alignment, flags, NULL)
+
+@script:python depends on org@
+p << x.p;
+@@
+coccilib.org.print_todo(p[0], "WARNING: opportunity for KMEM_CACHE()")
+
+@script:python depends on report@
+p << x.p;
+@@
+coccilib.report.print_report(p[0], "WARNING: opportunity for KMEM_CACHE()")
--
2.43.0
prev parent reply other threads:[~2024-02-02 9:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-24 18:09 [PATCH] " Markus Elfring
2024-02-02 9:12 ` Markus Elfring [this message]
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=b08603d6-cac1-4876-a56c-30c680d5dc52@web.de \
--to=markus.elfring@web.de \
--cc=Julia.Lawall@inria.fr \
--cc=chentao@kylinos.cn \
--cc=cocci@inria.fr \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nicolas.palix@imag.fr \
/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
all inboxes | Powered by JetHome®