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