bcachefs: Fix refcount leak in bch2_do_invalidates()
authorKent Overstreet <kent.overstreet@gmail.com>
Mon, 20 Jun 2022 23:48:16 +0000 (19:48 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:34 +0000 (17:09 -0400)
If we fail to queue the work item because it's already in process, we
need to drop the ref we just took.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
fs/bcachefs/alloc_background.c

index 3084081966b64b853388a1de3146bed428c798c4..933334fed960be36148cf3323ef0eb62e4ead9db 100644 (file)
@@ -1192,8 +1192,9 @@ static void bch2_do_invalidates_work(struct work_struct *work)
 
 void bch2_do_invalidates(struct bch_fs *c)
 {
-       if (percpu_ref_tryget_live(&c->writes))
-               queue_work(system_long_wq, &c->invalidate_work);
+       if (percpu_ref_tryget_live(&c->writes) &&
+           !queue_work(system_long_wq, &c->invalidate_work))
+               percpu_ref_put(&c->writes);
 }
 
 static int bucket_freespace_init(struct btree_trans *trans, struct btree_iter *iter)