From 4f43cbe66cf8eb89e0dac4e7cfb26f42275a1c96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 21 May 2024 18:10:12 +0200 Subject: [PATCH 1/3] nspawn: use FOREACH_ARRAY() in one more place --- src/nspawn/nspawn.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 5842d3ba8fa..712fa654632 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -2251,23 +2251,22 @@ static int copy_devnodes(const char *dest) { } static int make_extra_nodes(const char *dest) { - size_t i; int r; BLOCK_WITH_UMASK(0000); - for (i = 0; i < arg_n_extra_nodes; i++) { + FOREACH_ARRAY(node, arg_extra_nodes, arg_n_extra_nodes) { _cleanup_free_ char *path = NULL; - DeviceNode *n = arg_extra_nodes + i; - path = path_join(dest, n->path); + path = path_join(dest, node->path); if (!path) return log_oom(); - if (mknod(path, n->mode, S_ISCHR(n->mode) || S_ISBLK(n->mode) ? makedev(n->major, n->minor) : 0) < 0) + dev_t dev = S_ISCHR(node->mode) || S_ISBLK(node->mode) ? makedev(node->major, node->minor) : 0; + if (mknod(path, node->mode, dev) < 0) return log_error_errno(errno, "Failed to create device node '%s': %m", path); - r = chmod_and_chown(path, n->mode, n->uid, n->gid); + r = chmod_and_chown(path, node->mode, node->uid, node->gid); if (r < 0) return log_error_errno(r, "Failed to adjust device node ownership of '%s': %m", path); } From cbd8fc859afc2e7cbc7850e2c062f8778cc93be2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 9 May 2024 10:57:54 +0200 Subject: [PATCH 2/3] core: simplify variable declaration It doesn't matter much, but right below there is a second declaration which already uses this style, and the mismatch was grating. --- src/core/dbus-unit.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c index 20fa43af9e3..5439ad52b5b 100644 --- a/src/core/dbus-unit.c +++ b/src/core/dbus-unit.c @@ -1370,8 +1370,7 @@ int bus_unit_method_get_processes(sd_bus_message *message, void *userdata, sd_bu if (r < 0) return r; - CGroupRuntime *crt; - crt = unit_get_cgroup_runtime(u); + CGroupRuntime *crt = unit_get_cgroup_runtime(u); if (crt && crt->cgroup_path) { r = append_cgroup(reply, crt->cgroup_path, pids); if (r < 0) From ab0137b44a4b0cf738381ef2109099dfd2f991a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 21 May 2024 09:08:48 +0200 Subject: [PATCH 3/3] shared/btrfs-util: simplify return conditions Coverity has trouble undertanding this function, so let's get rid of the redundant return branch to simplify the code. --- src/shared/btrfs-util.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/shared/btrfs-util.c b/src/shared/btrfs-util.c index d6b218d842f..a7881b8b7e7 100644 --- a/src/shared/btrfs-util.c +++ b/src/shared/btrfs-util.c @@ -1637,13 +1637,10 @@ int btrfs_qgroup_find_parents(int fd, uint64_t qgroupid, uint64_t **ret) { break; } - if (n_items <= 0) { - *ret = NULL; - return 0; - } + assert((n_items > 0) == !!items); + assert(n_items <= INT_MAX); *ret = TAKE_PTR(items); - return (int) n_items; }