Re: [Cocci] [PATCH] Coccinelle: add atomic_as_refcounter script
2018-06-15 14:06 GMT+09:00 Julia Lawall : > > > On Thu, 14 Jun 2018, Kees Cook wrote: > >> On Fri, Sep 1, 2017 at 2:40 AM, Elena Reshetova >> wrote: >> > 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 >> > Acked-by: Julia Lawall >> >> Reviewed-by: Kees Cook >> >> Oops, I think this got lost. Who can take this patch? I thought Julia >> ran the scripts/coccinelle/ tree, but looking at git log, it looks >> more like it's Masahiro? Either way, let's get this in the tree. Who >> can take it? > > Masahiro takes patches. > > julia Somehow I missed this one. Now, applied to linux-kbuild. Thanks for the reminder. (If Julia hosted a git repository, that would be better, though.) -- Best Regards Masahiro Yamada ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] [PATCH] Coccinelle: add atomic_as_refcounter script
On Thu, 14 Jun 2018, Kees Cook wrote: > On Fri, Sep 1, 2017 at 2:40 AM, Elena Reshetova > wrote: > > 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 > > Acked-by: Julia Lawall > > Reviewed-by: Kees Cook > > Oops, I think this got lost. Who can take this patch? I thought Julia > ran the scripts/coccinelle/ tree, but looking at git log, it looks > more like it's Masahiro? Either way, let's get this in the tree. Who > can take it? Masahiro takes patches. julia > > Thanks! > > -Kees > > > --- > > 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 000..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 > > > > > > -- > Kees Cook > Pixel Security > ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] [PATCH] Coccinelle: add atomic_as_refcounter script
On Fri, Sep 1, 2017 at 2:40 AM, Elena Reshetova wrote: > 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 > Acked-by: Julia Lawall Reviewed-by: Kees Cook Oops, I think this got lost. Who can take this patch? I thought Julia ran the scripts/coccinelle/ tree, but looking at git log, it looks more like it's Masahiro? Either way, let's get this in the tree. Who can take it? Thanks! -Kees > --- > 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 000..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 > -- Kees Cook Pixel Security ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] [PATCH] Coccinelle: add atomic_as_refcounter script
> On Wed, 30 Aug 2017, Reshetova, Elena wrote: > > > > > > > > > On Wed, 30 Aug 2017, Elena Reshetova wrote: > > > > > > > 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> > > > > > Acked-by: Julia Lawall > > > > Thank you very much Julia! What is the correct path to merge this? > > I will resend with your acked-by, but what is the tree that should merge it? > > Marek will take it. If you want to resend, please get rid of the > metavariable y in the rule r1. It causes an unused variable warning. Sure, will do. Thank you! Best Regards, Elena. > > julia > > > > > Best Regards, > > Elena. > > > > > > > --- > > > > 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 000..f83771b > > > > --- /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, y; > > > > +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 > > > > > > > > > > ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] [PATCH] Coccinelle: add atomic_as_refcounter script
On Wed, 30 Aug 2017, Reshetova, Elena wrote: > > > > > On Wed, 30 Aug 2017, Elena Reshetova wrote: > > > > > 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> > > > Acked-by: Julia Lawall > > Thank you very much Julia! What is the correct path to merge this? > I will resend with your acked-by, but what is the tree that should merge it? Marek will take it. If you want to resend, please get rid of the metavariable y in the rule r1. It causes an unused variable warning. julia > > Best Regards, > Elena. > > > > > --- > > > 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 000..f83771b > > > --- /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, y; > > > +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 > > > > > > > ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] [PATCH] Coccinelle: add atomic_as_refcounter script
> > On Wed, 30 Aug 2017, Elena Reshetova wrote: > > > 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> > Acked-by: Julia Lawall Thank you very much Julia! What is the correct path to merge this? I will resend with your acked-by, but what is the tree that should merge it? Best Regards, Elena. > > > --- > > 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 000..f83771b > > --- /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, y; > > +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 > > > > ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] [PATCH] Coccinelle: add atomic_as_refcounter script
On Wed, 30 Aug 2017, Elena Reshetova wrote: > 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 ReshetovaAcked-by: Julia Lawall > --- > 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 000..f83771b > --- /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, y; > +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 > > ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] [PATCH] Coccinelle: add atomic_as_refcounter script
> > +identifier fname =~ ".*free.*"; > > +identifier fname2 =~ ".*destroy.*"; > > +identifier fname3 =~ ".*del.*"; > > +identifier fname4 =~ ".*queue_work.*"; > > +identifier fname5 =~ ".*schedule_work.*"; > > +identifier fname6 =~ ".*call_rcu.*"; > > Personally, I find the above regular expressions much easier to understand > than the merged version that Markus proposed. I really don't have a strong opinion on the presentation side. One is more compact, the above one perhaps a bit clearer for unexperienced reader (like myself). Sometimes when I try to read patterns from cocci folder, it takes me really a while to understand what is happening, which is not the case with simple expression above. I have just considered myself to be too new into this and therefore sticked to simple expressions to make sure I am minimizing functional mistakes. But the performance issue is > only on whether to use regular expressions or not. If you use regular > expressions, Coccinelle will not do some optimizations. But once you > decide to use regular expressions, the performance hit is already taken - > for a good cause here, to my understanding. Ok, so then performance is not even a factor. Thank you for the explanation! So just put whatever you find > convenient, in terms of readability, precision, etc. It seems that del is > not very precise, because it is a substring of multiple words with > different meanings. Maybe it should be improved, or maybe one can just > live with the false positives (eg delay), if they actually are false > positives. This is the problem that some of them might be and some not. I can call the queuing works explicitly: identifier fname4 =~ ".*queue_work.*"; identifier fname5 =~ ".*queue_delayed_work.*"; Then there is no need to match "delay", but I still like to match both "delete" and "del". Best Regards, Elena. > > julia ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] [PATCH] Coccinelle: add atomic_as_refcounter script
> +identifier fname =~ ".*free.*"; > +identifier fname2 =~ ".*destroy.*"; > +identifier fname3 =~ ".*del.*"; > +identifier fname4 =~ ".*queue_work.*"; > +identifier fname5 =~ ".*schedule_work.*"; > +identifier fname6 =~ ".*call_rcu.*"; Personally, I find the above regular expressions much easier to understand than the merged version that Markus proposed. But the performance issue is only on whether to use regular expressions or not. If you use regular expressions, Coccinelle will not do some optimizations. But once you decide to use regular expressions, the performance hit is already taken - for a good cause here, to my understanding. So just put whatever you find convenient, in terms of readability, precision, etc. It seems that del is not very precise, because it is a substring of multiple words with different meanings. Maybe it should be improved, or maybe one can just live with the false positives (eg delay), if they actually are false positives. julia ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] [PATCH] Coccinelle: add atomic_as_refcounter script
> On Mon, 14 Aug 2017, Elena Reshetova wrote: > > > 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> > --- > > scripts/coccinelle/api/atomic_as_refcounter.cocci | 148 > ++ > > 1 file changed, 148 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 000..996d72b > > --- /dev/null > > +++ b/scripts/coccinelle/api/atomic_as_refcounter.cocci > > @@ -0,0 +1,148 @@ > > +// 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, y; > > +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.*"; > > +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) > > +) > > +... > > +y=a > > +... > > +( > > + fname@p2(y, ...); > > +| > > + fname2@p2(...); > > From here to the end of the rule there is no a or y. So they would match > the same thing as in the previous rule. so you could get rid of all of > these cases, and just leave fname@p2(y, ...); True, stupid of me :( Will fix. Best Regards, Elena. > > julia > > > +| > > + fname3@p2(...); > > +| > > + fname4@p2(...); > > +| > > + fname5@p2(...); > > +| > > + fname6@p2(...); > > +) > > + > > + > > +@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 > > > > ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] [PATCH] Coccinelle: add atomic_as_refcounter script
On Mon, 14 Aug 2017, Elena Reshetova wrote: > 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> --- > scripts/coccinelle/api/atomic_as_refcounter.cocci | 148 > ++ > 1 file changed, 148 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 000..996d72b > --- /dev/null > +++ b/scripts/coccinelle/api/atomic_as_refcounter.cocci > @@ -0,0 +1,148 @@ > +// 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, y; > +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.*"; > +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) > +) > +... > +y=a > +... > +( > + fname@p2(y, ...); > +| > + fname2@p2(...); >From here to the end of the rule there is no a or y. So they would match the same thing as in the previous rule. so you could get rid of all of these cases, and just leave fname@p2(y, ...); julia > +| > + fname3@p2(...); > +| > + fname4@p2(...); > +| > + fname5@p2(...); > +| > + fname6@p2(...); > +) > + > + > +@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 > > ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] [PATCH] Coccinelle: add atomic_as_refcounter script
> On Tue, 18 Jul 2017, Elena Reshetova wrote: > > > 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> > --- > > scripts/coccinelle/api/atomic_as_refcounter.cocci | 102 > ++ > > 1 file changed, 102 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 000..a16d395 > > --- /dev/null > > +++ b/scripts/coccinelle/api/atomic_as_refcounter.cocci > > @@ -0,0 +1,102 @@ > > +// 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, y; > > +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) > > +) > > +... > > +?y=a > > This makes the line optional. And if it dosn't appear, there is no > constraint on y. So the rule matches: > > int main() { > atomic64_dec_and_test(&(a)->x); > free(b); > } > > I would suggest to just make two rules, one with y=a and one without. Oh, thank you for the catch! I was a bit afraid it might be the case, but when I tried it in practice it didn't show up that many additional cases compare to not having ?y=a at all (only 20 or so), and when I checked some, they looked worth a manual check anyway and interesting. But I will fix the rule and send a new version! Best Regards, Elena. > > julia > > > +... > > +( > > + fname@p2(a, ...); > > +| > > + fname@p2(y, ...); > > +| > > + 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)) > > + > > +@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 > > > > ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] [PATCH] Coccinelle: add atomic_as_refcounter script
On Tue, 18 Jul 2017, Elena Reshetova wrote: > 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> --- > scripts/coccinelle/api/atomic_as_refcounter.cocci | 102 > ++ > 1 file changed, 102 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 000..a16d395 > --- /dev/null > +++ b/scripts/coccinelle/api/atomic_as_refcounter.cocci > @@ -0,0 +1,102 @@ > +// 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, y; > +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) > +) > +... > +?y=a This makes the line optional. And if it dosn't appear, there is no constraint on y. So the rule matches: int main() { atomic64_dec_and_test(&(a)->x); free(b); } I would suggest to just make two rules, one with y=a and one without. julia > +... > +( > + fname@p2(a, ...); > +| > + fname@p2(y, ...); > +| > + 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)) > + > +@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 > > ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] [PATCH] Coccinelle: add atomic_as_refcounter script
On Tue, Jul 18, 2017 at 12:48 AM, Elena Reshetovawrote: > 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 > --- > scripts/coccinelle/api/atomic_as_refcounter.cocci | 102 > ++ > 1 file changed, 102 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 000..a16d395 > --- /dev/null > +++ b/scripts/coccinelle/api/atomic_as_refcounter.cocci > @@ -0,0 +1,102 @@ > +// 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, y; > +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) > [...] > +) > +... > +?y=a > +... > +( > + fname@p2(a, ...); > +| > + fname@p2(y, ...); > +| > [...] Just to double check, this "?y=a" catches the seccomp case I pointed out? while (orig && atomic_dec_and_test(>usage)) { struct seccomp_filter *freeme = orig; orig = orig->prev; seccomp_filter_free(freeme); } Seems like it should match. Did this find anything else besides seccomp? -Kees -- Kees Cook Pixel Security ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci