Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scripts/coccinelle/free: add NULL test before dev_{put, hold} functions

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>
Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>

authored by

Ziyang Xuan and committed by
Julia Lawall
bbd5c968 8e54fe1b

+54
+54
scripts/coccinelle/free/ifnulldev_put.cocci
··· 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 + 11 + virtual patch 12 + virtual org 13 + virtual report 14 + virtual context 15 + 16 + @r2 depends on patch@ 17 + expression 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 @ 35 + expression E; 36 + position 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@ 44 + p << r.p; 45 + @@ 46 + 47 + cocci.print_main("NULL check before dev_{put, hold} functions is not needed", p) 48 + 49 + @script:python depends on report@ 50 + p << r.p; 51 + @@ 52 + 53 + msg = "WARNING: NULL check before dev_{put, hold} functions is not needed." 54 + coccilib.report.print_report(p[0], msg)