summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-11-16 14:42:14 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-11-16 16:05:29 +0100
commitf20db199541ea35c65edfeed9e5401cab6fe6bac (patch)
tree0c697e7e98ceb7e48a7776a401e2229a25aa6ee2
parenttests: run fuzzers four times in a row (#10794) (diff)
downloadsystemd-f20db199541ea35c65edfeed9e5401cab6fe6bac.tar.xz
systemd-f20db199541ea35c65edfeed9e5401cab6fe6bac.zip
cocci: simplify some if checks
-rw-r--r--coccinelle/redundant-if.cocci54
-rw-r--r--src/basic/cgroup-util.c4
-rw-r--r--src/core/manager.c4
-rw-r--r--src/resolve/resolved-dns-dnssec.c12
4 files changed, 59 insertions, 15 deletions
diff --git a/coccinelle/redundant-if.cocci b/coccinelle/redundant-if.cocci
new file mode 100644
index 0000000000..515e36e151
--- /dev/null
+++ b/coccinelle/redundant-if.cocci
@@ -0,0 +1,54 @@
+@@
+expression r;
+@@
+- if (r < 0)
+- return r;
+- if (r == 0)
+- return 0;
++ if (r <= 0)
++ return r;
+@@
+expression r;
+@@
+- if (r == 0)
+- return 0;
+- if (r < 0)
+- return r;
++ if (r <= 0)
++ return r;
+@@
+expression r;
+@@
+- if (r < 0)
+- return r;
+- if (r == 0)
+- return r;
++ if (r <= 0)
++ return r;
+@@
+expression r;
+@@
+- if (r == 0)
+- return r;
+- if (r < 0)
+- return r;
++ if (r <= 0)
++ return r;
+@@
+expression r;
+@@
+- if (r < 0)
+- return r;
+- if (r > 0)
+- return r;
++ if (r != 0)
++ return r;
+@@
+expression r;
+@@
+- if (r > 0)
+- return r;
+- if (r < 0)
+- return r;
++ if (r != 0)
++ return r;
diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c
index 5c02f0cb35..70c91249d7 100644
--- a/src/basic/cgroup-util.c
+++ b/src/basic/cgroup-util.c
@@ -199,10 +199,8 @@ int cg_rmdir(const char *controller, const char *path) {
return -errno;
r = cg_hybrid_unified();
- if (r < 0)
+ if (r <= 0)
return r;
- if (r == 0)
- return 0;
if (streq(controller, SYSTEMD_CGROUP_CONTROLLER)) {
r = cg_rmdir(SYSTEMD_CGROUP_CONTROLLER_LEGACY, path);
diff --git a/src/core/manager.c b/src/core/manager.c
index 3150740e05..1f739bf22b 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -2788,10 +2788,8 @@ static int manager_dispatch_timezone_change(
log_debug("inotify event for /etc/localtime");
changed = manager_read_timezone_stat(m);
- if (changed < 0)
+ if (changed <= 0)
return changed;
- if (!changed)
- return 0;
/* Something changed, restart the watch, to ensure we watch the new /etc/localtime if it changed */
(void) manager_setup_timezone_change(m);
diff --git a/src/resolve/resolved-dns-dnssec.c b/src/resolve/resolved-dns-dnssec.c
index 86a9a58c5b..a837414ca1 100644
--- a/src/resolve/resolved-dns-dnssec.c
+++ b/src/resolve/resolved-dns-dnssec.c
@@ -1378,17 +1378,13 @@ static int nsec3_is_good(DnsResourceRecord *rr, DnsResourceRecord *nsec3) {
a = dns_resource_key_name(rr->key);
r = dns_name_parent(&a); /* strip off hash */
- if (r < 0)
+ if (r <= 0)
return r;
- if (r == 0)
- return 0;
b = dns_resource_key_name(nsec3->key);
r = dns_name_parent(&b); /* strip off hash */
- if (r < 0)
+ if (r <= 0)
return r;
- if (r == 0)
- return 0;
/* Make sure both have the same parent */
return dns_name_equal(a, b);
@@ -2096,10 +2092,8 @@ static int dnssec_test_positive_wildcard_nsec3(
for (;;) {
next_closer = name;
r = dns_name_parent(&name);
- if (r < 0)
+ if (r <= 0)
return r;
- if (r == 0)
- return 0;
r = dns_name_equal(name, source);
if (r < 0)