Skip to content

Commit 856473c

Browse files
Andreas Gruenbacherdjwong
authored andcommitted
iomap: Make sure iomap_end is called after iomap_begin
Make sure iomap_end is always called when iomap_begin succeeds. Without this fix, iomap_end won't be called when a filesystem's iomap_begin operation returns an invalid mapping, bypassing any unlocking done in iomap_end. With this fix, the unlocking will still happen. This bug was found by Bob Peterson during code review. It's unlikely that such iomap_begin bugs will survive to affect users, so backporting this fix seems unnecessary. Fixes: ae259a9 ("fs: introduce iomap infrastructure") Signed-off-by: Andreas Gruenbacher <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent dcb7fd8 commit 856473c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

fs/iomap/apply.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,14 @@ iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags,
4646
ret = ops->iomap_begin(inode, pos, length, flags, &iomap, &srcmap);
4747
if (ret)
4848
return ret;
49-
if (WARN_ON(iomap.offset > pos))
50-
return -EIO;
51-
if (WARN_ON(iomap.length == 0))
52-
return -EIO;
49+
if (WARN_ON(iomap.offset > pos)) {
50+
written = -EIO;
51+
goto out;
52+
}
53+
if (WARN_ON(iomap.length == 0)) {
54+
written = -EIO;
55+
goto out;
56+
}
5357

5458
trace_iomap_apply_dstmap(inode, &iomap);
5559
if (srcmap.type != IOMAP_HOLE)
@@ -80,6 +84,7 @@ iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags,
8084
written = actor(inode, pos, length, data, &iomap,
8185
srcmap.type != IOMAP_HOLE ? &srcmap : &iomap);
8286

87+
out:
8388
/*
8489
* Now the data has been copied, commit the range we've copied. This
8590
* should not fail unless the filesystem has had a fatal error.

0 commit comments

Comments
 (0)