From 60997a87ef91d53fd9f4594eb982d6a7e4fbd1ec Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Sat, 3 May 2025 21:01:54 +0200 Subject: [PATCH] blockdev-util: don't use mixed style of retval in block_device_get_originating We have two typical styles of 'ret' param assignment + retval: 1) < 0 on actual error, 0 on nothing (ret == NULL), > 0 on something 2) recognizable errno on nothing, < 0 on other errors, >= 0 on something but never use both at the same time. --- src/shared/blockdev-util.c | 8 ++++---- src/storagetm/storagetm.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/shared/blockdev-util.c b/src/shared/blockdev-util.c index 383df8bd8fb..968ff6adc3d 100644 --- a/src/shared/blockdev-util.c +++ b/src/shared/blockdev-util.c @@ -138,7 +138,7 @@ int block_device_get_originating(sd_device *dev, sd_device **ret) { return -ENOENT; *ret = TAKE_PTR(first_found); - return 1; /* found */ + return 0; } int block_device_new_from_fd(int fd, BlockDeviceLookupFlag flags, sd_device **ret) { @@ -166,10 +166,10 @@ int block_device_new_from_fd(int fd, BlockDeviceLookupFlag flags, sd_device **re return r; r = block_device_get_originating(dev_whole_disk, &dev_origin); - if (r < 0 && r != -ENOENT) - return r; - if (r > 0) + if (r >= 0) device_unref_and_replace(dev, dev_origin); + else if (r != -ENOENT) + return r; } if (FLAGS_SET(flags, BLOCK_DEVICE_LOOKUP_WHOLE_DISK)) { diff --git a/src/storagetm/storagetm.c b/src/storagetm/storagetm.c index 1f1ebe2e8fe..4bc69178874 100644 --- a/src/storagetm/storagetm.c +++ b/src/storagetm/storagetm.c @@ -842,7 +842,7 @@ static void device_track_back(sd_device *d, sd_device **ret) { _cleanup_(sd_device_unrefp) sd_device *d_originating = NULL; r = block_device_get_originating(d, &d_originating); - if (r < 0) + if (r < 0 && r != -ENOENT) log_device_debug_errno(d, r, "Failed to get originating device for '%s', ignoring: %m", strna(devname)); sd_device *d_whole = NULL; -- 2.47.3