diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/coccinelle/error_propagate_null.cocci | 10 | ||||
-rw-r--r-- | scripts/coccinelle/remove_local_err.cocci | 29 | ||||
-rw-r--r-- | scripts/coccinelle/return_directly.cocci | 19 |
3 files changed, 58 insertions, 0 deletions
diff --git a/scripts/coccinelle/error_propagate_null.cocci b/scripts/coccinelle/error_propagate_null.cocci new file mode 100644 index 0000000000..c23638007a --- /dev/null +++ b/scripts/coccinelle/error_propagate_null.cocci @@ -0,0 +1,10 @@ +// error_propagate() already ignores local_err==NULL, so there's +// no need to check it before calling. + +@@ +identifier L; +expression E; +@@ +-if (L) { + error_propagate(E, L); +-} diff --git a/scripts/coccinelle/remove_local_err.cocci b/scripts/coccinelle/remove_local_err.cocci new file mode 100644 index 0000000000..9261c99687 --- /dev/null +++ b/scripts/coccinelle/remove_local_err.cocci @@ -0,0 +1,29 @@ +// Replace unnecessary usage of local_err variable with +// direct usage of errp argument + +@@ +identifier F; +expression list ARGS; +expression F2; +identifier LOCAL_ERR; +identifier ERRP; +idexpression V; +typedef Error; +@@ + F(..., Error **ERRP) + { + ... +- Error *LOCAL_ERR; + ... when != LOCAL_ERR + when != ERRP +( +- F2(ARGS, &LOCAL_ERR); +- error_propagate(ERRP, LOCAL_ERR); ++ F2(ARGS, ERRP); +| +- V = F2(ARGS, &LOCAL_ERR); +- error_propagate(ERRP, LOCAL_ERR); ++ V = F2(ARGS, ERRP); +) + ... when != LOCAL_ERR + } diff --git a/scripts/coccinelle/return_directly.cocci b/scripts/coccinelle/return_directly.cocci new file mode 100644 index 0000000000..48680f2c2a --- /dev/null +++ b/scripts/coccinelle/return_directly.cocci @@ -0,0 +1,19 @@ +// replace 'R = X; return R;' with 'return R;' +@@ +identifier VAR; +expression E; +type T; +identifier F; +@@ + T F(...) + { + ... +- T VAR; + ... when != VAR + +- VAR = ++ return + E; +- return VAR; + ... when != VAR + } |