From: Denis Efremov <efremov@linux.com>
To: Julia Lawall <Julia.Lawall@lip6.fr>
Cc: linux-kernel@vger.kernel.org, cocci@systeme.lip6.fr
Subject: [Cocci] [PATCH v2 4/4] coccinelle: api: add selfcheck for memdup_user rule
Date: Mon, 8 Jun 2020 18:00:38 +0300 [thread overview]
Message-ID: <20200608150038.223747-5-efremov@linux.com> (raw)
In-Reply-To: <20200608150038.223747-1-efremov@linux.com>
Check that the rule matches vmemdup_user implementation.
memdup_user is out of scope because we are not matching
kmalloc_track_caller() function.
Signed-off-by: Denis Efremov <efremov@linux.com>
---
scripts/coccinelle/api/memdup_user.cocci | 46 ++++++++++++++++++++++--
1 file changed, 44 insertions(+), 2 deletions(-)
diff --git a/scripts/coccinelle/api/memdup_user.cocci b/scripts/coccinelle/api/memdup_user.cocci
index 8621bd98be1e..78fded83b197 100644
--- a/scripts/coccinelle/api/memdup_user.cocci
+++ b/scripts/coccinelle/api/memdup_user.cocci
@@ -14,13 +14,24 @@ virtual patch
virtual context
virtual org
virtual report
+virtual selfcheck
@initialize:python@
@@
-filter = frozenset(['memdup_user', 'vmemdup_user'])
+
+definitions = {
+ 'memdup_user': 'mm/util.c',
+ 'vmemdup_user': 'mm/util.c',
+}
+
+filter = frozenset(definitions.keys())
+coccinelle.filtered = set()
+coccinelle.checked_files = set()
def relevant(p):
- return not (filter & {el.current_element for el in p})
+ found = filter & {el.current_element for el in p}
+ coccinelle.filtered |= found
+ return not found
@depends on patch@
expression from,to,size;
@@ -117,3 +128,34 @@ p << rv.p;
@@
coccilib.report.print_report(p[0], "WARNING opportunity for vmemdup_user")
+
+@script:python depends on selfcheck@
+@@
+coccinelle.checked_files |= set(definitions.values()) & set(cocci.files())
+
+@finalize:python depends on selfcheck@
+filtered << merge.filtered;
+checked_files << merge.checked_files;
+@@
+
+# Don't check memdup_user because the pattern is not capturing
+# kmalloc_track_caller() calls
+del definitions['memdup_user']
+
+# mapping between checked files and filtered definitions
+found_defns = {}
+for files, funcs in zip(checked_files, filtered):
+ for file in files:
+ found_defns[file] = funcs
+
+# reverse mapping of definitions
+expected_defns = {v : set() for v in definitions.values()}
+for k, v in definitions.items():
+ expected_defns[v] |= {k}
+
+for efile, efuncs in expected_defns.items():
+ if efile in found_defns:
+ not_found = efuncs - found_defns[efile]
+ if not_found:
+ print('SELF-CHECK: the pattern no longer matches ' \
+ 'definitions {} in file {}'.format(not_found, efile))
--
2.26.2
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
next prev parent reply other threads:[~2020-06-08 15:01 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-08 15:00 [Cocci] [PATCH v2 0/4] Update memdup_user.cocci Denis Efremov
2020-06-08 15:00 ` [Cocci] [PATCH v2 1/4] coccinelle: api: extend memdup_user transformation with GFP_USER Denis Efremov
2020-07-17 20:56 ` Julia Lawall
2020-06-08 15:00 ` [Cocci] [PATCH v2 2/4] coccinelle: api: extend memdup_user rule with vmemdup_user() Denis Efremov
2020-06-08 15:00 ` [Cocci] [PATCH v2 3/4] coccinelle: api: filter out memdup_user definitions Denis Efremov
2020-06-08 15:00 ` Denis Efremov [this message]
2020-06-09 16:22 ` [Cocci] [PATCH v2 4/4] coccinelle: api: add selfcheck for memdup_user rule Julia Lawall
2020-06-11 21:25 ` Denis Efremov
2020-07-17 12:01 ` [Cocci] [PATCH v2 0/4] Update memdup_user.cocci Denis Efremov
2020-06-08 19:07 [Cocci] [PATCH v2 4/4] coccinelle: api: add selfcheck for memdup_user rule Markus Elfring
2020-06-09 9:36 Markus Elfring
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=20200608150038.223747-5-efremov@linux.com \
--to=efremov@linux.com \
--cc=Julia.Lawall@lip6.fr \
--cc=cocci@systeme.lip6.fr \
--cc=linux-kernel@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).