0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /// Since commit b37a46683739 ("netdevice: add the case if dev is NULL"),
0003 /// NULL check before dev_{put, hold} functions is not needed.
0004 ///
0005 /// Based on ifnullfree.cocci by Fabian Frederick.
0006 ///
0007 // Copyright: (C) 2022 Ziyang Xuan.
0008 // Comments: -
0009 // Options: --no-includes --include-headers
0010 // Version min: 5.15
0011
0012 virtual patch
0013 virtual org
0014 virtual report
0015 virtual context
0016
0017 @r2 depends on patch@
0018 expression E;
0019 @@
0020 - if (E != NULL)
0021 (
0022 __dev_put(E);
0023 |
0024 dev_put(E);
0025 |
0026 dev_put_track(E, ...);
0027 |
0028 __dev_hold(E);
0029 |
0030 dev_hold(E);
0031 |
0032 dev_hold_track(E, ...);
0033 )
0034
0035 @r depends on context || report || org @
0036 expression E;
0037 position p;
0038 @@
0039
0040 * if (E != NULL)
0041 * \(__dev_put@p\|dev_put@p\|dev_put_track@p\|__dev_hold@p\|dev_hold@p\|
0042 * dev_hold_track@p\)(E, ...);
0043
0044 @script:python depends on org@
0045 p << r.p;
0046 @@
0047
0048 cocci.print_main("NULL check before dev_{put, hold} functions is not needed", p)
0049
0050 @script:python depends on report@
0051 p << r.p;
0052 @@
0053
0054 msg = "WARNING: NULL check before dev_{put, hold} functions is not needed."
0055 coccilib.report.print_report(p[0], msg)