[PATCH linux-next RESEND] scripts/coccinelle/misc: Warn about NULL check on kmap()

From: Fabian Frederick
Date: Thu May 04 2017 - 15:09:47 EST


This script removes NULL check on kmap() and all process involved
(OOM message ...)

Thanks to Jan Kara for explanations.

Acked-by: Julia Lawall <julia.lawall@xxxxxxx>
Signed-off-by: Fabian Frederick <fabf@xxxxxxxxx>
---
scripts/coccinelle/misc/kmap.cocci | 43 ++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
create mode 100644 scripts/coccinelle/misc/kmap.cocci

diff --git a/scripts/coccinelle/misc/kmap.cocci b/scripts/coccinelle/misc/kmap.cocci
new file mode 100644
index 0000000..9ae4a6e
--- /dev/null
+++ b/scripts/coccinelle/misc/kmap.cocci
@@ -0,0 +1,43 @@
+/// kmap never fails; remove NULL test case.
+///
+// Copyright: (C) 2017 Fabian Frederick. GPLv2.
+// Comments: -
+// Options: --no-includes --include-headers
+
+virtual patch
+virtual org
+virtual report
+virtual context
+
+@r2 depends on patch@
+expression E;
+position p;
+@@
+
+E = kmap(...);
+- if (!E) {
+- ...
+- }
+
+@r depends on context || report || org @
+expression E;
+position p;
+@@
+
+* E = kmap(...);
+* if (@p!E) {
+* ...
+* }
+
+@script:python depends on org@
+p << r.p;
+@@
+
+cocci.print_main("kmap() can't fail, NULL check and special process is not needed", p)
+
+@script:python depends on report@
+p << r.p;
+@@
+
+msg = "WARNING: NULL check on kmap() result is not needed."
+coccilib.report.print_report(p[0], msg)
--
2.9.3