Skip to content

Commit 76e2d16

Browse files
committed
Merge branch 'for-5.14' of git://git.kernel.org/pub/scm/linux/kernel/git/jlawall/linux
Pull coccinelle updates from Julia Lawall: "There are two new semantic patches: - minmax: To use min and max instead of ? : - swap: To use swap when possible Some other semantic patches have been updated to better conform to Linux kernel developer expectations or to make the explanation message more clear. Finally, there is a fix for the coccicheck script" * 'for-5.14' of git://git.kernel.org/pub/scm/linux/kernel/git/jlawall/linux: coccinelle: api: remove kobj_to_dev.cocci script scripts: coccicheck: fix troubles on non-English builds coccinelle: misc: minmax: suppress patch generation for err returns drop unneeded *s coccinelle: irqf_oneshot: reduce the severity due to false positives coccinelle: misc: add swap script coccinelle: misc: update uninitialized_var.cocci documentation coccinelle: misc: restrict patch mode in flexible_array.cocci coccinelle: misc: add minmax script
2 parents 8e4f3e1 + 5e52344 commit 76e2d16

File tree

8 files changed

+384
-61
lines changed

8 files changed

+384
-61
lines changed

scripts/coccicheck

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ else
8787
fi
8888

8989
# Use only one thread per core by default if hyperthreading is enabled
90-
THREADS_PER_CORE=$(lscpu | grep "Thread(s) per core: " | tr -cd "[:digit:]")
90+
THREADS_PER_CORE=$(LANG=C lscpu | grep "Thread(s) per core: " | tr -cd "[:digit:]")
9191
if [ -z "$J" ]; then
9292
NPROC=$(getconf _NPROCESSORS_ONLN)
9393
if [ $THREADS_PER_CORE -gt 1 -a $NPROC -gt 4 ] ; then

scripts/coccinelle/api/kobj_to_dev.cocci

Lines changed: 0 additions & 45 deletions
This file was deleted.

scripts/coccinelle/free/kfree.cocci

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ position p1;
2222
@@
2323

2424
(
25-
* kfree@p1(E)
25+
kfree@p1(E)
2626
|
27-
* kfree_sensitive@p1(E)
27+
kfree_sensitive@p1(E)
2828
)
2929

3030
@print expression@
@@ -66,9 +66,9 @@ position ok;
6666

6767
while (1) { ...
6868
(
69-
* kfree@ok(E)
69+
kfree@ok(E)
7070
|
71-
* kfree_sensitive@ok(E)
71+
kfree_sensitive@ok(E)
7272
)
7373
... when != break;
7474
when != goto l;
@@ -84,9 +84,9 @@ position free.p1!=loop.ok,p2!={print.p,sz.p};
8484
@@
8585

8686
(
87-
* kfree@p1(E,...)
87+
kfree@p1(E,...)
8888
|
89-
* kfree_sensitive@p1(E,...)
89+
kfree_sensitive@p1(E,...)
9090
)
9191
...
9292
(

scripts/coccinelle/misc/flexible_array.cocci

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,40 @@ position p : script:python() { relevant(p) };
5151
};
5252
)
5353

54+
@only_field depends on patch@
55+
identifier name, array;
56+
type T;
57+
position q;
58+
@@
59+
60+
(
61+
struct name {@q
62+
T array[0];
63+
};
64+
|
65+
struct {@q
66+
T array[0];
67+
};
68+
)
69+
5470
@depends on patch@
5571
identifier name, array;
5672
type T;
5773
position p : script:python() { relevant(p) };
74+
// position @q with rule "only_field" simplifies
75+
// handling of bitfields, arrays, etc.
76+
position q != only_field.q;
5877
@@
5978

