Skip to contentSkip to conversation

btrfs: don't double unlock on error in btrfs_punch_hole

PATCH In review Josef Bacik 4 participants 5 messages May 3, 2019 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: don't double unlock on error in btrfs_punch_hole

If we have an error writing out a delalloc range in btrfs_punch_hole_lock_range we'll unlock the inode and then goto out_only_mutex, where we will again unlock the inode. This is bad, don't do this.

---
 fs/btrfs/file.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
fs/btrfs/file.c +1 -3
index 7f7833149cb7..d23ea0b388e0 100644
@@ -2554,10 +2554,8 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
 
 	ret = btrfs_punch_hole_lock_range(inode, lockstart, lockend,
 					  &cached_state);
-	if (ret) {
-		inode_unlock(inode);
+	if (ret)
 		goto out_only_mutex;
-	}
 
 	path = btrfs_alloc_path();
 	if (!path) {
Signature · 1 line
2.13.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Josef Bacik

If we have an error writing out a delalloc range in btrfs_punch_hole_lock_range we'll unlock the inode and then goto out_only_mutex, where we will again unlock the inode. This is bad, don't do this.

Looks good, I introduced the double unlock accidentally.

Quoted 23 lines
---
 fs/btrfs/file.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
fs/btrfs/file.c +1 -4
index 7f7833149cb7..d23ea0b388e0 100644
@@ -2554,10 +2554,8 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
 
        ret = btrfs_punch_hole_lock_range(inode, lockstart, lockend,
                                          &cached_state);
-       if (ret) {
-               inode_unlock(inode);
+       if (ret)
                goto out_only_mutex;
-       }
 
        path = btrfs_alloc_path();
        if (!path) {
--

2.13.5

Signature · 3 lines
Filipe David Manana,

“Whether you think you can, or you think you can't — you're right.”
#2 lore raw
Quoted 7 lines · Filipe Manana
Quoted 5 lines · Josef Bacik

If we have an error writing out a delalloc range in btrfs_punch_hole_lock_range we'll unlock the inode and then goto out_only_mutex, where we will again unlock the inode. This is bad, don't do this.

Quoted 5 lines
Quoted 1 line

Looks good, I introduced the double unlock accidentally.

Does the patch need a Fixes: tag so the -stable
people know how far to backport it?

#3 lore raw
Quoted 8 lines · Rik van Riel
Quoted 7 lines · Filipe Manana
Quoted 5 lines · Josef Bacik

If we have an error writing out a delalloc range in btrfs_punch_hole_lock_range we'll unlock the inode and then goto out_only_mutex, where we will again unlock the inode. This is bad, don't do this.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Looks good, I introduced the double unlock accidentally.

Does the patch need a Fixes: tag so the -stable
people know how far to backport it?

I add the tags.