diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2016-10-14 18:03:08 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-10-14 18:03:08 -0400 |
commit | 50cff89837a43a7c62ac080de9742a298d6418b3 (patch) | |
tree | 28e12a9565ec81ac7bac6d433de0e2d05e6dade5 | |
parent | 84d69848c97faab0c25aa2667b273404d2e2a64a (diff) | |
parent | c8990359d4b12f14656386526ddf904635076902 (diff) |
Merge branch 'misc' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild
Pull misc kbuild changes from Michal Marek:
"Just a few patches on the kbuild.git#misc branch this time:
- New Coccinelle patch by Nicholas Mc Guire
- Existing patch fixes by Julia Lawall
- Minor comment fix by Markus Elfring"
* 'misc' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild:
Coccinelle: flag conditions with no effect
scripts/coccicheck: Update reference for the corresponding documentation
Coccinelle: pm_runtime: ensure relevance of pm_runtime reports
Coccinelle: limit memdup_user transformation to GFP_KERNEL case
-rwxr-xr-x | scripts/coccicheck | 2 | ||||
-rw-r--r-- | scripts/coccinelle/api/memdup_user.cocci | 8 | ||||
-rw-r--r-- | scripts/coccinelle/api/pm_runtime.cocci | 18 | ||||
-rw-r--r-- | scripts/coccinelle/misc/cond_no_effect.cocci | 64 |
4 files changed, 80 insertions, 12 deletions
diff --git a/scripts/coccicheck b/scripts/coccicheck index c92c1528a54d..ec487b8e7051 100755 --- a/scripts/coccicheck +++ b/scripts/coccicheck | |||
@@ -1,7 +1,7 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | # Linux kernel coccicheck | 2 | # Linux kernel coccicheck |
3 | # | 3 | # |
4 | # Read Documentation/coccinelle.txt | 4 | # Read Documentation/dev-tools/coccinelle.rst |
5 | # | 5 | # |
6 | # This script requires at least spatch | 6 | # This script requires at least spatch |
7 | # version 1.0.0-rc11. | 7 | # version 1.0.0-rc11. |
diff --git a/scripts/coccinelle/api/memdup_user.cocci b/scripts/coccinelle/api/memdup_user.cocci index c606231b0e46..2a5aea8e8487 100644 --- a/scripts/coccinelle/api/memdup_user.cocci +++ b/scripts/coccinelle/api/memdup_user.cocci | |||
@@ -15,11 +15,11 @@ virtual org | |||
15 | virtual report | 15 | virtual report |
16 | 16 | ||
17 | @depends on patch@ | 17 | @depends on patch@ |
18 | expression from,to,size,flag; | 18 | expression from,to,size; |
19 | identifier l1,l2; | 19 | identifier l1,l2; |
20 | @@ | 20 | @@ |
21 | 21 | ||
22 | - to = \(kmalloc\|kzalloc\)(size,flag); | 22 | - to = \(kmalloc\|kzalloc\)(size,GFP_KERNEL); |
23 | + to = memdup_user(from,size); | 23 | + to = memdup_user(from,size); |
24 | if ( | 24 | if ( |
25 | - to==NULL | 25 | - to==NULL |
@@ -37,12 +37,12 @@ identifier l1,l2; | |||
37 | - } | 37 | - } |
38 | 38 | ||
39 | @r depends on !patch@ | 39 | @r depends on !patch@ |
40 | expression from,to,size,flag; | 40 | expression from,to,size; |
41 | position p; | 41 | position p; |
42 | statement S1,S2; | 42 | statement S1,S2; |
43 | @@ | 43 | @@ |
44 | 44 | ||
45 | * to = \(kmalloc@p\|kzalloc@p\)(size,flag); | 45 | * to = \(kmalloc@p\|kzalloc@p\)(size,GFP_KERNEL); |
46 | if (to==NULL || ...) S1 | 46 | if (to==NULL || ...) S1 |
47 | if (copy_from_user(to, from, size) != 0) | 47 | if (copy_from_user(to, from, size) != 0) |
48 | S2 | 48 | S2 |
diff --git a/scripts/coccinelle/api/pm_runtime.cocci b/scripts/coccinelle/api/pm_runtime.cocci index 89b98a2f7a6f..d67ccf5f8227 100644 --- a/scripts/coccinelle/api/pm_runtime.cocci +++ b/scripts/coccinelle/api/pm_runtime.cocci | |||
@@ -17,9 +17,10 @@ virtual report | |||
17 | 17 | ||
18 | @runtime_bad_err_handle exists@ | 18 | @runtime_bad_err_handle exists@ |
19 | expression ret; | 19 | expression ret; |
20 | position p; | ||
20 | @@ | 21 | @@ |
21 | ( | 22 | ( |
22 | ret = \(pm_runtime_idle\| | 23 | ret@p = \(pm_runtime_idle\| |
23 | pm_runtime_suspend\| | 24 | pm_runtime_suspend\| |
24 | pm_runtime_autosuspend\| | 25 | pm_runtime_autosuspend\| |
25 | pm_runtime_resume\| | 26 | pm_runtime_resume\| |
@@ -47,12 +48,13 @@ IS_ERR_VALUE(ret) | |||
47 | // For context mode | 48 | // For context mode |
48 | //---------------------------------------------------------- | 49 | //---------------------------------------------------------- |
49 | 50 | ||
50 | @depends on runtime_bad_err_handle && context@ | 51 | @depends on context@ |
51 | identifier pm_runtime_api; | 52 | identifier pm_runtime_api; |
52 | expression ret; | 53 | expression ret; |
54 | position runtime_bad_err_handle.p; | ||
53 | @@ | 55 | @@ |
54 | ( | 56 | ( |
55 | ret = pm_runtime_api(...); | 57 | ret@p = pm_runtime_api(...); |
56 | ... | 58 | ... |
57 | * IS_ERR_VALUE(ret) | 59 | * IS_ERR_VALUE(ret) |
58 | ... | 60 | ... |
@@ -62,12 +64,13 @@ ret = pm_runtime_api(...); | |||
62 | // For patch mode | 64 | // For patch mode |
63 | //---------------------------------------------------------- | 65 | //---------------------------------------------------------- |
64 | 66 | ||
65 | @depends on runtime_bad_err_handle && patch@ | 67 | @depends on patch@ |
66 | identifier pm_runtime_api; | 68 | identifier pm_runtime_api; |
67 | expression ret; | 69 | expression ret; |
70 | position runtime_bad_err_handle.p; | ||
68 | @@ | 71 | @@ |
69 | ( | 72 | ( |
70 | ret = pm_runtime_api(...); | 73 | ret@p = pm_runtime_api(...); |
71 | ... | 74 | ... |
72 | - IS_ERR_VALUE(ret) | 75 | - IS_ERR_VALUE(ret) |
73 | + ret < 0 | 76 | + ret < 0 |
@@ -78,13 +81,14 @@ ret = pm_runtime_api(...); | |||
78 | // For org and report mode | 81 | // For org and report mode |
79 | //---------------------------------------------------------- | 82 | //---------------------------------------------------------- |
80 | 83 | ||
81 | @r depends on runtime_bad_err_handle && (org || report) exists@ | 84 | @r depends on (org || report) exists@ |
82 | position p1, p2; | 85 | position p1, p2; |
83 | identifier pm_runtime_api; | 86 | identifier pm_runtime_api; |
84 | expression ret; | 87 | expression ret; |
88 | position runtime_bad_err_handle.p; | ||
85 | @@ | 89 | @@ |
86 | ( | 90 | ( |
87 | ret = pm_runtime_api@p1(...); | 91 | ret@p = pm_runtime_api@p1(...); |
88 | ... | 92 | ... |
89 | IS_ERR_VALUE@p2(ret) | 93 | IS_ERR_VALUE@p2(ret) |
90 | ... | 94 | ... |
diff --git a/scripts/coccinelle/misc/cond_no_effect.cocci b/scripts/coccinelle/misc/cond_no_effect.cocci new file mode 100644 index 000000000000..8467dbd1c465 --- /dev/null +++ b/scripts/coccinelle/misc/cond_no_effect.cocci | |||
@@ -0,0 +1,64 @@ | |||
1 | ///Find conditions where if and else branch are functionally | ||
2 | // identical. | ||
3 | // | ||
4 | // There can be false positives in cases where the positional | ||
5 | // information is used (as with lockdep) or where the identity | ||
6 | // is a placeholder for not yet handled cases. | ||
7 | // Unfortunately there also seems to be a tendency to use | ||
8 | // the last if else/else as a "default behavior" - which some | ||
9 | // might consider a legitimate coding pattern. From discussion | ||
10 | // on kernelnewbies though it seems that this is not really an | ||
11 | // accepted pattern and if at all it would need to be commented | ||
12 | // | ||
13 | // In the Linux kernel it does not seem to actually report | ||
14 | // false positives except for those that were documented as | ||
15 | // being intentional. | ||
16 | // the two known cases are: | ||
17 | // arch/sh/kernel/traps_64.c:read_opcode() | ||
18 | // } else if ((pc & 1) == 0) { | ||
19 | // /* SHcompact */ | ||
20 | // /* TODO : provide handling for this. We don't really support | ||
21 | // user-mode SHcompact yet, and for a kernel fault, this would | ||
22 | // have to come from a module built for SHcompact. */ | ||
23 | // return -EFAULT; | ||
24 | // } else { | ||
25 | // /* misaligned */ | ||
26 | // return -EFAULT; | ||
27 | // } | ||
28 | // fs/kernfs/file.c:kernfs_fop_open() | ||
29 | // * Both paths of the branch look the same. They're supposed to | ||
30 | // * look that way and give @of->mutex different static lockdep keys. | ||
31 | // */ | ||
32 | // if (has_mmap) | ||
33 | // mutex_init(&of->mutex); | ||
34 | // else | ||
35 | // mutex_init(&of->mutex); | ||
36 | // | ||
37 | // All other cases look like bugs or at least lack of documentation | ||
38 | // | ||
39 | // Confidence: Moderate | ||
40 | // Copyright: (C) 2016 Nicholas Mc Guire, OSADL. GPLv2. | ||
41 | // Comments: | ||
42 | // Options: --no-includes --include-headers | ||
43 | |||
44 | virtual org | ||
45 | virtual report | ||
46 | |||
47 | @cond@ | ||
48 | statement S1; | ||
49 | position p; | ||
50 | @@ | ||
51 | |||
52 | * if@p (...) S1 else S1 | ||
53 | |||
54 | @script:python depends on org@ | ||
55 | p << cond.p; | ||
56 | @@ | ||
57 | |||
58 | cocci.print_main("WARNING: possible condition with no effect (if == else)",p) | ||
59 | |||
60 | @script:python depends on report@ | ||
61 | p << cond.p; | ||
62 | @@ | ||
63 | |||
64 | coccilib.report.print_report(p[0],"WARNING: possible condition with no effect (if == else)") | ||