From: Kent Overstreet Date: Fri, 19 Mar 2021 20:32:46 +0000 (-0400) Subject: bcachefs: Fix btree iterator leak in extent_handle_overwrites() X-Git-Tag: Ubuntu-6.8.0-17.17~2238^2~1736 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=dbb93db9721e8d94e3d1a3c2217fc6265aace811;p=mirror_ubuntu-kernels.git bcachefs: Fix btree iterator leak in extent_handle_overwrites() Signed-off-by: Kent Overstreet Signed-off-by: Kent Overstreet --- diff --git a/fs/bcachefs/btree_update_leaf.c b/fs/bcachefs/btree_update_leaf.c index bf2a2b0695b6..f8b493706c94 100644 --- a/fs/bcachefs/btree_update_leaf.c +++ b/fs/bcachefs/btree_update_leaf.c @@ -754,7 +754,7 @@ static int extent_handle_overwrites(struct btree_trans *trans, enum btree_id btree_id, struct bpos start, struct bpos end) { - struct btree_iter *iter = NULL, *update_iter; + struct btree_iter *iter, *update_iter; struct bkey_i *update; struct bkey_s_c k; int ret = 0; @@ -767,8 +767,6 @@ static int extent_handle_overwrites(struct btree_trans *trans, break; if (bkey_cmp(bkey_start_pos(k.k), start) < 0) { - update_iter = bch2_trans_copy_iter(trans, iter); - update = bch2_trans_kmalloc(trans, bkey_bytes(k.k)); if ((ret = PTR_ERR_OR_ZERO(update))) goto err; @@ -776,6 +774,7 @@ static int extent_handle_overwrites(struct btree_trans *trans, bkey_reassemble(update, k); bch2_cut_back(start, update); + update_iter = bch2_trans_copy_iter(trans, iter); update_iter->flags &= ~BTREE_ITER_IS_EXTENTS; bch2_btree_iter_set_pos(update_iter, update->k.p); ret = bch2_trans_update2(trans, update_iter, update); @@ -785,8 +784,6 @@ static int extent_handle_overwrites(struct btree_trans *trans, } if (bkey_cmp(k.k->p, end) > 0) { - update_iter = bch2_trans_copy_iter(trans, iter); - update = bch2_trans_kmalloc(trans, bkey_bytes(k.k)); if ((ret = PTR_ERR_OR_ZERO(update))) goto err; @@ -794,6 +791,7 @@ static int extent_handle_overwrites(struct btree_trans *trans, bkey_reassemble(update, k); bch2_cut_front(end, update); + update_iter = bch2_trans_copy_iter(trans, iter); update_iter->flags &= ~BTREE_ITER_IS_EXTENTS; bch2_btree_iter_set_pos(update_iter, update->k.p); ret = bch2_trans_update2(trans, update_iter, update); @@ -801,8 +799,6 @@ static int extent_handle_overwrites(struct btree_trans *trans, if (ret) goto err; } else { - update_iter = bch2_trans_copy_iter(trans, iter); - update = bch2_trans_kmalloc(trans, sizeof(struct bkey)); if ((ret = PTR_ERR_OR_ZERO(update))) goto err; @@ -812,6 +808,7 @@ static int extent_handle_overwrites(struct btree_trans *trans, update->k.type = KEY_TYPE_deleted; update->k.size = 0; + update_iter = bch2_trans_copy_iter(trans, iter); update_iter->flags &= ~BTREE_ITER_IS_EXTENTS; bch2_btree_iter_set_pos(update_iter, update->k.p); ret = bch2_trans_update2(trans, update_iter, update); @@ -823,8 +820,7 @@ static int extent_handle_overwrites(struct btree_trans *trans, k = bch2_btree_iter_next_with_updates(iter); } err: - if (!IS_ERR_OR_NULL(iter)) - bch2_trans_iter_put(trans, iter); + bch2_trans_iter_put(trans, iter); return ret; }