summaryrefslogtreecommitdiff
path: root/coccinelle
diff options
context:
space:
mode:
Diffstat (limited to 'coccinelle')
-rw-r--r--coccinelle/empty-if.cocci56
-rw-r--r--coccinelle/errno.cocci32
-rw-r--r--coccinelle/hashmap_free.cocci54
-rw-r--r--coccinelle/mfree.cocci6
-rw-r--r--coccinelle/no-if-assignments.cocci20
-rw-r--r--coccinelle/safe_close-no-if.cocci7
-rw-r--r--coccinelle/safe_close.cocci18
-rw-r--r--coccinelle/safe_closedir.cocci27
-rw-r--r--coccinelle/safe_fclose.cocci27
-rw-r--r--coccinelle/strempty.cocci10
-rw-r--r--coccinelle/strv_free.cocci27
-rw-r--r--coccinelle/while-true.cocci12
-rw-r--r--coccinelle/xsprintf.cocci6
13 files changed, 302 insertions, 0 deletions
diff --git a/coccinelle/empty-if.cocci b/coccinelle/empty-if.cocci
new file mode 100644
index 0000000000..026c461ee6
--- /dev/null
+++ b/coccinelle/empty-if.cocci
@@ -0,0 +1,56 @@
+@@
+expression e, f, g, h, i, j;
+statement s, t;
+@@
+(
+if (e) {
+(
+if (h) s
+|
+if (h) s else t
+|
+while (h) s
+|
+for (h; i; j) s
+)
+}
+|
+while (e) {
+(
+if (h) s
+|
+if (h) s else t
+|
+while (h) s
+|
+for (h; i; j) s
+)
+}
+|
+for (e; f; g) {
+(
+if (h) s
+|
+if (h) s else t
+|
+while (h) s
+|
+for (h; i; j) s
+)
+}
+|
+- if (e) {
++ if (e)
+s
+- }
+|
+- while (e) {
++ while (e)
+s
+- }
+|
+- for (e; f; g) {
++ for (e; f; g)
+s
+- }
+)
diff --git a/coccinelle/errno.cocci b/coccinelle/errno.cocci
new file mode 100644
index 0000000000..ed74c0a98a
--- /dev/null
+++ b/coccinelle/errno.cocci
@@ -0,0 +1,32 @@
+@@
+identifier log_LEVEL_errno =~ "^log_(debug|info|notice|warning|error|emergency)_errno$";
+local idexpression r;
+expression e;
+@@
+- r = -e;
++ r =
+ log_LEVEL_errno(e, ...);
+@@
+identifier log_LEVEL_errno =~ "^log_(debug|info|notice|warning|error|emergency)_errno$";
+local idexpression r;
+expression e;
+@@
++ r =
+ log_LEVEL_errno(e, ...);
+- r = -e;
+@@
+identifier log_LEVEL_errno =~ "^log_(debug|info|notice|warning|error|emergency)_errno$";
+local idexpression r;
+expression e;
+@@
+- r =
++ return
+ log_LEVEL_errno(e, ...);
+- return r;
+@@
+identifier log_LEVEL_errno =~ "^log_(debug|info|notice|warning|error|emergency)_errno$";
+expression e;
+@@
++ return
+ log_LEVEL_errno(e, ...);
+- return -e;
diff --git a/coccinelle/hashmap_free.cocci b/coccinelle/hashmap_free.cocci
new file mode 100644
index 0000000000..86b9542488
--- /dev/null
+++ b/coccinelle/hashmap_free.cocci
@@ -0,0 +1,54 @@
+@@
+expression p;
+@@
+- set_free(p);
+- p = NULL;
++ p = set_free(p);
+@@
+expression p;
+@@
+- if (p)
+- set_free(p);
+- p = NULL;
++ p = set_free(p);
+@@
+expression p;
+@@
+- if (p) {
+- set_free(p);
+- p = NULL;
+- }
++ p = set_free(p);
+@@
+expression p;
+@@
+- if (p)
+- set_free(p);
++ set_free(p);
+@@
+expression p;
+@@
+- hashmap_free(p);
+- p = NULL;
++ p = hashmap_free(p);
+@@
+expression p;
+@@
+- if (p)
+- hashmap_free(p);
+- p = NULL;
++ p = hashmap_free(p);
+@@
+expression p;
+@@
+- if (p) {
+- hashmap_free(p);
+- p = NULL;
+- }
++ p = hashmap_free(p);
+@@
+expression p;
+@@
+- if (p)
+- hashmap_free(p);
++ hashmap_free(p);
diff --git a/coccinelle/mfree.cocci b/coccinelle/mfree.cocci
new file mode 100644
index 0000000000..1389cd35db
--- /dev/null
+++ b/coccinelle/mfree.cocci
@@ -0,0 +1,6 @@
+@@
+expression p;
+@@
+- free(p);
+- p = NULL;
++ p = mfree(p);
diff --git a/coccinelle/no-if-assignments.cocci b/coccinelle/no-if-assignments.cocci
new file mode 100644
index 0000000000..9f63e90337
--- /dev/null
+++ b/coccinelle/no-if-assignments.cocci
@@ -0,0 +1,20 @@
+@@
+expression p, q;
+identifier r;
+statement s;
+@@
+- if ((r = q) < p)
+- s
++ r = q;
++ if (r < p)
++ s
+@@
+expression p, q;
+identifier r;
+statement s;
+@@
+- if ((r = q) >= p)
+- s
++ r = q;
++ if (r >= p)
++ s
diff --git a/coccinelle/safe_close-no-if.cocci b/coccinelle/safe_close-no-if.cocci
new file mode 100644
index 0000000000..81c5678518
--- /dev/null
+++ b/coccinelle/safe_close-no-if.cocci
@@ -0,0 +1,7 @@
+@@
+expression fd;
+@@
+- if (fd >= 0) {
+- fd = safe_close(fd);
+- }
++ fd = safe_close(fd);
diff --git a/coccinelle/safe_close.cocci b/coccinelle/safe_close.cocci
new file mode 100644
index 0000000000..6fedd804f2
--- /dev/null
+++ b/coccinelle/safe_close.cocci
@@ -0,0 +1,18 @@
+@@
+expression fd;
+@@
+- close(fd);
+- fd = -1;
++ fd = safe_close(fd);
+@@
+expression fd;
+@@
+- close_nointr(fd);
+- fd = -1;
++ fd = safe_close(fd);
+@@
+expression fd;
+@@
+- safe_close(fd);
+- fd = -1;
++ fd = safe_close(fd);
diff --git a/coccinelle/safe_closedir.cocci b/coccinelle/safe_closedir.cocci
new file mode 100644
index 0000000000..743ffd97ef
--- /dev/null
+++ b/coccinelle/safe_closedir.cocci
@@ -0,0 +1,27 @@
+@@
+expression p;
+@@
+- if (p) {
+- closedir(p);
+- p = NULL;
+- }
++ p = safe_closedir(p);
+@@
+expression p;
+@@
+- if (p)
+- closedir(p);
+- p = NULL;
++ p = safe_closedir(p);
+@@
+expression p;
+@@
+- closedir(p);
+- p = NULL;
++ p = safe_closedir(p);
+@@
+expression p;
+@@
+- if (p)
+- closedir(p);
++ safe_closedir(p);
diff --git a/coccinelle/safe_fclose.cocci b/coccinelle/safe_fclose.cocci
new file mode 100644
index 0000000000..6961cd0164
--- /dev/null
+++ b/coccinelle/safe_fclose.cocci
@@ -0,0 +1,27 @@
+@@
+expression p;
+@@
+- if (p) {
+- fclose(p);
+- p = NULL;
+- }
++ p = safe_fclose(p);
+@@
+expression p;
+@@
+- if (p)
+- fclose(p);
+- p = NULL;
++ p = safe_fclose(p);
+@@
+expression p;
+@@
+- fclose(p);
+- p = NULL;
++ p = safe_fclose(p);
+@@
+expression p;
+@@
+- if (p)
+- fclose(p);
++ safe_fclose(p);
diff --git a/coccinelle/strempty.cocci b/coccinelle/strempty.cocci
new file mode 100644
index 0000000000..e3bd0a1f56
--- /dev/null
+++ b/coccinelle/strempty.cocci
@@ -0,0 +1,10 @@
+@@
+expression s;
+@@
+- s ?: ""
++ strempty(s)
+@@
+expression s;
+@@
+- s ? s : ""
++ strempty(s)
diff --git a/coccinelle/strv_free.cocci b/coccinelle/strv_free.cocci
new file mode 100644
index 0000000000..0ad56f772f
--- /dev/null
+++ b/coccinelle/strv_free.cocci
@@ -0,0 +1,27 @@
+@@
+expression p;
+@@
+- strv_free(p);
+- p = NULL;
++ p = strv_free(p);
+@@
+expression p;
+@@
+- if (p)
+- strv_free(p);
+- p = NULL;
++ p = strv_free(p);
+@@
+expression p;
+@@
+- if (p) {
+- strv_free(p);
+- p = NULL;
+- }
++ p = strv_free(p);
+@@
+expression p;
+@@
+- if (p)
+- strv_free(p);
++ strv_free(p);
diff --git a/coccinelle/while-true.cocci b/coccinelle/while-true.cocci
new file mode 100644
index 0000000000..c23fb11f22
--- /dev/null
+++ b/coccinelle/while-true.cocci
@@ -0,0 +1,12 @@
+@@
+statement s;
+@@
+- while (true)
++ for (;;)
+s
+@@
+statement s;
+@@
+- while (1)
++ for (;;)
+s
diff --git a/coccinelle/xsprintf.cocci b/coccinelle/xsprintf.cocci
new file mode 100644
index 0000000000..401216ad72
--- /dev/null
+++ b/coccinelle/xsprintf.cocci
@@ -0,0 +1,6 @@
+@@
+expression e, fmt;
+expression list vaargs;
+@@
+- snprintf(e, sizeof(e), fmt, vaargs);
++ xsprintf(e, fmt, vaargs);