cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [cocci] [PATCH] scripts/coccinelle/free: add NULL test before dev_{put, hold} functions
@ 2022-06-16  1:32 Ziyang Xuan
  2022-06-25 16:55 ` Markus Elfring
  2022-07-16 13:38 ` [cocci] [PATCH] " Julia Lawall
  0 siblings, 2 replies; 7+ messages in thread
From: Ziyang Xuan @ 2022-06-16  1:32 UTC (permalink / raw)
  To: Julia.Lawall, nicolas.palix, cocci; +Cc: fabf, william.xuanziyang

Since commit b37a46683739 ("netdevice: add the case if dev is NULL"),
NULL check before dev_{put, hold} functions is not needed.

Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>
---
 scripts/coccinelle/free/ifnulldev_put.cocci | 54 +++++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 scripts/coccinelle/free/ifnulldev_put.cocci

diff --git a/scripts/coccinelle/free/ifnulldev_put.cocci b/scripts/coccinelle/free/ifnulldev_put.cocci
new file mode 100644
index 000000000000..7ff36e6212ba
--- /dev/null
+++ b/scripts/coccinelle/free/ifnulldev_put.cocci
@@ -0,0 +1,54 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/// Since commit b37a46683739 ("netdevice: add the case if dev is NULL"),
+/// NULL check before dev_{put, hold} functions is not needed.
+///
+/// Based on ifnullfree.cocci by Fabian Frederick.
+///
+// Copyright: (C) 2022 Ziyang Xuan.
+// Comments: -
+// Options: --no-includes --include-headers
+
+virtual patch
+virtual org
+virtual report
+virtual context
+
+@r2 depends on patch@
+expression E;
+@@
+- if (E != NULL)
+(
+  __dev_put(E);
+|
+  dev_put(E);
+|
+  dev_put_track(E, ...);
+|
+  __dev_hold(E);
+|
+  dev_hold(E);
+|
+  dev_hold_track(E, ...);
+)
+
+@r depends on context || report || org @
+expression E;
+position p;
+@@
+
+* if (E != NULL)
+*	\(__dev_put@p\|dev_put@p\|dev_put_track@p\|__dev_hold@p\|dev_hold@p\|
+*         dev_hold_track@p\)(E, ...);
+
+@script:python depends on org@
+p << r.p;
+@@
+
+cocci.print_main("NULL check before dev_{put, hold} functions is not needed", p)
+
+@script:python depends on report@
+p << r.p;
+@@
+
+msg = "WARNING: NULL check before dev_{put, hold} functions is not needed."
+coccilib.report.print_report(p[0], msg)
-- 
2.25.1


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

end of thread, other threads:[~2022-07-16 13:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-16  1:32 [cocci] [PATCH] scripts/coccinelle/free: add NULL test before dev_{put, hold} functions Ziyang Xuan
2022-06-25 16:55 ` Markus Elfring
2022-06-29 12:32   ` Ziyang Xuan (William)
2022-06-29 18:42     ` [cocci] " Markus Elfring
2022-06-30  2:22       ` Ziyang Xuan (William)
2022-06-30 19:10         ` Markus Elfring
2022-07-16 13:38 ` [cocci] [PATCH] " Julia Lawall

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).