]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: various fixlets suggested by Coccinelle
authorFrantisek Sumsal <frantisek@sumsal.cz>
Wed, 4 Mar 2026 18:03:54 +0000 (19:03 +0100)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Thu, 5 Mar 2026 09:27:58 +0000 (10:27 +0100)
24 files changed:
src/basic/socket-util.c
src/import/pull.c
src/libsystemd-network/test-dhcp-server.c
src/libsystemd/sd-varlink/sd-varlink.c
src/login/logind-session-device.c
src/machine/machined-dbus.c
src/mount/mount-tool.c
src/network/generator/network-generator.c
src/network/networkd-wwan.c
src/oom/oomd-manager.c
src/resolve/resolved-dns-browse-services.c
src/resolve/resolved-hook.c
src/resolve/test-dns-packet-append.c
src/resolve/test-dns-packet-extract.c
src/resolve/test-dns-query.c
src/resolve/test-dns-rr.c
src/shared/discover-image.c
src/shared/hostname-setup.c
src/shared/libfido2-util.c
src/ssh-generator/ssh-issue.c
src/systemctl/systemctl-compat-shutdown.c
src/sysupdate/sysupdate.c
src/udev/udev-builtin-dissect_image.c
src/udev/udev-worker.c

index 1194eafc1b0cdae196c1a3fa05bc76ff58ebebea..159486f7f1e52facd0d51b61c9155b8d4cd12e89 100644 (file)
@@ -1150,10 +1150,8 @@ int flush_accept(int fd) {
                 r = fd_wait_for_event(fd, POLLIN, 0);
                 if (r == -EINTR)
                         continue;
-                if (r < 0)
+                if (r <= 0)
                         return r;
-                if (r == 0)
-                        return 0;
 
                 if (iteration >= MAX_FLUSH_ITERATIONS)
                         return log_debug_errno(SYNTHETIC_ERRNO(EBUSY),
index e2f816152698f689d8e0fd8c5dcf5d7edce2d9b5..f8b90ad725a362ac4de2c68479388fc38033fcae 100644 (file)
@@ -454,8 +454,7 @@ static int parse_argv(int argc, char *argv[]) {
                                                                "64 hex character SHA256 hash required when specifying explicit checksum, %zu specified", n * 2);
 
                                 iovec_done(&arg_checksum);
-                                arg_checksum.iov_base = TAKE_PTR(h);
-                                arg_checksum.iov_len = n;
+                                arg_checksum = IOVEC_MAKE(TAKE_PTR(h), n);
 
                                 arg_import_flags &= ~(IMPORT_PULL_SETTINGS|IMPORT_PULL_ROOTHASH|IMPORT_PULL_ROOTHASH_SIGNATURE|IMPORT_PULL_VERITY);
                                 arg_verify = _IMPORT_VERIFY_INVALID;
index 7789037011e7d3ab1a3ddb9833481a7fafaa5aa4..e84d800ad81980ee7558c3065c7ed526514039e8 100644 (file)
@@ -68,7 +68,7 @@ static int test_basic(bool bind_to_interface) {
         r = sd_dhcp_server_start(server);
         /* skip test if running in an environment with no full networking support, CONFIG_PACKET not
          * compiled in kernel, nor af_packet module available. */
-        if (r == -EPERM || r == -EAFNOSUPPORT)
+        if (IN_SET(r, -EPERM, -EAFNOSUPPORT))
                 return r;
         ASSERT_OK(r);
 
index 534e141554404b2e808e7710fb0f86ab6c3550d0..f868f11850b573b51e0cac1c2e8c8a056af442a1 100644 (file)
@@ -3411,7 +3411,7 @@ _public_ int sd_varlink_set_allow_fd_passing_output(sd_varlink *v, int b) {
         if (r < 0)
                 return r;
 
-        v->allow_fd_passing_output = !!b;
+        v->allow_fd_passing_output = b;
         return 1;
 }
 
index 7129f823e8aad7e7125ec9f0f74890505880313c..137db8e93e1d8a9f26a0251bdc7015bf3c93fd89 100644 (file)
@@ -105,9 +105,8 @@ static void sd_eviocrevoke(int fd) {
                 if (errno == EINVAL) {
                         log_warning_errno(errno, "Kernel does not support evdev-revocation, continuing without revoking device access: %m");
                         warned = true;
-                } else if (errno != ENODEV) {
+                } else if (errno != ENODEV)
                         log_warning_errno(errno, "Failed to revoke evdev device, continuing without revoking device access: %m");
-                }
         }
 }
 
index 31237c811a9e7928fbb83f0aed5834c6d437b1db..ab7ca94fd01bd0b0d637b8060d0ab43136a8f1e7 100644 (file)
@@ -316,10 +316,8 @@ static int machine_add_from_params(
                                 details,
                                 &manager->polkit_registry,
                                 error);
-                if (r < 0)
-                        return r;
-                if (r == 0)
-                        return 0; /* Will call us back */
+                if (r <= 0)
+                        return r; /* 0 means Polkit will call us back, see method_create_machine() */
         }
 
         r = manager_add_machine(manager, name, &m);
