mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] Coccinelle: api: Add SmPL script “use_KMEM_CACHE.cocci”
@ 2024-01-24 18:09 Markus Elfring
  2024-02-02  9:12 ` [PATCH v2] " Markus Elfring
  0 siblings, 1 reply; 2+ messages in thread
From: Markus Elfring @ 2024-01-24 18:09 UTC (permalink / raw)
  To: cocci, kernel-janitors, Julia Lawall, Nicolas Palix; +Cc: LKML, Kunwu Chan

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 24 Jan 2024 18:38:39 +0100

A wrapper macro is available since the commit 8eb8284b412906181357c2b0110d879d5af95e52
("usercopy: Prepare for usercopy whitelisting").
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>
---
 scripts/coccinelle/api/use_KMEM_CACHE.cocci | 48 +++++++++++++++++++++
 1 file changed, 48 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..259a8c998bb1
--- /dev/null
+++ b/scripts/coccinelle/api/use_KMEM_CACHE.cocci
@@ -0,0 +1,48 @@
+// 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
+
+@depends on context disable sizeof_type_expr@
+constant char[] text;
+expression alignment, flags;
+identifier name;
+@@
+*kmem_cache_create(text, sizeof(struct name), alignment, flags, NULL)
+
+@depends on patch disable sizeof_type_expr@
+constant char[] text;
+expression alignment, flags;
+identifier name;
+@@
+-kmem_cache_create
++KMEM_CACHE
+ (
+-text, sizeof(struct
+ name
+-), alignment
+ , flags
+-, NULL
+ )
+
+@x depends on org || report disable sizeof_type_expr@
+constant char[] text;
+expression alignment, flags;
+identifier name;
+position p;
+@@
+ kmem_cache_create@p(text, sizeof(struct name), 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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-02-02  9:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-24 18:09 [PATCH] Coccinelle: api: Add SmPL script “use_KMEM_CACHE.cocci” Markus Elfring
2024-02-02  9:12 ` [PATCH v2] " Markus Elfring

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®