bcachefs: Fix btree_path leaks in bch2_trans_update()
authorKent Overstreet <kent.overstreet@gmail.com>
Wed, 1 Dec 2021 08:47:54 +0000 (03:47 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:18 +0000 (17:09 -0400)
bch2_trans_update() had some dodgy gets() and puts() - this fixes a few
leaks.

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

index 205eaee11da0e1e8c61f4c776853b650fa82e16b..65facdd1536f969776954f12f0c87e9c88b71d55 100644 (file)
@@ -1336,8 +1336,6 @@ int bch2_trans_update(struct btree_trans *trans, struct btree_iter *iter,
                .ip_allocated   = _RET_IP_,
        };
 
-       __btree_path_get(n.path, true);
-
 #ifdef CONFIG_BCACHEFS_DEBUG
        trans_for_each_update(trans, i)
                BUG_ON(i != trans->updates &&
@@ -1374,16 +1372,17 @@ int bch2_trans_update(struct btree_trans *trans, struct btree_iter *iter,
                if (n.cached && !i->cached) {
                        i->k = n.k;
                        i->flags = n.flags;
-
-                       __btree_path_get(n.path, false);
-               } else {
-                       bch2_path_put(trans, i->path, true);
-                       *i = n;
+                       return 0;
                }
+
+               bch2_path_put(trans, i->path, true);
+               *i = n;
        } else
                array_insert_item(trans->updates, trans->nr_updates,
                                  i - trans->updates, n);
 
+       __btree_path_get(n.path, true);
+
        return 0;
 }