]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
blockdev-util: don't use mixed style of retval in block_device_get_originating
authorMike Yuan <me@yhndnzj.com>
Sat, 3 May 2025 19:01:54 +0000 (21:01 +0200)
committerMike Yuan <me@yhndnzj.com>
Mon, 5 May 2025 16:39:05 +0000 (18:39 +0200)
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
src/storagetm/storagetm.c

index 383df8bd8fb1b076324b1979c10e83d521876e4f..968ff6adc3df59d9140597b48d067310ed221d8a 100644 (file)
@@ -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)) {
index 1f1ebe2e8feeaba86426cb1271dafc621b8fcfcf..4bc69178874a1144305b9e3803f2f0e1e3a43e20 100644 (file)
@@ -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;