loop: restore the correct return vaule of set_loop()

It is only used by mount's error path, though...

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2022-12-13 15:49:09 +01:00
parent 45734a2351
commit a55bd1c484

View File

@ -147,10 +147,8 @@ static int set_loopdev_params(int lfd,
loopinfo.lo_offset = offset; loopinfo.lo_offset = offset;
loopinfo.lo_sizelimit = sizelimit; loopinfo.lo_sizelimit = sizelimit;
/* /*
* Used by mount to set LO_FLAGS_AUTOCLEAR. * LO_FLAGS_READ_ONLY is not set because RO is controlled
* LO_FLAGS_READ_ONLY is not set because RO is controlled by open type of the file. * by open type of the lfd.
* Note that closing LO_FLAGS_AUTOCLEARed lfd before mount
* is wrong (would free the loop device!)
*/ */
loopinfo.lo_flags = (flags & ~BB_LO_FLAGS_READ_ONLY); loopinfo.lo_flags = (flags & ~BB_LO_FLAGS_READ_ONLY);
@ -266,6 +264,12 @@ int FAST_FUNC set_loop(char **device, const char *file, unsigned long long offse
/* SUCCESS! */ /* SUCCESS! */
if (!*device) if (!*device)
*device = xstrdup(dev); *device = xstrdup(dev);
/* Note: mount asks for LO_FLAGS_AUTOCLEAR loopdev.
* Closing LO_FLAGS_AUTOCLEARed lfd before mount
* is wrong (would free the loop device!),
* this is why we return without closing it.
*/
rc = lfd; /* return this */
break; break;
} }
close(lfd); close(lfd);