scripts/coccinelle/free: add NULL test before dev_{put, hold} functions
[linux-2.6-block.git] / scripts / coccinelle / free / ifnulldev_put.cocci
CommitLineData
bbd5c968
ZX
1// SPDX-License-Identifier: GPL-2.0-only
2/// Since commit b37a46683739 ("netdevice: add the case if dev is NULL"),
3/// NULL check before dev_{put, hold} functions is not needed.
4///
5/// Based on ifnullfree.cocci by Fabian Frederick.
6///
7// Copyright: (C) 2022 Ziyang Xuan.
8// Comments: -
9// Options: --no-includes --include-headers
10
11virtual patch
12virtual org
13virtual report
14virtual context
15
16@r2 depends on patch@
17expression E;
18@@
19- if (E != NULL)
20(
21 __dev_put(E);
22|
23 dev_put(E);
24|
25 dev_put_track(E, ...);
26|
27 __dev_hold(E);
28|
29 dev_hold(E);
30|
31 dev_hold_track(E, ...);
32)
33
34@r depends on context || report || org @
35expression E;
36position p;
37@@
38
39* if (E != NULL)
40* \(__dev_put@p\|dev_put@p\|dev_put_track@p\|__dev_hold@p\|dev_hold@p\|
41* dev_hold_track@p\)(E, ...);
42
43@script:python depends on org@
44p << r.p;
45@@
46
47cocci.print_main("NULL check before dev_{put, hold} functions is not needed", p)
48
49@script:python depends on report@
50p << r.p;
51@@
52
53msg = "WARNING: NULL check before dev_{put, hold} functions is not needed."
54coccilib.report.print_report(p[0], msg)