Skip to contentSkip to conversation

btrfs: drop the lock on error in btrfs_dev_replace_cancel()

PATCH In review Dan Carpenter 3 participants 3 messages Feb 11, 2019 – Feb 20, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: drop the lock on error in btrfs_dev_replace_cancel()

We should drop the lock on this error path. This is from static analysis and I don't know if it's possible to hit this error path in real life.

---
 fs/btrfs/dev-replace.c | 1 +
 1 file changed, 1 insertion(+)
fs/btrfs/dev-replace.c +1 -0
index 13863354ff9d..ee193c5222b2 100644
@@ -862,6 +862,7 @@ int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info)
 			btrfs_destroy_dev_replace_tgtdev(tgt_device);
 		break;
 	default:
+		up_write(&dev_replace->rwsem);
 		result = -EINVAL;
 	}
 
Signature · 1 line
2.17.1
#1 lore raw
Quoted 3 lines · Dan Carpenter

We should drop the lock on this error path. This is from static analysis and I don't know if it's possible to hit this error path in real life.

Yes the lock needs to be released, it's there to protect access to the dev_replace members and is not supposed to be left locked. The value of state that's being switched would need to be artifically changed to an invalid value so the default: branch is taken.

It's been introduced by d189dd70e25561817325 in 5.0-rc1 so it counts as a regression but I don't think it's urgent enough to be sent to a late rc. It'll go through the stable tree channel. Thanks.

Reviewed-by
#2 lore raw
Quoted 5 lines · David Sterba
Quoted 3 lines · Dan Carpenter

We should drop the lock on this error path. This is from static analysis and I don't know if it's possible to hit this error path in real life.

Quoted 9 lines

Yes the lock needs to be released, it's there to protect access to the dev_replace members and is not supposed to be left locked. The value of state that's being switched would need to be artifically changed to an invalid value so the default: branch is taken.

It's been introduced by d189dd70e25561817325 in 5.0-rc1 so it counts as a regression but I don't think it's urgent enough to be sent to a late rc. It'll go through the stable tree channel. Thanks.

oops I missed this email. Thanks Dan and David.