From ccd52940d06fc6ba06f44f7ea64f056529c0beb0 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Mon, 29 Apr 2019 16:12:41 +0200 Subject: [PATCH] coccinelle: further restrict certain transformations Some transformations generate results we don't want to keep, so let's disable such transformations for specific files. Also, disable const-strlen.cocci everywhere, as the STRLEN macro has a pretty limited scope, so the transformation generates false positives in most cases. --- ...nst-strlen.cocci => const-strlen.disabled} | 0 coccinelle/dup-fcntl.cocci | 4 +- coccinelle/flags-set.cocci | 19 ++--- coccinelle/isempty.cocci | 72 +++++++------------ coccinelle/synthetic-errno.cocci | 6 ++ 5 files changed, 46 insertions(+), 55 deletions(-) rename coccinelle/{const-strlen.cocci => const-strlen.disabled} (100%) diff --git a/coccinelle/const-strlen.cocci b/coccinelle/const-strlen.disabled similarity index 100% rename from coccinelle/const-strlen.cocci rename to coccinelle/const-strlen.disabled diff --git a/coccinelle/dup-fcntl.cocci b/coccinelle/dup-fcntl.cocci index ef13564282..8b133b3a24 100644 --- a/coccinelle/dup-fcntl.cocci +++ b/coccinelle/dup-fcntl.cocci @@ -1,5 +1,7 @@ @@ +/* We want to stick with dup() in test-fd-util.c */ +position p : script:python() { p[0].file != "src/test/test-fd-util.c" }; expression fd; @@ -- dup(fd) +- dup@p(fd) + fcntl(fd, F_DUPFD, 3) diff --git a/coccinelle/flags-set.cocci b/coccinelle/flags-set.cocci index 1a70717e76..73966b02e5 100644 --- a/coccinelle/flags-set.cocci +++ b/coccinelle/flags-set.cocci @@ -1,15 +1,16 @@ @@ +/* Disable this transformation for the securebits-util.h, as it makes + * the expression there confusing. */ +position p : script:python() { p[0].file != "src/shared/securebits-util.h" }; expression x, y; @@ -- ((x) & (y)) == (y) +( +- ((x@p) & (y)) == (y) + FLAGS_SET(x, y) -@@ -expression x, y; -@@ -- (x & (y)) == (y) +| +- (x@p & (y)) == (y) + FLAGS_SET(x, y) -@@ -expression x, y; -@@ -- ((x) & y) == y +| +- ((x@p) & y) == y + FLAGS_SET(x, y) +) diff --git a/coccinelle/isempty.cocci b/coccinelle/isempty.cocci index d8d5275889..e0a9f07ca6 100644 --- a/coccinelle/isempty.cocci +++ b/coccinelle/isempty.cocci @@ -1,60 +1,42 @@ @@ +/* Disable this transformation for the test-string-util.c */ +position p : script:python() { p[0].file != "src/test/test-string-util.c" }; expression s; @@ -- strv_length(s) == 0 +( +- strv_length@p(s) == 0 + strv_isempty(s) -@@ -expression s; -@@ -- strv_length(s) <= 0 +| +- strv_length@p(s) <= 0 + strv_isempty(s) -@@ -expression s; -@@ -- strv_length(s) > 0 +| +- strv_length@p(s) > 0 + !strv_isempty(s) -@@ -expression s; -@@ -- strv_length(s) != 0 +| +- strv_length@p(s) != 0 + !strv_isempty(s) -@@ -expression s; -@@ -- strlen(s) == 0 +| +- strlen@p(s) == 0 + isempty(s) -@@ -expression s; -@@ -- strlen(s) <= 0 +| +- strlen@p(s) <= 0 + isempty(s) -@@ -expression s; -@@ -- strlen(s) > 0 +| +- strlen@p(s) > 0 + !isempty(s) -@@ -expression s; -@@ -- strlen(s) != 0 +| +- strlen@p(s) != 0 + !isempty(s) -@@ -expression s; -@@ -- strlen_ptr(s) == 0 +| +- strlen_ptr@p(s) == 0 + isempty(s) -@@ -expression s; -@@ -- strlen_ptr(s) <= 0 +| +- strlen_ptr@p(s) <= 0 + isempty(s) -@@ -expression s; -@@ -- strlen_ptr(s) > 0 +| +- strlen_ptr@p(s) > 0 + !isempty(s) -@@ -expression s; -@@ -- strlen_ptr(s) != 0 +| +- strlen_ptr@p(s) != 0 + !isempty(s) +) diff --git a/coccinelle/synthetic-errno.cocci b/coccinelle/synthetic-errno.cocci index 645bfc945f..3ddb69cb4c 100644 --- a/coccinelle/synthetic-errno.cocci +++ b/coccinelle/synthetic-errno.cocci @@ -2,9 +2,15 @@ expression e; expression list args; @@ +( +/* Ignore one specific case in src/shared/bootspec.c where we want to stick + * with the log_debug() + return pattern */ +log_debug("Found no default boot entry :("); +| - log_debug(args); - return -e; + return log_debug_errno(SYNTHETIC_ERRNO(e), args); +) @@ expression e; expression list args;