From ff27ef4b598ca6b26381c6abc124641a228f0d85 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 1 Sep 2022 19:08:10 +0200 Subject: [PATCH] loop: convert impossibe EBADF cases into asserts --- src/shared/loop-util.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/shared/loop-util.c b/src/shared/loop-util.c index def2fa89fb..724e05b7d2 100644 --- a/src/shared/loop-util.c +++ b/src/shared/loop-util.c @@ -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)); }