All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] coccinelle: api: add kzfree script
@ 2020-06-04 14:08 ` Denis Efremov
  0 siblings, 0 replies; 59+ messages in thread
From: Denis Efremov @ 2020-06-04 14:08 UTC (permalink / raw)
  To: Julia Lawall; +Cc: Denis Efremov, cocci, linux-kernel

Check for memset() with 0 followed by kfree().

Signed-off-by: Denis Efremov <efremov@linux.com>
---
Patches:
1. kzfree in drivers/w1 https://lkml.org/lkml/2020/6/4/438
2. kzfree in drivers/iommu/ https://lkml.org/lkml/2020/6/4/421
3. kzfree in drivers/scsi/ https://lkml.org/lkml/2020/6/4/442

 scripts/coccinelle/api/kzfree.cocci | 53 +++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 scripts/coccinelle/api/kzfree.cocci

diff --git a/scripts/coccinelle/api/kzfree.cocci b/scripts/coccinelle/api/kzfree.cocci
new file mode 100644
index 000000000000..c6b8f7676af4
--- /dev/null
+++ b/scripts/coccinelle/api/kzfree.cocci
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0-only
+///
+/// Use kzfree rather than memset with 0 followed by kfree
+///
+// Confidence: High
+// Copyright: (C) 2020 Denis Efremov ISPRAS
+// Options: --no-includes --include-headers
+//
+// Keywords: kzfree
+//
+
+virtual context
+virtual org
+virtual report
+virtual patch
+
+// Ignore kzfree definition
+// Ignore kasan test
+@r depends on !patch && !(file in "lib/test_kasan.c") && !(file in "mm/slab_common.c")@
+expression E;
+position p;
+@@
+
+(
+* memset(E, 0, ...);
+|
+* memset(E, '\0', ...);
+)
+* kfree(E)@p;
+
+@r1 depends on patch && !(file in "lib/test_kasan.c") && !(file in "mm/slab_common.c")@
+expression E;
+@@
+
+(
+- memset(E, 0, ...);
+|
+- memset(E, '\0', ...);
+)
+- kfree(E);
++ kzfree(E);
+
+@script:python depends on report@
+p << r.p;
+@@
+
+coccilib.report.print_report(p[0], "WARNING opportunity for kzfree")
+
+@script:python depends on org@
+p << r.p;
+@@
+
+coccilib.org.print_todo(p[0], "WARNING opportunity for kzfree")
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 59+ messages in thread
* Re: [Cocci] [PATCH v3] coccinelle: api: add kzfree script
@ 2020-06-15 13:26 Markus Elfring
  0 siblings, 0 replies; 59+ messages in thread
From: Markus Elfring @ 2020-06-15 13:26 UTC (permalink / raw)
  To: Denis Efremov, Coccinelle, Gilles Muller, Julia Lawall,
	Masahiro Yamada, Michal Marek, Nicolas Palix
  Cc: kernel-janitors, linux-kernel

…
> +virtual context
> +virtual patch
> +virtual org
> +virtual report

+virtual context, patch, org, report

Is such a SmPL code variant more succinct?


…
> +if (...)
> +  \(memset@ok\|memzero_explicit@ok\)(...);

Would you like to tolerate any extra source code around such a function call
in an if branch?


…
> +(
> +* memset@m((T)E, 0, ...);
> +|
> +* memzero_explicit@m((T)E, ...);
> +)
…

I suggest to move a semicolon.

+(
+*memset@m((T)E, 0, ...)
+|
+*memzero_explicit@m((T)E, ...)
+);


…
> +- \(kfree\|vfree\|kvfree\)(E);
> ++ kvfree_sensitive(E, size);
…

Would you like to increase the precision a bit for the change specification?

+-\(kfree\|vfree\|kvfree\)
++kvfree_sensitive
+ (E
++ , size
+ );


…
> +(
> +- kfree(E);
> ++ kzfree(E);
> +|
> +- \(vfree\|kvfree\)(E);
> ++ kvfree_sensitive(E, size);
> +)
…

+(
+-kfree
++kzfree
+      (E)
+|
+-\(vfree\|kvfree\)
++kvfree_sensitive
+ (E
++ , size
+ )
+);


…
> +coccilib.org.print_todo(p[0],
> +  "WARNING: opportunity for kzfree/kvfree_sensitive")

I suggest to align the second function parameter.

+coccilib.org.print_todo(p[0],
+                        "WARNING: opportunity for kzfree/kvfree_sensitive")


Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

end of thread, other threads:[~2020-09-12 15:08 UTC | newest]

Thread overview: 59+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-04 14:08 [PATCH] coccinelle: api: add kzfree script Denis Efremov
2020-06-04 14:08 ` [Cocci] " Denis Efremov
2020-06-04 14:15 ` Julia Lawall
2020-06-04 14:15   ` [Cocci] " Julia Lawall
2020-06-04 15:39   ` Denis Efremov
2020-06-04 15:39     ` [Cocci] " Denis Efremov
2020-06-04 15:51     ` Julia Lawall
2020-06-04 15:51       ` [Cocci] " Julia Lawall
2020-06-04 17:22       ` Denis Efremov
2020-06-04 17:22         ` [Cocci] " Denis Efremov
2020-06-04 17:28         ` Julia Lawall
2020-06-04 17:28           ` [Cocci] " Julia Lawall
2020-06-04 16:27 ` Joe Perches
2020-06-04 16:27   ` [Cocci] " Joe Perches
2020-06-04 17:30   ` Denis Efremov
2020-06-04 17:30     ` [Cocci] " Denis Efremov
2020-06-04 17:36     ` Joe Perches
2020-06-04 17:36       ` [Cocci] " Joe Perches
2020-06-14 19:42   ` Denis Efremov
2020-06-14 19:42     ` [Cocci] " Denis Efremov
2020-06-14 20:01     ` Joe Perches
2020-06-14 20:01       ` [Cocci] " Joe Perches
2020-06-15 12:03     ` Dan Carpenter
2020-06-15 12:03       ` [Cocci] " Dan Carpenter
2020-06-15 13:51       ` Denis Efremov
2020-06-15 13:51         ` [Cocci] " Denis Efremov
2020-06-04 20:48 ` [PATCH v2] " Denis Efremov
2020-06-04 20:48   ` [Cocci] " Denis Efremov
2020-06-04 20:57   ` Julia Lawall
2020-06-04 20:57     ` Julia Lawall
2020-06-04 21:03     ` Denis Efremov
2020-06-04 21:03       ` Denis Efremov
2020-06-04 21:25     ` Denis Efremov
2020-06-04 21:25       ` Denis Efremov
2020-06-06  8:16       ` Julia Lawall
2020-06-06  8:16         ` Julia Lawall
2020-06-14 21:54 ` [PATCH v3] " Denis Efremov
2020-06-14 21:54   ` [Cocci] " Denis Efremov
2020-06-17 20:42   ` Julia Lawall
2020-06-17 20:42     ` Julia Lawall
2020-06-17 21:42     ` Denis Efremov
2020-06-17 21:42       ` Denis Efremov
2020-07-07 21:35   ` Julia Lawall
2020-07-07 21:35     ` Julia Lawall
2020-07-17 11:57 ` [PATCH v4] " Denis Efremov
2020-07-17 11:57   ` [Cocci] " Denis Efremov
2020-07-17 20:39   ` Julia Lawall
2020-07-17 20:39     ` [Cocci] " Julia Lawall
2020-08-10 23:45     ` Eric Biggers
2020-08-10 23:45       ` [Cocci] " Eric Biggers
2020-08-11  7:12       ` Denis Efremov
2020-08-11  7:12         ` [Cocci] " Denis Efremov
2020-08-11  7:49 ` [PATCH] coccinelle: api: update kzfree script to kfree_sensitive Denis Efremov
2020-08-11  7:49   ` [Cocci] " Denis Efremov
2020-08-26  8:12   ` Denis Efremov
2020-08-26  8:12     ` [Cocci] " Denis Efremov
2020-09-12 15:08   ` Julia Lawall
2020-09-12 15:08     ` [Cocci] " Julia Lawall
2020-06-15 13:26 [Cocci] [PATCH v3] coccinelle: api: add kzfree script Markus Elfring

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.