chiark / gitweb /
tree-wide: drop redundant if checks before safe_close()
authorLennart Poettering <lennart@poettering.net>
Tue, 8 Sep 2015 16:58:28 +0000 (18:58 +0200)
committerSven Eden <yamakuzure@gmx.net>
Wed, 29 Mar 2017 08:45:09 +0000 (10:45 +0200)
Replace this:

        if (fd >= 0)
                safe_close(fd);

by this:

        safe_close(fd);

coccinelle/safe_close-no-if.cocci [new file with mode: 0644]
src/login/logind-button.c

diff --git a/coccinelle/safe_close-no-if.cocci b/coccinelle/safe_close-no-if.cocci
new file mode 100644 (file)
index 0000000..81c5678
--- /dev/null
@@ -0,0 +1,7 @@
+@@
+expression fd;
+@@
+- if (fd >= 0) {
+- fd = safe_close(fd);
+- }
++ fd = safe_close(fd);
index 3324c46..92c1b67 100644 (file)
@@ -239,9 +239,7 @@ int button_open(Button *b) {
 
         assert(b);
 
-        if (b->fd >= 0) {
-                b->fd = safe_close(b->fd);
-        }
+        b->fd = safe_close(b->fd);
 
         p = strjoina("/dev/input/", b->name);