]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
os-util: do not use 'r' for storing loop status
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 8 Apr 2023 16:31:29 +0000 (01:31 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 11 Apr 2023 09:48:58 +0000 (18:48 +0900)
The variable 'r' is usually used for storing return value of functional
call. Let's introduce another boolean to store the current loop status.

No functional change, just refactoring.

src/basic/os-util.c

index 35c7555461db37a59350f55454c53238bf01f248..0ca307064e594e5440fc4d72d7b7225e9801e476 100644 (file)
@@ -149,6 +149,7 @@ int open_extension_release(
 
         _cleanup_close_ int fd = -EBADF;
         _cleanup_free_ char *q = NULL;
+        bool found = false;
         int r;
 
         assert(!extension || (image_class >= 0 && image_class < _IMAGE_CLASS_MAX));
@@ -183,7 +184,6 @@ int open_extension_release(
         if (r < 0)
                 return log_debug_errno(r, "Cannot open %s%s, ignoring: %m", root, image_class_release_info[image_class].release_file_directory);
 
-        r = -ENOENT;
         FOREACH_DIRENT(de, extension_release_dir, return -errno) {
                 int k;
 
@@ -228,12 +228,10 @@ int open_extension_release(
                 /* We already found what we were looking for, but there's another candidate? We treat this as
                  * an error, as we want to enforce that there are no ambiguities in case we are in the
                  * fallback path. */
-                if (r == 0) {
-                        r = -ENOTUNIQ;
-                        break;
-                }
+                if (found)
+                        return -ENOTUNIQ;
 
-                r = 0; /* Found it! */
+                found = true;
 
                 if (ret_fd)
                         fd = TAKE_FD(extension_release_fd);
@@ -244,8 +242,8 @@ int open_extension_release(
                                 return -ENOMEM;
                 }
         }
-        if (r < 0)
-                return r;
+        if (!found)
+                return -ENOENT;
 
         if (ret_fd)
                 *ret_fd = TAKE_FD(fd);