From: Lennart Poettering Date: Thu, 1 Sep 2022 17:08:10 +0000 (+0200) Subject: loop: convert impossibe EBADF cases into asserts X-Git-Tag: v252-rc1~275^2~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ff27ef4b598ca6b26381c6abc124641a228f0d85;p=thirdparty%2Fsystemd.git loop: convert impossibe EBADF cases into asserts --- diff --git a/src/shared/loop-util.c b/src/shared/loop-util.c index def2fa89fbb..724e05b7d2f 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)); }