From 38288f0bb843bf4c0ad7aacea5c81254b2d7d00b Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Sat, 21 Sep 2019 16:01:14 +0200 Subject: [PATCH] tree-wide: various code-formatting improvements Reported/found by Coccinelle --- src/basic/alloc-util.c | 2 +- src/basic/cgroup-util.c | 4 +--- src/network/generator/network-generator.c | 4 +--- src/network/networkd-link.c | 4 +--- src/nspawn/nspawn-mount.c | 5 +++-- src/shared/mount-util.c | 2 +- src/test/test-exit-status.c | 2 +- 7 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/basic/alloc-util.c b/src/basic/alloc-util.c index a16db6824f..5951e8c3d5 100644 --- a/src/basic/alloc-util.c +++ b/src/basic/alloc-util.c @@ -78,7 +78,7 @@ void* greedy_realloc(void **p, size_t *allocated, size_t need, size_t size) { * take possession of the extra space. This should be cheap, since libc doesn't have to move * the memory for this. */ - qq = realloc(q, bn * size); + qq = reallocarray(q, bn, size); if (_likely_(qq)) { *p = qq; *allocated = bn; diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index 7b5839ccd6..d5c33014d7 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -345,10 +345,8 @@ int cg_kill( a workaround for kernel bug. It was fixed in 5.2-rc5 (c03cd7738a83), backported to 4.19.66 (4340d175b898) and 4.14.138 (feb6b123b7dd). */ r = cg_unified_controller(controller); - if (r < 0) + if (r <= 0) return r; - if (r == 0) /* doesn't apply to legacy hierarchy */ - return 0; return cg_kill_items(controller, path, sig, flags, s, log_kill, userdata, "cgroup.threads"); } diff --git a/src/network/generator/network-generator.c b/src/network/generator/network-generator.c index 0b5af33566..81afa95307 100644 --- a/src/network/generator/network-generator.c +++ b/src/network/generator/network-generator.c @@ -837,9 +837,7 @@ static int parse_cmdline_bridge(Context *context, const char *key, const char *v _cleanup_free_ char *word = NULL; r = extract_first_word(&p, &word, ",", 0); - if (r == 0) - return 0; - if (r < 0) + if (r <= 0) return r; r = network_set_bridge(context, word, name); diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 50648b29a1..54cbc678b4 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -1915,10 +1915,8 @@ static int link_append_to_master(Link *link, NetDev *netdev) { return r; r = set_put(master->slaves, link); - if (r < 0) + if (r <= 0) return r; - if (r == 0) - return 0; link_ref(link); return 0; diff --git a/src/nspawn/nspawn-mount.c b/src/nspawn/nspawn-mount.c index 140df4e16b..2f842754a4 100644 --- a/src/nspawn/nspawn-mount.c +++ b/src/nspawn/nspawn-mount.c @@ -703,8 +703,9 @@ static int parse_mount_bind_options(const char *options, unsigned long *mount_fl else if (streq(word, "norbind")) flags &= ~MS_REC; else { - log_error("Invalid bind mount option: %s", word); - return -EINVAL; + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "Invalid bind mount option: %s", + word); } } diff --git a/src/shared/mount-util.c b/src/shared/mount-util.c index b6ff8d8c84..e55d3c2315 100644 --- a/src/shared/mount-util.c +++ b/src/shared/mount-util.c @@ -85,7 +85,7 @@ static int get_mount_flags(const char *path, unsigned long *flags, struct libmnt int r = 0; fs = mnt_table_find_target(table, path, MNT_ITER_FORWARD); - if (fs == NULL) { + if (!fs) { log_warning("Could not find '%s' in mount table", path); goto fallback; } diff --git a/src/test/test-exit-status.c b/src/test/test-exit-status.c index a007bda5c4..e90375f6bd 100644 --- a/src/test/test-exit-status.c +++ b/src/test/test-exit-status.c @@ -14,7 +14,7 @@ static void test_exit_status_to_string(void) { class = exit_status_class(i); log_info("%d: %s%s%s%s", i, s ?: "-", - class ? " (" : "", class ?: "", class ? ")" : ""); + class ? " (" : "", strempty(class), class ? ")" : ""); if (s) assert_se(exit_status_from_string(s) == i);