]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
block: fix incorrect error injection static key decrement
authorChristoph Hellwig <hch@lst.de>
Mon, 22 Jun 2026 16:07:52 +0000 (18:07 +0200)
committerJens Axboe <axboe@kernel.dk>
Mon, 22 Jun 2026 21:55:11 +0000 (15:55 -0600)
Only decrement the static key when we had items and thus it was
incremented before.

Fixes: e8dcf2d142bd ("block: add configurable error injection")
Reported-by: Damien Le Moal <dlemoal@kernel.org>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://patch.msgid.link/20260622160752.1552516-1-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/error-injection.c

index d24c90e9a25f91924689fda160b35802456f8e4c..cfb83138960c866825837a47c1f4e3b7d4289ccd 100644 (file)
@@ -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);
 }