diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-09-14 05:25:08 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-09-16 16:11:09 +0200 |
commit | 5bf5013fc9eea110820868ab404b426eddb3a71b (patch) | |
tree | 2add17f4c113f3cd958e8e033eeabd355ff219c1 | |
parent | dissect-image: fix memleak on failure (diff) | |
download | systemd-5bf5013fc9eea110820868ab404b426eddb3a71b.tar.xz systemd-5bf5013fc9eea110820868ab404b426eddb3a71b.zip |
dissect-image: handle all non-negative return values as success
No functional changes, just coding syle update.
-rw-r--r-- | src/shared/dissect-image.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index 82ed55d02b..93f70d7588 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -1957,11 +1957,10 @@ static int verity_partition( * https://gitlab.com/cryptsetup/cryptsetup/-/merge_requests/96 */ if (r == -EINVAL && FLAGS_SET(flags, DISSECT_IMAGE_VERITY_SHARE)) return verity_partition(designator, m, v, verity, flags & ~DISSECT_IMAGE_VERITY_SHARE, d); - if (!IN_SET(r, - 0, /* Success */ - -EEXIST, /* Volume is already open and ready to be used */ - -EBUSY, /* Volume is being opened but not ready, crypt_init_by_name can fetch details */ - -ENODEV /* Volume is being opened but not ready, crypt_init_by_name would fail, try to open again */)) + if (r < 0 && !IN_SET(r, + -EEXIST, /* Volume is already open and ready to be used */ + -EBUSY, /* Volume is being opened but not ready, crypt_init_by_name can fetch details */ + -ENODEV /* Volume is being opened but not ready, crypt_init_by_name would fail, try to open again */)) return r; if (IN_SET(r, -EEXIST, -EBUSY)) { _cleanup_(sym_crypt_freep) struct crypt_device *existing_cd = NULL; @@ -1972,7 +1971,7 @@ static int verity_partition( /* If activation returns EBUSY there might be no deferred removal to cancel, that's fine */ if (r < 0 && r != -ENXIO) return log_debug_errno(r, "Disabling automated deferred removal for verity device %s failed: %m", node); - if (r == 0) { + if (r >= 0) { restore_deferred_remove = strdup(name); if (!restore_deferred_remove) return -ENOMEM; @@ -1983,9 +1982,9 @@ static int verity_partition( /* Same as above, -EINVAL can randomly happen when it actually means -EEXIST */ if (r == -EINVAL && FLAGS_SET(flags, DISSECT_IMAGE_VERITY_SHARE)) return verity_partition(designator, m, v, verity, flags & ~DISSECT_IMAGE_VERITY_SHARE, d); - if (!IN_SET(r, 0, -ENODEV, -ENOENT, -EBUSY)) + if (r < 0 && !IN_SET(r, -ENODEV, -ENOENT, -EBUSY)) return log_debug_errno(r, "Checking whether existing verity device %s can be reused failed: %m", node); - if (r == 0) { + if (r >= 0) { usec_t timeout_usec = 100 * USEC_PER_MSEC; const char *e; @@ -2018,7 +2017,7 @@ static int verity_partition( cd = TAKE_PTR(existing_cd); } } - if (r == 0) + if (r >= 0) break; /* Device is being opened by another process, but it has not finished yet, yield for 2ms */ @@ -2027,7 +2026,7 @@ static int verity_partition( /* An existing verity device was reported by libcryptsetup/libdevmapper, but we can't use it at this time. * Fall back to activating it with a unique device name. */ - if (r != 0 && FLAGS_SET(flags, DISSECT_IMAGE_VERITY_SHARE)) + if (r < 0 && FLAGS_SET(flags, DISSECT_IMAGE_VERITY_SHARE)) return verity_partition(designator, m, v, verity, flags & ~DISSECT_IMAGE_VERITY_SHARE, d); /* Everything looks good and we'll be able to mount the device, so deferred remove will be re-enabled at that point. */ |