hfs_brec_insert() may fail while inserting a new extent record, but __hfs_ext_write_extent() currently ignores its return value and clears HFS_FLG_EXT_DIRTY and HFS_FLG_EXT_NEW as if the insertion had succeeded. Propagate the error returned by hfs_brec_insert() and only clear the extent flags after a successful insertion. Fault injection of -EIO into the extent B-tree insertion path confirmed that __hfs_ext_write_extent() returned success despite the insertion failure. With the error propagated, the failure is returned to the caller instead. Signed-off-by: Davy Felipe --- fs/hfs/extent.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/hfs/extent.c b/fs/hfs/extent.c index f066a99a863b..77ba0f63fcb9 100644 --- a/fs/hfs/extent.c +++ b/fs/hfs/extent.c @@ -121,7 +121,10 @@ static int __hfs_ext_write_extent(struct inode *inode, struct hfs_find_data *fd) res = hfs_bmap_reserve(fd->tree, fd->tree->depth + 1); if (res) return res; - hfs_brec_insert(fd, HFS_I(inode)->cached_extents, sizeof(hfs_extent_rec)); + res = hfs_brec_insert(fd, HFS_I(inode)->cached_extents, + sizeof(hfs_extent_rec)); + if (res) + return res; HFS_I(inode)->flags &= ~(HFS_FLG_EXT_DIRTY|HFS_FLG_EXT_NEW); } else { if (res) -- 2.55.0