]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/loopdev: consistently return error values from loopcxt_find_unused()
authorThomas Weißschuh <thomas@t-8ch.de>
Sun, 25 Jun 2023 07:59:26 +0000 (09:59 +0200)
committerThomas Weißschuh <thomas@t-8ch.de>
Sun, 25 Jun 2023 08:06:21 +0000 (10:06 +0200)
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
lib/loopdev.c

index fc44ca550a4a702407e6302f3cb6c7974613e6dd..dd9ead3ee3ec093e85d5af6667c14042e67b3942 100644 (file)
@@ -1602,6 +1602,8 @@ done:
  * kernels we have to check all loop devices to found unused one.
  *
  * See kernel commit 770fe30a46a12b6fb6b63fbe1737654d28e8484.
+ *
+ * Returns: 0 = success, < 0 error
  */
 int loopcxt_find_unused(struct loopdev_cxt *lc)
 {
@@ -1617,6 +1619,8 @@ int loopcxt_find_unused(struct loopdev_cxt *lc)
                ctl = open(_PATH_DEV_LOOPCTL, O_RDWR|O_CLOEXEC);
                if (ctl >= 0)
                        rc = ioctl(ctl, LOOP_CTL_GET_FREE);
+               else
+                       rc = -errno;
                if (rc >= 0) {
                        char name[16];
                        snprintf(name, sizeof(name), "loop%d", rc);
@@ -1638,6 +1642,8 @@ int loopcxt_find_unused(struct loopdev_cxt *lc)
                rc = loopcxt_next(lc);
                loopcxt_deinit_iterator(lc);
                DBG(CXT, ul_debugobj(lc, "find_unused by scan [rc=%d]", rc));
+               if (rc)
+                       return -ENOENT;
        }
        return rc;
 }