Skip to content

Commit a2fc371

Browse files
evdenisJuliaLawall
authored andcommitted
coccinelle: api: add kobj_to_dev.cocci script
Use kobj_to_dev() instead of container_of(). Signed-off-by: Denis Efremov <efremov@linux.com> Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
1 parent 7a2624e commit a2fc371

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
///
3+
/// Use kobj_to_dev() instead of container_of()
4+
///
5+
// Confidence: High
6+
// Copyright: (C) 2020 Denis Efremov ISPRAS
7+
// Options: --no-includes --include-headers
8+
//
9+
// Keywords: kobj_to_dev, container_of
10+
//
11+
12+
virtual context
13+
virtual report
14+
virtual org
15+
virtual patch
16+
17+
18+
@r depends on !patch@
19+
expression ptr;
20+
symbol kobj;
21+
position p;
22+
@@
23+
24+
* container_of(ptr, struct device, kobj)@p
25+
26+
27+
@depends on patch@
28+
expression ptr;
29+
@@
30+
31+
- container_of(ptr, struct device, kobj)
32+
+ kobj_to_dev(ptr)
33+
34+
35+
@script:python depends on report@
36+
p << r.p;
37+
@@
38+
39+
coccilib.report.print_report(p[0], "WARNING opportunity for kobj_to_dev()")
40+
41+
@script:python depends on org@
42+
p << r.p;
43+
@@
44+
45+
coccilib.org.print_todo(p[0], "WARNING opportunity for kobj_to_dev()")

0 commit comments

Comments
 (0)