From d0aec7d4daa0670411613de4e9c3cd444a8a216f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sun, 12 Jun 2022 20:51:41 +0200 Subject: [PATCH 1/3] sd-id128: avoid an unnecessary function call in inline helper When optimizing, the compiler will most likely replace the call to memcmp(), but at -O0, the code that is emitted builds the call preamble and does the call. Let's use the same pattern as with sd_id128_is_null() and sd_id128_is_allf() and avoid the call. --- src/systemd/sd-id128.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/systemd/sd-id128.h b/src/systemd/sd-id128.h index f7d3244bb3..2aa41623ce 100644 --- a/src/systemd/sd-id128.h +++ b/src/systemd/sd-id128.h @@ -116,7 +116,7 @@ int sd_id128_get_boot_app_specific(sd_id128_t app_id, sd_id128_t *ret); #a #b #c #d "-" #e #f "-" #g #h "-" #i #j "-" #k #l #m #n #o #p _sd_pure_ static __inline__ int sd_id128_equal(sd_id128_t a, sd_id128_t b) { - return memcmp(&a, &b, 16) == 0; + return a.qwords[0] == b.qwords[0] && a.qwords[1] == b.qwords[1]; } _sd_pure_ static __inline__ int sd_id128_is_null(sd_id128_t a) { From 55ce4e1bcb1d802fe6eef2aba84d9228fa66549b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 30 Jun 2022 14:32:49 +0200 Subject: [PATCH 2/3] sd-journal: silence bogus gcc warning In function 'sd_id128_equal', inlined from 'journal_file_verify' at ../src/libsystemd/sd-journal/journal-verify.c:1047:29: ../src/systemd/sd-id128.h:119:43: error: 'entry_boot_id.qwords[0]' may be used uninitialized [-Werror=maybe-uninitialized] 119 | return a.qwords[0] == b.qwords[0] && a.qwords[1] == b.qwords[1]; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../src/libsystemd/sd-journal/journal-verify.c: In function 'journal_file_verify': ../src/libsystemd/sd-journal/journal-verify.c:823:20: note: 'entry_boot_id.qwords[0]' was declared here 823 | sd_id128_t entry_boot_id; | ^~~~~~~~~~~~~ cc1: all warnings being treated as errors entry_boot_id is only used when entry_monotonic_set has been set, and that's only done in one place where entry_boot_id is also initalized. --- src/journal/journalctl.c | 2 +- src/libsystemd/sd-journal/journal-verify.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 6ee49a6913..127c3d491b 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -2164,7 +2164,7 @@ int main(int argc, char *argv[]) { bool previous_boot_id_valid = false, first_line = true, ellipsized = false, need_seek = false; bool use_cursor = false, after_cursor = false; _cleanup_(sd_journal_closep) sd_journal *j = NULL; - sd_id128_t previous_boot_id; + sd_id128_t previous_boot_id = {}; /* Unnecessary initialization to appease gcc */ int n_shown = 0, r, poll_fd = -1; setlocale(LC_ALL, ""); diff --git a/src/libsystemd/sd-journal/journal-verify.c b/src/libsystemd/sd-journal/journal-verify.c index 1495450394..08b86f9758 100644 --- a/src/libsystemd/sd-journal/journal-verify.c +++ b/src/libsystemd/sd-journal/journal-verify.c @@ -815,7 +815,7 @@ int journal_file_verify( uint64_t p = 0, last_epoch = 0, last_tag_realtime = 0, last_sealed_realtime = 0; uint64_t entry_seqnum = 0, entry_monotonic = 0, entry_realtime = 0; - sd_id128_t entry_boot_id; + sd_id128_t entry_boot_id = {}; /* Unnecessary initialization to appease gcc */ bool entry_seqnum_set = false, entry_monotonic_set = false, entry_realtime_set = false, found_main_entry_array = false; uint64_t n_weird = 0, n_objects = 0, n_entries = 0, n_data = 0, n_fields = 0, n_data_hash_tables = 0, n_field_hash_tables = 0, n_entry_arrays = 0, n_tags = 0; usec_t last_usec = 0; From 1474e66a52c2d53aed91b101b9dc5fbb632b303c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 1 Jul 2022 15:44:39 +0200 Subject: [PATCH 3/3] homework: silence gcc warning gcc was warning that found_fs_uuid was used unitialized. The issue stemmed from the call to open(), where gcc seemingly didn't know that errno must be negative. When that is set, we can drop some unnecessary initializations without warnings. --- src/home/homework-luks.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/home/homework-luks.c b/src/home/homework-luks.c index 100b0e1650..0ab8e207cd 100644 --- a/src/home/homework-luks.c +++ b/src/home/homework-luks.c @@ -179,7 +179,7 @@ static int probe_file_system_by_path(const char *path, char **ret_fstype, sd_id1 fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NONBLOCK); if (fd < 0) - return -errno; + return negative_errno(); return probe_file_system_by_fd(fd, ret_fstype, ret_uuid); } @@ -1229,7 +1229,7 @@ int home_setup_luks( PasswordCache *cache, UserRecord **ret_luks_home) { - sd_id128_t found_partition_uuid = SD_ID128_NULL, found_luks_uuid = SD_ID128_NULL, found_fs_uuid = SD_ID128_NULL; + sd_id128_t found_partition_uuid, found_fs_uuid, found_luks_uuid = SD_ID128_NULL; _cleanup_(user_record_unrefp) UserRecord *luks_home = NULL; _cleanup_(erase_and_freep) void *volume_key = NULL; size_t volume_key_size = 0;