From fae98e8341ae34f2ec0dcd8636b52d14e96cf5b2 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Tue, 3 Nov 2026 15:10:34 +0100 Subject: [PATCH] shared: comment bare literal arguments docs/CODING_STYLE.md asks for a /* name= */ comment whenever NULL or another value meaning "unset" is passed to a function. Add it wherever a bare NULL, 0, false or true is passed for a parameter with a telling name. Mechanical, generated by tools/check-argument-comments.py --fix. While at it, add the '=' that some of the existing comments are missing. By hand, drop the /* uncompressed */ in dns_packet_read_rr() which only repeats the new comment, and wrap the get_mempolicy() call in numa-util.c that grew to 141 columns. --- src/shared/bpf-util.h | 2 +- src/shared/bus-wait-for-units.c | 2 +- src/shared/data-fd-util.c | 2 +- src/shared/dns-packet.c | 2 +- src/shared/image-policy.c | 2 +- src/shared/mount-util.c | 22 +++++++++++----------- src/shared/mstack.c | 10 +++++----- src/shared/numa-util.c | 3 ++- src/shared/seccomp-util.c | 4 ++-- src/shared/uapi16-manifest.c | 6 +++--- 10 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/shared/bpf-util.h b/src/shared/bpf-util.h index 88457483f90..9a212a2e53d 100644 --- a/src/shared/bpf-util.h +++ b/src/shared/bpf-util.h @@ -96,7 +96,7 @@ static inline int compat_bpf_map_create( value_size, max_entries, opts); return sym_bpf_create_map(map_type, key_size, value_size, max_entries, - 0 /* opts->map_flags, but opts is always NULL for us so skip build dependency on the type */); + /* map_flags= */ 0 /* opts->map_flags, but opts is always NULL for us so skip build dependency on the type */); } /* libbpf sometimes returns error codes that make sense only in the kernel, like 524 for EOPNOTSUPP. Use diff --git a/src/shared/bus-wait-for-units.c b/src/shared/bus-wait-for-units.c index 7293bf90653..ac65e027a58 100644 --- a/src/shared/bus-wait-for-units.c +++ b/src/shared/bus-wait-for-units.c @@ -246,7 +246,7 @@ static void bus_wait_for_units_check_ready(BusWaitForUnits *d) { d->state = d->has_failed ? BUS_WAIT_FAILURE : BUS_WAIT_SUCCESS; if (d->event) - (void) sd_event_exit(d->event, 0); + (void) sd_event_exit(d->event, /* code= */ 0); } static void wait_for_item_fail(WaitForItem *item) { diff --git a/src/shared/data-fd-util.c b/src/shared/data-fd-util.c index 4405bf3c047..6b1041e0f3c 100644 --- a/src/shared/data-fd-util.c +++ b/src/shared/data-fd-util.c @@ -85,7 +85,7 @@ int copy_data_fd_full(int fd, uint64_t max_size) { /* If we have reason to believe this will fit fine in /tmp, then use that as first fallback. */ if ((!S_ISREG(st.st_mode) || (uint64_t) st.st_size < DATA_FD_TMP_LIMIT)) { - tmp_fd = open_tmpfile_unlinkable(NULL /* NULL as directory means /tmp */, O_RDWR); + tmp_fd = open_tmpfile_unlinkable(/* directory= */ NULL /* NULL as directory means /tmp */, O_RDWR); if (tmp_fd < 0) return tmp_fd; diff --git a/src/shared/dns-packet.c b/src/shared/dns-packet.c index 74b72c081f4..12a67f7405d 100644 --- a/src/shared/dns-packet.c +++ b/src/shared/dns-packet.c @@ -2399,7 +2399,7 @@ int dns_packet_read_rr( if (r < 0) return r; - r = dns_packet_read_name(p, &rr->svcb.target_name, false /* uncompressed */, /* start= */ NULL); + r = dns_packet_read_name(p, &rr->svcb.target_name, /* allow_compression= */ false, /* start= */ NULL); if (r < 0) return r; diff --git a/src/shared/image-policy.c b/src/shared/image-policy.c index cfabd3042ce..436a5616a77 100644 --- a/src/shared/image-policy.c +++ b/src/shared/image-policy.c @@ -799,7 +799,7 @@ int config_parse_image_policy( return 0; } - r = image_policy_from_string(rvalue, /* graceful */ true, &np); + r = image_policy_from_string(rvalue, /* graceful= */ true, &np); if (r == -ENOTUNIQ) return log_syntax(unit, LOG_ERR, filename, line, r, "Duplicate rule in image policy, refusing: %s", rvalue); if (r == -EBADSLT) diff --git a/src/shared/mount-util.c b/src/shared/mount-util.c index 821f190a528..61db151f399 100644 --- a/src/shared/mount-util.c +++ b/src/shared/mount-util.c @@ -2021,14 +2021,14 @@ int fsmount_credentials_fs(int *ret_fsfd) { if (fs_fd < 0) return -errno; - if (fsconfig(fs_fd, FSCONFIG_SET_STRING, "nr_inodes", "1024", 0) < 0) + if (fsconfig(fs_fd, FSCONFIG_SET_STRING, "nr_inodes", "1024", /* aux= */ 0) < 0) return -errno; xsprintf(size_str, "%" PRIu64, CREDENTIALS_TOTAL_SIZE_MAX); - if (fsconfig(fs_fd, FSCONFIG_SET_STRING, "size", size_str, 0) < 0) + if (fsconfig(fs_fd, FSCONFIG_SET_STRING, "size", size_str, /* aux= */ 0) < 0) return -errno; - if (fsconfig(fs_fd, FSCONFIG_SET_FLAG, "noswap", NULL, 0) < 0) { + if (fsconfig(fs_fd, FSCONFIG_SET_FLAG, "noswap", /* value= */ NULL, /* aux= */ 0) < 0) { if (errno != EINVAL) return -errno; @@ -2037,10 +2037,10 @@ int fsmount_credentials_fs(int *ret_fsfd) { close_and_replace(fs_fd, ramfs_fd); } - if (fsconfig(fs_fd, FSCONFIG_SET_STRING, "mode", "0700", 0) < 0) + if (fsconfig(fs_fd, FSCONFIG_SET_STRING, "mode", "0700", /* aux= */ 0) < 0) return -errno; - if (fsconfig(fs_fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0) < 0) + if (fsconfig(fs_fd, FSCONFIG_CMD_CREATE, /* key= */ NULL, /* value= */ NULL, /* aux= */ 0) < 0) return -errno; unsigned mount_attrs = ms_flags_to_mount_attr(credentials_fs_mount_flags(/* ro = */ false)); @@ -2109,11 +2109,11 @@ int make_fsmount( if (fs_fd < 0) return log_full_errno(error_log_level, errno, "Failed to open superblock for \"%s\": %m", type); - if (fsconfig(fs_fd, FSCONFIG_SET_STRING, "source", what, 0) < 0) + if (fsconfig(fs_fd, FSCONFIG_SET_STRING, "source", what, /* aux= */ 0) < 0) return log_full_errno(error_log_level, errno, "Failed to set mount source for \"%s\" to \"%s\": %m", type, what); if (FLAGS_SET(f, MS_RDONLY)) - if (fsconfig(fs_fd, FSCONFIG_SET_FLAG, "ro", NULL, 0) < 0) + if (fsconfig(fs_fd, FSCONFIG_SET_FLAG, "ro", /* value= */ NULL, /* aux= */ 0) < 0) return log_full_errno(error_log_level, errno, "Failed to set read only mount flag for \"%s\": %m", type); for (const char *p = o;;) { @@ -2131,18 +2131,18 @@ int make_fsmount( *eq = 0; eq++; - if (fsconfig(fs_fd, FSCONFIG_SET_STRING, word, eq, 0) < 0) + if (fsconfig(fs_fd, FSCONFIG_SET_STRING, word, eq, /* aux= */ 0) < 0) return log_full_errno(error_log_level, errno, "Failed to set mount option \"%s=%s\" for \"%s\": %m", word, eq, type); } else { - if (fsconfig(fs_fd, FSCONFIG_SET_FLAG, word, NULL, 0) < 0) + if (fsconfig(fs_fd, FSCONFIG_SET_FLAG, word, /* value= */ NULL, /* aux= */ 0) < 0) return log_full_errno(error_log_level, errno, "Failed to set mount flag \"%s\" for \"%s\": %m", word, type); } } - if (fsconfig(fs_fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0) < 0) + if (fsconfig(fs_fd, FSCONFIG_CMD_CREATE, /* key= */ NULL, /* value= */ NULL, /* aux= */ 0) < 0) return log_full_errno(error_log_level, errno, "Failed to realize fs fd for \"%s\" (\"%s\"): %m", what, type); - mnt_fd = fsmount(fs_fd, FSMOUNT_CLOEXEC, 0); + mnt_fd = fsmount(fs_fd, FSMOUNT_CLOEXEC, /* attr_flags= */ 0); if (mnt_fd < 0) return log_full_errno(error_log_level, errno, "Failed to create mount fd for \"%s\" (\"%s\"): %m", what, type); diff --git a/src/shared/mstack.c b/src/shared/mstack.c index 179c158870a..0cb0462a943 100644 --- a/src/shared/mstack.c +++ b/src/shared/mstack.c @@ -904,7 +904,7 @@ static int mstack_make_overlayfs( report_errno_and_exit(errno_pipe_fds[1], /* error= */ 0); } - _cleanup_close_ int overlayfs_mnt_fd = fsmount(sb_fd, FSMOUNT_CLOEXEC, 0); + _cleanup_close_ int overlayfs_mnt_fd = fsmount(sb_fd, FSMOUNT_CLOEXEC, /* attr_flags= */ 0); if (overlayfs_mnt_fd < 0) return log_debug_errno(errno, "Failed to create mount fd: %m"); @@ -951,16 +951,16 @@ int mstack_make_mounts( if (sb_fd < 0) return log_debug_errno(errno, "Failed to create tmpfs: %m"); - if (fsconfig(sb_fd, FSCONFIG_SET_STRING, "source", mstack->path, 0) < 0) + if (fsconfig(sb_fd, FSCONFIG_SET_STRING, "source", mstack->path, /* aux= */ 0) < 0) return log_debug_errno(errno, "Failed to set mount source: %m"); - if (fsconfig(sb_fd, FSCONFIG_SET_STRING, "mode", "0755", 0) < 0) + if (fsconfig(sb_fd, FSCONFIG_SET_STRING, "mode", "0755", /* aux= */ 0) < 0) return log_debug_errno(errno, "Failed to set mount source: %m"); - if (fsconfig(sb_fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0) < 0) + if (fsconfig(sb_fd, FSCONFIG_CMD_CREATE, /* key= */ NULL, /* value= */ NULL, /* aux= */ 0) < 0) return log_debug_errno(errno, "Failed to realize tmpfs: %m"); - mstack->root_mount_fd = fsmount(sb_fd, FSMOUNT_CLOEXEC, 0); + mstack->root_mount_fd = fsmount(sb_fd, FSMOUNT_CLOEXEC, /* attr_flags= */ 0); if (mstack->root_mount_fd < 0) return log_debug_errno(errno, "Failed to create mount fd: %m"); diff --git a/src/shared/numa-util.c b/src/shared/numa-util.c index af8770106e3..53e026d362e 100644 --- a/src/shared/numa-util.c +++ b/src/shared/numa-util.c @@ -72,7 +72,8 @@ int apply_numa_policy(const NUMAPolicy *policy) { assert(policy); - if (get_mempolicy(NULL, NULL, 0, NULL, 0) < 0 && errno == ENOSYS) + if (get_mempolicy(/* mode= */ NULL, /* nodemask= */ NULL, /* maxnode= */ 0, + /* addr= */ NULL, /* flags= */ 0) < 0 && errno == ENOSYS) /* NUMA syscall interface not available (kernel compiled without NUMA support). * Return -ENOSYS so callers can distinguish this from -EOPNOTSUPP, which we * return below when the syscall interface exists but the requested policy is diff --git a/src/shared/seccomp-util.c b/src/shared/seccomp-util.c index 9bd5d8392fd..45ae95d4188 100644 --- a/src/shared/seccomp-util.c +++ b/src/shared/seccomp-util.c @@ -2228,7 +2228,7 @@ static int add_personality_rules(scmp_filter_ctx seccomp, uint32_t arch, uint32_ assert((value & ~mask) == 0); BIT_FOREACH(bit, value) { - r = add_personality_rule(seccomp, arch, INDEX_TO_MASK(uint32_t, bit), 0); + r = add_personality_rule(seccomp, arch, INDEX_TO_MASK(uint32_t, bit), /* value= */ 0); if (r < 0) return r; } @@ -2281,7 +2281,7 @@ int seccomp_restrict_read_implies_exec(void) { if (r < 0) return r; - r = add_personality_rules(seccomp, arch, READ_IMPLIES_EXEC, 0); + r = add_personality_rules(seccomp, arch, READ_IMPLIES_EXEC, /* value= */ 0); if (r < 0) return r; diff --git a/src/shared/uapi16-manifest.c b/src/shared/uapi16-manifest.c index b1bdfe073e2..bff48145756 100644 --- a/src/shared/uapi16-manifest.c +++ b/src/shared/uapi16-manifest.c @@ -115,7 +115,7 @@ bool uapi16_name_is_valid(const char *s) { if (!path_is_normalized(s)) return false; - if (string_has_cc(s, NULL)) + if (string_has_cc(s, /* ok= */ NULL)) return false; if (uapi16_manifest_filename_is_reserved(s)) @@ -130,7 +130,7 @@ bool uapi16_xattr_name_is_valid(const char *s) { return !isempty(s) && utf8_is_valid(s) && - !string_has_cc(s, NULL); + !string_has_cc(s, /* ok= */ NULL); } static int json_dispatch_uapi16_name(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { @@ -426,7 +426,7 @@ int uapi16_xattrs_build_json(const Uapi16Xattr *x, size_t n, sd_json_variant **r assert(ret); _cleanup_(sd_json_variant_unrefp) sd_json_variant *ns = NULL; - r = sd_json_variant_new_object(&ns, NULL, 0); + r = sd_json_variant_new_object(&ns, /* array= */ NULL, 0); if (r < 0) return r;