All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Coccinelle: add atomic_as_refcounter script
@ 2017-09-01  9:40 ` Elena Reshetova
  0 siblings, 0 replies; 42+ messages in thread
From: Elena Reshetova @ 2017-09-01  9:40 UTC (permalink / raw)
  To: julia.lawall
  Cc: linux-kernel, cocci, Gilles.Muller, nicolas.palix, mmarek,
	keescook, ishkamiel, Elena Reshetova

atomic_as_refcounter.cocci script allows detecting
cases when refcount_t type and API should be used
instead of atomic_t.

Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
---
 scripts/coccinelle/api/atomic_as_refcounter.cocci | 131 ++++++++++++++++++++++
 1 file changed, 131 insertions(+)
 create mode 100644 scripts/coccinelle/api/atomic_as_refcounter.cocci

diff --git a/scripts/coccinelle/api/atomic_as_refcounter.cocci b/scripts/coccinelle/api/atomic_as_refcounter.cocci
new file mode 100644
index 0000000..bfa880d
--- /dev/null
+++ b/scripts/coccinelle/api/atomic_as_refcounter.cocci
@@ -0,0 +1,131 @@
+// Check if refcount_t type and API should be used
+// instead of atomic_t type when dealing with refcounters
+//
+// Copyright (c) 2016-2017, Elena Reshetova, Intel Corporation
+//
+// Confidence: Moderate
+// URL: http://coccinelle.lip6.fr/
+// Options: --include-headers --very-quiet
+
+virtual report
+
+@r1 exists@
+identifier a, x;
+position p1, p2;
+identifier fname =~ ".*free.*";
+identifier fname2 =~ ".*destroy.*";
+identifier fname3 =~ ".*del.*";
+identifier fname4 =~ ".*queue_work.*";
+identifier fname5 =~ ".*schedule_work.*";
+identifier fname6 =~ ".*call_rcu.*";
+
+@@
+
+(
+ atomic_dec_and_test@p1(&(a)->x)
+|
+ atomic_dec_and_lock@p1(&(a)->x, ...)
+|
+ atomic_long_dec_and_lock@p1(&(a)->x, ...)
+|
+ atomic_long_dec_and_test@p1(&(a)->x)
+|
+ atomic64_dec_and_test@p1(&(a)->x)
+|
+ local_dec_and_test@p1(&(a)->x)
+)
+...
+(
+ fname@p2(a, ...);
+|
+ fname2@p2(...);
+|
+ fname3@p2(...);
+|
+ fname4@p2(...);
+|
+ fname5@p2(...);
+|
+ fname6@p2(...);
+)
+
+
+@script:python depends on report@
+p1 << r1.p1;
+p2 << r1.p2;
+@@
+msg = "atomic_dec_and_test variation before object free at line %s."
+coccilib.report.print_report(p1[0], msg % (p2[0].line))
+
+@r4 exists@
+identifier a, x, y;
+position p1, p2;
+identifier fname =~ ".*free.*";
+
+@@
+
+(
+ atomic_dec_and_test@p1(&(a)->x)
+|
+ atomic_dec_and_lock@p1(&(a)->x, ...)
+|
+ atomic_long_dec_and_lock@p1(&(a)->x, ...)
+|
+ atomic_long_dec_and_test@p1(&(a)->x)
+|
+ atomic64_dec_and_test@p1(&(a)->x)
+|
+ local_dec_and_test@p1(&(a)->x)
+)
+...
+y=a
+...
+fname@p2(y, ...);
+
+
+@script:python depends on report@
+p1 << r4.p1;
+p2 << r4.p2;
+@@
+msg = "atomic_dec_and_test variation before object free at line %s."
+coccilib.report.print_report(p1[0], msg % (p2[0].line))
+
+@r2 exists@
+identifier a, x;
+position p1;
+@@
+
+(
+atomic_add_unless(&(a)->x,-1,1)@p1
+|
+atomic_long_add_unless(&(a)->x,-1,1)@p1
+|
+atomic64_add_unless(&(a)->x,-1,1)@p1
+)
+
+@script:python depends on report@
+p1 << r2.p1;
+@@
+msg = "atomic_add_unless"
+coccilib.report.print_report(p1[0], msg)
+
+@r3 exists@
+identifier x;
+position p1;
+@@
+
+(
+x = atomic_add_return@p1(-1, ...);
+|
+x = atomic_long_add_return@p1(-1, ...);
+|
+x = atomic64_add_return@p1(-1, ...);
+)
+
+@script:python depends on report@
+p1 << r3.p1;
+@@
+msg = "x = atomic_add_return(-1, ...)"
+coccilib.report.print_report(p1[0], msg)
+
+
-- 
2.7.4

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

end of thread, other threads:[~2018-08-01 12:30 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-01  9:40 [PATCH] Coccinelle: add atomic_as_refcounter script Elena Reshetova
2017-09-01  9:40 ` [Cocci] " Elena Reshetova
2018-06-14 23:58 ` Kees Cook
2018-06-14 23:58   ` [Cocci] " Kees Cook
2018-06-15  5:06   ` Julia Lawall
2018-06-15  5:06     ` [Cocci] " Julia Lawall
2018-06-18 13:47     ` Masahiro Yamada
2018-06-18 13:47       ` [Cocci] " Masahiro Yamada
2018-07-03  7:30       ` [PATCH 0/6] Coccinelle: atomic_as_refcounter: Improvements for source code search specifications SF Markus Elfring
2018-07-03  7:30         ` SF Markus Elfring
2018-07-03  7:35         ` [PATCH 1/6] Coccinelle: atomic_as_refcounter: Omit placeholder specifications from two SmPL constraints SF Markus Elfring
2018-07-03  7:35           ` [PATCH 1/6] Coccinelle: atomic_as_refcounter: Omit placeholder specifications from two SmPL constrai SF Markus Elfring
2018-07-03  7:37         ` [PATCH 2/6] Coccinelle: atomic_as_refcounter: Optimise a disjunction in the first SmPL rule SF Markus Elfring
2018-07-03  7:37           ` SF Markus Elfring
2018-07-03  7:40         ` [PATCH 3/6] Coccinelle: atomic_as_refcounter: Use type “expression” for another metavariable SF Markus Elfring
2018-07-03  7:40           ` [PATCH 3/6] Coccinelle: atomic_as_refcounter: Use typ =?UTF-8?Q?e_=e2=80=9cexpressio SF Markus Elfring
2018-07-03  7:42         ` [PATCH 4/6] Coccinelle: atomic_as_refcounter: Replace disjunction by a constraint in two SmPL rules SF Markus Elfring
2018-07-03  7:42           ` SF Markus Elfring
2018-07-03  7:45         ` [PATCH 5/6] Coccinelle: atomic_as_refcounter: Use nested disjunctions " SF Markus Elfring
2018-07-03  7:45           ` SF Markus Elfring
2018-07-03  7:48         ` [PATCH 6/6] Coccinelle: atomic_as_refcounter: Use format strings directly in " SF Markus Elfring
2018-07-03  7:48           ` SF Markus Elfring
2018-08-01 12:30           ` [PATCH] Coccinelle: atomic_as_refcounter: Merge two " SF Markus Elfring
2018-08-01 12:30             ` SF Markus Elfring
2018-07-16 17:21         ` [PATCH v2 0/8] Coccinelle: atomic_as_refcounter: Adjustments for source code search specifications SF Markus Elfring
2018-07-16 17:21           ` SF Markus Elfring
2018-07-16 17:24           ` [PATCH v2 1/8] Coccinelle: atomic_as_refcounter: Delete an unnecessary SmPL rule SF Markus Elfring
2018-07-16 17:24             ` SF Markus Elfring
2018-07-16 17:26           ` [PATCH v2 2/8] Coccinelle: atomic_as_refcounter: Omit placeholder specifications from a SmPL constraint SF Markus Elfring
2018-07-16 17:26             ` [PATCH v2 2/8] Coccinelle: atomic_as_refcounter: Omit placeholder specifications from a SmPL constra SF Markus Elfring
2018-07-16 17:28           ` [PATCH v2 3/8] Coccinelle: atomic_as_refcounter: Optimise a disjunction in the first SmPL rule SF Markus Elfring
2018-07-16 17:28             ` SF Markus Elfring
2018-07-16 17:30           ` [PATCH v2 4/8] Coccinelle: atomic_as_refcounter: Use type “expression” for another metavariable SF Markus Elfring
2018-07-16 17:30             ` [PATCH v2 4/8] Coccinelle: atomic_as_refcounter: Use =?UTF-8?Q?type_=e2=80=9cexpres SF Markus Elfring
2018-07-16 17:32           ` [PATCH v2 5/8] Coccinelle: atomic_as_refcounter: Replace disjunction by a constraint in two SmPL rules SF Markus Elfring
2018-07-16 17:32             ` [PATCH v2 5/8] Coccinelle: atomic_as_refcounter: Replace disjunction by a constraint in two SmPL rul SF Markus Elfring
2018-07-16 17:34           ` [PATCH v2 6/8] Coccinelle: atomic_as_refcounter: Use nested disjunctions in the first SmPL rule SF Markus Elfring
2018-07-16 17:34             ` SF Markus Elfring
2018-07-16 17:36           ` [PATCH v2 7/8] Coccinelle: atomic_as_refcounter: Use string literals directly in two SmPL rules SF Markus Elfring
2018-07-16 17:36             ` SF Markus Elfring
2018-07-16 17:39           ` [PATCH v2 8/8] Coccinelle: atomic_as_refcounter: Use format string directly in the first SmPL rule SF Markus Elfring
2018-07-16 17:39             ` SF 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.