From: Dmitry V. Levin Date: Fri, 14 Jul 2023 08:00:00 +0000 (+0000) Subject: homework: cleanup use of ERRNO_IS_DEVICE_ABSENT() X-Git-Tag: v255-rc1~886^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0d16fab986a2147292d466ddf3315ceafcae0eef;p=thirdparty%2Fsystemd.git homework: cleanup use of ERRNO_IS_DEVICE_ABSENT() Given that ERRNO_IS_DEVICE_ABSENT() also matches positive values, make sure this macro is not called with arguments that do not have errno semantics. In this case the arguments passed to ERRNO_IS_DEVICE_ABSENT() are the values returned by external cryptsetup functions sym_crypt_init_by_name() and sym_crypt_deactivate_by_name() which are not expected to return any positive values, but let's be consistent anyway and move ERRNO_IS_DEVICE_ABSENT() invocations to the branches where the return values are known to be negative. --- diff --git a/src/home/homework-luks.c b/src/home/homework-luks.c index 06e346e1e04..7946e6c120b 100644 --- a/src/home/homework-luks.c +++ b/src/home/homework-luks.c @@ -498,10 +498,11 @@ static int acquire_open_luks_device( return r; r = sym_crypt_init_by_name(&cd, setup->dm_name); - if ((ERRNO_IS_DEVICE_ABSENT(r) || r == -EINVAL) && graceful) - return 0; - if (r < 0) + if (r < 0) { + if ((ERRNO_IS_DEVICE_ABSENT(r) || r == -EINVAL) && graceful) + return 0; return log_error_errno(r, "Failed to initialize cryptsetup context for %s: %m", setup->dm_name); + } cryptsetup_enable_logging(cd); @@ -1638,11 +1639,12 @@ int home_deactivate_luks(UserRecord *h, HomeSetup *setup) { cryptsetup_enable_logging(setup->crypt_device); r = sym_crypt_deactivate_by_name(setup->crypt_device, setup->dm_name, 0); - if (ERRNO_IS_DEVICE_ABSENT(r) || r == -EINVAL) - log_debug_errno(r, "LUKS device %s is already detached.", setup->dm_node); - else if (r < 0) - return log_info_errno(r, "LUKS device %s couldn't be deactivated: %m", setup->dm_node); - else { + if (r < 0) { + if (ERRNO_IS_DEVICE_ABSENT(r) || r == -EINVAL) + log_debug_errno(r, "LUKS device %s is already detached.", setup->dm_node); + else + return log_info_errno(r, "LUKS device %s couldn't be deactivated: %m", setup->dm_node); + } else { log_info("LUKS device detaching completed."); we_detached = true; }