]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
loop: convert impossibe EBADF cases into asserts
authorLennart Poettering <lennart@poettering.net>
Thu, 1 Sep 2022 17:08:10 +0000 (19:08 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 1 Sep 2022 18:40:01 +0000 (20:40 +0200)
src/shared/loop-util.c

index def2fa89fbb57d05bda991b05294724a52e67f9f..724e05b7d2f075e917aeb76e8c61e8fd8d6a7737 100644 (file)
@@ -878,7 +878,9 @@ static int resize_partition(int partition_fd, uint64_t offset, uint64_t size) {
 
 int loop_device_refresh_size(LoopDevice *d, uint64_t offset, uint64_t size) {
         struct loop_info64 info;
+
         assert(d);
+        assert(d->fd >= 0);
 
         /* Changes the offset/start of the loop device relative to the beginning of the underlying file or
          * block device. If this loop device actually refers to a partition and not a loopback device, we'll
@@ -886,9 +888,6 @@ int loop_device_refresh_size(LoopDevice *d, uint64_t offset, uint64_t size) {
          *
          * If either offset or size is UINT64_MAX we won't change that parameter. */
 
-        if (d->fd < 0)
-                return -EBADF;
-
         if (d->nr < 0) /* not a loopback device */
                 return resize_partition(d->fd, offset, size);
 
@@ -924,12 +923,10 @@ int loop_device_flock(LoopDevice *d, int operation) {
 
 int loop_device_sync(LoopDevice *d) {
         assert(d);
+        assert(d->fd >= 0);
 
         /* We also do this implicitly in loop_device_unref(). Doing this explicitly here has the benefit that
          * we can check the return value though. */
 
-        if (d->fd < 0)
-                return -EBADF;
-
         return RET_NERRNO(fsync(d->fd));
 }