index b2ee90f4b7ada79bef3899af57c348948044f9cb..d2af4688abb27e9e00f4bf79939fc5b4c4da83fb 100644 (file)
@@ -1321,10 +1321,8 @@ static int acquire_removable(sd_device *d) {
                         return r;
 
                 r = device_in_subsystem(d, "block");
-                if (r < 0)
+                if (r <= 0)
                         return r;
-                if (r == 0)
-                        return 0;
         }
 
         if (parse_boolean(v) <= 0)
index 0988aef93f14bc4aac0f73fb818b3b7c6d40d91f..d0204366fb6abf968e10091acc49424de8dcf4cc 100644 (file)
@@ -1439,12 +1439,11 @@ void netdev_dump(NetDev *netdev, FILE *f) {
         if (netdev->mtu > 0)
                 fprintf(f, "MTUBytes=%" PRIu32 "\n", netdev->mtu);
 
-        if (streq(netdev->kind, "vlan")) {
+        if (streq(netdev->kind, "vlan"))
                 fprintf(f,
                         "\n[VLAN]\n"
                         "Id=%u\n",
                         netdev->vlan_id);
-        }
 }
 
 void link_dump(Link *link, FILE *f) {
index ccd72d0ee31b3581c188dddde685b47a40a78c97..b84ace130102aa021dba781465919edfd0173cc6 100644 (file)
@@ -152,11 +152,8 @@ Modem* modem_free(Modem *modem) {
         if (!modem)
                 return NULL;
 
-        if (modem->bearers_by_name)
-                hashmap_free(modem->bearers_by_name);
-
-        if (modem->bearers_by_path)
-                hashmap_free(modem->bearers_by_path);
+        hashmap_free(modem->bearers_by_name);
+        hashmap_free(modem->bearers_by_path);
 
         if (modem->manager)
                 hashmap_remove_value(modem->manager->modems_by_path, modem->path, modem);
index b2142dd43cf335560d6ffdf91b78f6201e5d2610..97ad9c0a9f77f0c37afb68859a6441700065ac91 100644 (file)
@@ -422,7 +422,7 @@ static int monitor_swap_contexts_handler(sd_event_source *s, uint64_t usec, void
                 if (r < 0)
                         log_error_errno(r, "Failed to select any cgroups based on swap: %m");
                 else {
-                        if (selected && r > 0) {
+                        if (selected && r > 0)
                                 log_notice("Marked %s for killing due to memory used (%"PRIu64") / total (%"PRIu64") and "
                                            "swap used (%"PRIu64") / total (%"PRIu64") being more than "
                                            PERMYRIAD_AS_PERCENT_FORMAT_STR,
@@ -430,7 +430,6 @@ static int monitor_swap_contexts_handler(sd_event_source *s, uint64_t usec, void
                                            m->system_context.mem_used, m->system_context.mem_total,
                                            m->system_context.swap_used, m->system_context.swap_total,
                                            PERMYRIAD_AS_PERCENT_FORMAT_VAL(m->swap_used_limit_permyriad));
-                        }
                         return 0;
                 }
         }
index f08b83cf5dcb46689c6acd2cb162a7e578cfd46e..68dcbee349bb558f02987675e5ef40813d90eef4 100644 (file)
@@ -441,9 +441,9 @@ int mdns_manage_services_answer(DnsServiceBrowser *sb, DnsAnswer *answer, int ow
                                                 browse_service_update_event_to_string(
                                                                 BROWSE_SERVICE_UPDATE_REMOVED)),
                                 SD_JSON_BUILD_PAIR_INTEGER("family", owner_family),
-                                SD_JSON_BUILD_PAIR_STRING("name", name ?: ""),
-                                SD_JSON_BUILD_PAIR_STRING("type", type ?: ""),
-                                SD_JSON_BUILD_PAIR_STRING("domain", domain ?: ""),
+                                SD_JSON_BUILD_PAIR_STRING("name", strempty(name)),
+                                SD_JSON_BUILD_PAIR_STRING("type", strempty(type)),
+                                SD_JSON_BUILD_PAIR_STRING("domain", strempty(domain)),
                                 SD_JSON_BUILD_PAIR_INTEGER("ifindex", ifindex));
                 if (r < 0) {
                         log_error_errno(r, "Failed to build JSON for removed service: %m");
index 5cec36c3aa2d62009748c95b65779dc1eb0598ba..4938e2d2a104dbfbcad93a30a7a93622b536f30e 100644 (file)
@@ -49,7 +49,7 @@ static Hook* hook_free(Hook *h) {
         if (!h)
                 return NULL;
 
-        mfree(h->socket_path);
+        free(h->socket_path);
         sd_varlink_unref(h->filter_link);
         set_free(h->idle_links);
 
index eaffc57184e9655c575e29cd81266a9f845c1151..862f3bea6969230016c2916bdfc369f8ad51b9ff 100644 (file)
@@ -1180,7 +1180,7 @@ static DnsSvcParam* add_svcb_param(DnsResourceRecord *rr, uint16_t key, const ch
         param->key = key;
         param->length = len;
 
-        if (value != NULL)
+        if (value)
                 memcpy(param->value, value, len);
 
         LIST_APPEND(params, rr->svcb.params, param);
index dfbfd832f2b864cf5c09633733f10749563877ff..ca90afb7eb1dced91cdd6fb5963fb76655b7f972 100644 (file)
@@ -3902,7 +3902,7 @@ static DnsSvcParam* add_svcb_param(DnsResourceRecord *rr, uint16_t key, const ch
         param->key = key;
         param->length = len;
 
-        if (value != NULL)
+        if (value)
                 memcpy(param->value, value, len);
 
         LIST_APPEND(params, rr->svcb.params, param);
index 3fcc93d9e4fab368defa7498b065611cadbf8e34..9c1e2a73a55a9ec3a7b5c893db7d626f5a6515a3 100644 (file)
@@ -858,7 +858,7 @@ static void exercise_dns_query_go(GoConfig *cfg, void (*check_query)(DnsQuery *q
         ASSERT_NOT_NULL(query);
         ASSERT_TRUE(dns_query_go(query));
 
-        if (check_query != NULL)
+        if (check_query)
                 check_query(query);
 }
 
index c679e45beeb94b66d16793196a202002184b5942..e45f1d34238b090e685276fcd6af0569b08e4e8d 100644 (file)
@@ -2043,7 +2043,7 @@ static DnsSvcParam* add_svcb_param(DnsResourceRecord *rr, uint16_t key, const ch
         param->key = key;
         param->length = len;
 
-        if (value != NULL)
+        if (value)
                 memcpy(param->value, value, len);
 
         LIST_APPEND(params, rr->svcb.params, param);
index 4c0752c97912825d060bd19055232bda9c0ac8c0..dd924523158ba6f7d837c3e1c7c75e8d6fab0a74 100644 (file)
@@ -2187,10 +2187,8 @@ int image_setup_pool(RuntimeScope scope, ImageClass class, bool use_btrfs_subvol
                 return r;
 
         r = check_btrfs(pool);
-        if (r < 0)
+        if (r <= 0)
                 return r;
-        if (r == 0)
-                return 0;
 
         if (!use_btrfs_subvol)
                 return 0;
index 50a0f077fa7bffdc89ac06783abc43c9e01dd981..ee88e2a877b777412e7d525a3e902c431d5984b2 100644 (file)
@@ -284,8 +284,8 @@ int hostname_substitute_wildcards(char *name) {
 
                         struct siphash state;
                         siphash24_init(&state, key.bytes);
-                        siphash24_compress(&mid, sizeof(mid), &state);
-                        siphash24_compress(&counter, sizeof(counter), &state); /* counter mode */
+                        siphash24_compress_typesafe(mid, &state);
+                        siphash24_compress_typesafe(counter, &state); /* counter mode */
                         h = siphash24_finalize(&state);
                         left_bits = sizeof(h) * 8;
                         counter++;
index 338b52881e8ab7d05994038a781005a8559c20ab..b4aee235a9923cfdc3f7d1600db5c7756b95b153 100644 (file)
@@ -1244,7 +1244,7 @@ int fido2_list_devices(void) {
                 goto finish;
         }
 
-        if (table_get_rows(t) > 1)
+        if (!table_isempty(t))
                 printf("\n"
                        "%1$sLegend: RK        %2$s Resident key%3$s\n"
                        "%1$s        CLIENTPIN %2$s PIN request%3$s\n"
index 852dabdb852d1388f0c3be163428d9158373fc9a..d2f02bd3d8a4d95cc7d71eea2da685fb8bbc7cc8 100644 (file)
@@ -95,7 +95,7 @@ static int parse_argv(int argc, char *argv[]) {
                         break;
 
                 case ARG_ISSUE_PATH:
-                        if (isempty(optarg) || streq(optarg, "-")) {
+                        if (empty_or_dash(optarg)) {
                                 arg_issue_path = mfree(arg_issue_path);
                                 arg_issue_stdout = true;
                                 break;
index 877ea8378b3759894fd888382eeb58c5f0a2507e..cfc917073ae0e70a05fc3865eb5e262e035c2368 100644 (file)
@@ -108,14 +108,13 @@ static int parse_shutdown_time_spec(const char *t, usec_t *ret) {
                         if (r < 0)
                                 return r;
 
-                        if (tm.tm_hour != requested_hour || tm.tm_min != requested_min) {
+                        if (tm.tm_hour != requested_hour || tm.tm_min != requested_min)
                                 log_warning("Requested shutdown time %02d:%02d does not exist. "
                                             "Rescheduling to %02d:%02d.",
                                             requested_hour,
                                             requested_min,
                                             tm.tm_hour,
                                             tm.tm_min);
-                        }
                 }
 
                 *ret = s;
index 7693ec373caac3eeedffe6e066322a4ec9dcea56..69848c3fcb7ebdd4d59cfa436453ad643a1d2cc4 100644 (file)
@@ -397,13 +397,12 @@ static int context_discover_update_sets_by_flag(Context *c, UpdateSetFlags flags
                                 assert(flags == UPDATE_INSTALLED);
 
                                 match = resource_find_instance(&t->target, cursor);
-                                if (!match && !(extra_flags & (UPDATE_PARTIAL|UPDATE_PENDING))) {
+                                if (!match && !(extra_flags & (UPDATE_PARTIAL|UPDATE_PENDING)))
                                         /* When we're looking for installed versions, let's be robust and treat
                                          * an incomplete installation as an installation. Otherwise, there are
                                          * situations that can lead to sysupdate wiping the currently booted OS.
                                          * See https://github.com/systemd/systemd/issues/33339 */
                                         extra_flags |= UPDATE_INCOMPLETE;
-                                }
                         }
 
                         cursor_instances[k] = match;
index 8b706a7f9a32febf5d98d6184707adbbca555fe7..0fd58ef2f56067a9b76d2bf2bca931bd105e53be 100644 (file)
@@ -192,7 +192,7 @@ static int verb_probe(UdevEvent *event, sd_device *dev) {
                                 (void) image_policy_to_string(image_policy, /* simplify= */ false, &a);
                                 (void) image_policy_to_string(image_policy_mangled, /* simplify= */ false, &b);
 
-                                log_device_debug_errno(dev, ERFKILL, "Couldn't dissect block device with regular policy '%s', retrying with policy where root/usr are set to ignore '%s'.", a, b);
+                                log_device_debug_errno(dev, SYNTHETIC_ERRNO(ERFKILL), "Couldn't dissect block device with regular policy '%s', retrying with policy where root/usr are set to ignore '%s'.", a, b);
                         }
 
                         r = dissect_loop_device(
index 67617203d765f949a1a38d65010407d2a8a5026c..a0c95d2ce330d3f8734c4429c4759aaa25ea956b 100644 (file)
@@ -157,10 +157,8 @@ static int worker_mark_block_device_read_only(sd_device *dev) {
                 return 0;
 
         r = device_in_subsystem(dev, "block");
-        if (r < 0)
+        if (r <= 0)
                 return r;
-        if (r == 0)
-                return 0;
 
         /* Exclude synthetic devices for now, this is supposed to be a safety feature to avoid modification
          * of physical devices, and what sits on top of those doesn't really matter if we don't allow the