diff --git a/fs/xfs/xfs_vnodeops.c b/fs/xfs/xfs_vnodeops.c
index 72a04a11cec4deb5b0a9e2da1a0e9efff179693b..d94fb9d9338b6601e3bf0ca55e266613ee46e36c 100644
--- a/fs/xfs/xfs_vnodeops.c
+++ b/fs/xfs/xfs_vnodeops.c
@@ -4337,8 +4337,10 @@ xfs_free_file_space(
 		nimap = 1;
 		error = xfs_bmapi(NULL, ip, startoffset_fsb, 1, 0, NULL, 0,
 			&imap, &nimap, NULL);
-		if (error)
+		if (error) {
+			xfs_iunlock(ip, XFS_IOLOCK_EXCL);
 			return error;
+		}
 		ASSERT(nimap == 0 || nimap == 1);
 		if (nimap && imap.br_startblock != HOLESTARTBLOCK) {
 			xfs_daddr_t	block;
@@ -4352,8 +4354,10 @@ xfs_free_file_space(
 		nimap = 1;
 		error = xfs_bmapi(NULL, ip, endoffset_fsb - 1, 1, 0, NULL, 0,
 			&imap, &nimap, NULL);
-		if (error)
+		if (error) {
+			xfs_iunlock(ip, XFS_IOLOCK_EXCL);
 			return error;
+		}
 		ASSERT(nimap == 0 || nimap == 1);
 		if (nimap && imap.br_startblock != HOLESTARTBLOCK) {
 			ASSERT(imap.br_startblock != DELAYSTARTBLOCK);