]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cryptsetup: cleanup use of ERRNO_IS_NOT_SUPPORTED()
authorDmitry V. Levin <ldv@strace.io>
Fri, 14 Jul 2023 08:00:00 +0000 (08:00 +0000)
committerDmitry V. Levin <ldv@strace.io>
Fri, 28 Jul 2023 12:28:35 +0000 (12:28 +0000)
Given that ERRNO_IS_NOT_SUPPORTED() also matches positive values,
make sure this macro is not called with arguments that do not have
errno semantics.

In this case the argument passed to ERRNO_IS_NOT_SUPPORTED() is the
value returned by find_tpm2_auto_data() which is not expected to return
any positive values, but let's be consistent anyway and move the
ERRNO_IS_NOT_SUPPORTED() invocation to the branch where
the return value is known to be negative.

src/cryptsetup/cryptsetup.c

index 31dff24b57e91af794fa252ab45b1002f5ad9c40..f62401b9bcb387721e17195aac1254230fc3bb27 100644 (file)
@@ -1728,10 +1728,11 @@ static int attach_luks_or_plain_or_bitlk_by_tpm2(
                                                               found_some
                                                               ? "No TPM2 metadata matching the current system state found in LUKS2 header, falling back to traditional unlocking."
                                                               : "No TPM2 metadata enrolled in LUKS2 header, falling back to traditional unlocking.");
-                                if (ERRNO_IS_NOT_SUPPORTED(r))  /* TPM2 support not compiled in? */
-                                        return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN), "TPM2 support not available, falling back to traditional unlocking.");
-                                if (r < 0)
+                                if (r < 0) {
+                                        if (ERRNO_IS_NOT_SUPPORTED(r))  /* TPM2 support not compiled in? */
+                                                return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN), "TPM2 support not available, falling back to traditional unlocking.");
                                         return r;
+                                }
 
                                 found_some = true;