Skip to contentSkip to conversation

block: fix incorrect error injection static key decrement

PATCH Applied Christoph Hellwig 2 participants 2 messages Jun 22 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: fix incorrect error injection static key decrement

Only decrement the static key when we had items and thus it was incremented before.

Fixes e8dcf2d142bd ("block: add configurable error injection")
---
 block/error-injection.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
block/error-injection.c +2 -2
index d24c90e9a25f..cfb83138960c 100644
@@ -120,13 +120,13 @@ static void error_inject_removeall(struct gendisk *disk)
 	struct blk_error_inject *inj;
 
 	mutex_lock(&disk->error_injection_lock);
-	clear_bit(GD_ERROR_INJECT, &disk->state);
+	if (test_and_clear_bit(GD_ERROR_INJECT, &disk->state))
+		static_branch_dec(&blk_error_injection_enabled);
 	while ((inj = list_first_entry_or_null(&disk->error_injection_list,
 			struct blk_error_inject, entry))) {
 		list_del_rcu(&inj->entry);
 		kfree_rcu_mightsleep(inj);
 	}
-	static_branch_dec(&blk_error_injection_enabled);
 	mutex_unlock(&disk->error_injection_lock);
 }
 
Signature · 1 line
2.53.0
maintainer Applied
#1 lore raw
Quoted 2 lines · Christoph Hellwig

Only decrement the static key when we had items and thus it was incremented before.

Applied, thanks!

[1/1] block: fix incorrect error injection static key decrement

      commit: 214cdae69dba9bb1fc0b517b7fb97bab385a2e3a

Best regards,

Signature · 1 line
Jens Axboe