6079
(
61-
struct name {
80+
struct name {@q
6281
...
6382
T array@p[
6483
- 0
6584
];
6685
};
6786
|
68-
struct {
87+
struct {@q
6988
...
7089
T array@p[
7190
- 0

scripts/coccinelle/misc/irqf_oneshot.cocci

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ devm_request_threaded_irq@p(dev, irq, NULL, ...)
103103
@script:python depends on org@
104104
p << match.p;
105105
@@
106-
msg = "ERROR: Threaded IRQ with no primary handler requested without IRQF_ONESHOT"
106+
msg = "WARNING: Threaded IRQ with no primary handler requested without IRQF_ONESHOT (unless it is nested IRQ)"
107107
coccilib.org.print_todo(p[0],msg)
108108
109109
@script:python depends on report@
110110
p << match.p;
111111
@@
112-
msg = "ERROR: Threaded IRQ with no primary handler requested without IRQF_ONESHOT"
112+
msg = "WARNING: Threaded IRQ with no primary handler requested without IRQF_ONESHOT (unless it is nested IRQ)"
113113
coccilib.report.print_report(p[0],msg)

scripts/coccinelle/misc/minmax.cocci

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
///
3+
/// Check for opencoded min(), max() implementations.
4+
/// Generated patches sometimes require adding a cast to fix compile warning.
5+
/// Warnings/patches scope intentionally limited to a function body.
6+
///
7+
// Confidence: Medium
8+
// Copyright: (C) 2021 Denis Efremov ISPRAS
9+
// Options: --no-includes --include-headers
10+
//
11+
// Keywords: min, max
12+
//
13+
14+
15+
virtual report
16+
virtual org
17+
virtual context
18+
virtual patch
19+
20+
@rmax depends on !patch@
21+
identifier func;
22+
expression x, y;
23+
binary operator cmp = {>, >=};
24+
position p;
25+
@@
26+
27+
func(...)
28+
{
29+
<...
30+
* ((x) cmp@p (y) ? (x) : (y))
31+
...>
32+
}
33+
34+
@rmaxif depends on !patch@
35+
identifier func;
36+
expression x, y;
37+
expression max_val;
38+
binary operator cmp = {>, >=};
39+
position p;
40+
@@
41+
42+
func(...)
43+
{
44+
<...
45+
* if ((x) cmp@p (y)) {
46+
* max_val = (x);
47+
* } else {
48+
* max_val = (y);
49+
* }
50+
...>
51+
}
52+
53+
@rmin depends on !patch@
54+
identifier func;
55+
expression x, y;
56+
binary operator cmp = {<, <=};
57+
position p;
58+
@@
59+
60+
func(...)
61+
{
62+
<...
63+
* ((x) cmp@p (y) ? (x) : (y))
64+
...>
65+
}
66+
67+
@rminif depends on !patch@
68+
identifier func;
69+
expression x, y;
70+
expression min_val;
71+
binary operator cmp = {<, <=};
72+
position p;
73+
@@
74+
75+
func(...)
76+
{
77+
<...
78+
* if ((x) cmp@p (y)) {
79+
* min_val = (x);
80+
* } else {
81+
* min_val = (y);
82+
* }
83+
...>
84+
}
85+
86+
@pmax depends on patch@
87+
identifier func;
88+
expression x, y;
89+
binary operator cmp = {>=, >};
90+
@@
91+
92+
func(...)
93+
{
94+
<...
95+
- ((x) cmp (y) ? (x) : (y))
96+
+ max(x, y)
97+
...>
98+
}
99+
100+
@pmaxif depends on patch@
101+
identifier func;
102+
expression x, y;
103+
expression max_val;
104+
binary operator cmp = {>=, >};
105+
@@
106+
107+
func(...)
108+
{
109+
<...
110+
- if ((x) cmp (y)) {
111+
- max_val = x;
112+
- } else {
113+
- max_val = y;
114+
- }
115+
+ max_val = max(x, y);
116+
...>
117+
}
118+
119+
// Don't generate patches for errcode returns.
120+
@errcode depends on patch@
121+
position p;
122+
identifier func;
123+
expression x;
124+
binary operator cmp = {<, <=};
125+
@@
126+
127+
func(...)
128+
{
129+
<...
130+
return ((x) cmp@p 0 ? (x) : 0);
131+
...>
132+
}
133+
134+
@pmin depends on patch@
135+
identifier func;
136+
expression x, y;
137+
binary operator cmp = {<=, <};
138+
position p != errcode.p;
139+
@@
140+
141+
func(...)
142+
{
143+
<...
144+
- ((x) cmp@p (y) ? (x) : (y))
145+
+ min(x, y)
146+
...>
147+
}
148+
149+
@pminif depends on patch@
150+
identifier func;
151+
expression x, y;
152+
expression min_val;
153+
binary operator cmp = {<=, <};
154+
@@
155+
156+
func(...)
157+
{
158+
<...
159+
- if ((x) cmp (y)) {
160+
- min_val = x;
161+
- } else {
162+
- min_val = y;
163+
- }
164+
+ min_val = min(x, y);
165+
...>
166+
}
167+
168+
@script:python depends on report@
169+
p << rmax.p;
170+
@@
171+
172+
for p0 in p:
173+
coccilib.report.print_report(p0, "WARNING opportunity for max()")
174+
175+
@script:python depends on org@
176+
p << rmax.p;
177+
@@
178+
179+
for p0 in p:
180+
coccilib.org.print_todo(p0, "WARNING opportunity for max()")
181+
182+
@script:python depends on report@
183+
p << rmaxif.p;
184+
@@
185+
186+
for p0 in p:
187+
coccilib.report.print_report(p0, "WARNING opportunity for max()")
188+
189+
@script:python depends on org@
190+
p << rmaxif.p;
191+
@@
192+
193+
for p0 in p:
194+
coccilib.org.print_todo(p0, "WARNING opportunity for max()")
195+
196+
@script:python depends on report@
197+
p << rmin.p;
198+
@@
199+
200+
for p0 in p:
201+
coccilib.report.print_report(p0, "WARNING opportunity for min()")
202+
203+
@script:python depends on org@
204+
p << rmin.p;
205+
@@
206+
207+
for p0 in p:
208+
coccilib.org.print_todo(p0, "WARNING opportunity for min()")
209+
210+
@script:python depends on report@
211+
p << rminif.p;
212+
@@
213+
214+
for p0 in p:
215+
coccilib.report.print_report(p0, "WARNING opportunity for min()")
216+
217+
@script:python depends on org@
218+
p << rminif.p;
219+
@@
220+
221+
for p0 in p:
222+
coccilib.org.print_todo(p0, "WARNING opportunity for min()")

0 commit comments

Comments
 (0)