Commit 80bf2f34 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Fix freeing in bch2_dev_buckets_resize()

We were double-freeing old_buckets and not freeing old_buckets_gens:
also, the code was supposed to free buckets, not old_buckets;
old_buckets is only needed because we have to use rcu_assign_pointer()
instead of swap(), and won't be set if we hit the error path.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
parent 35228ecb
...@@ -451,7 +451,7 @@ struct bch_dev { ...@@ -451,7 +451,7 @@ struct bch_dev {
* Or rcu_read_lock(), but only for ptr_stale(): * Or rcu_read_lock(), but only for ptr_stale():
*/ */
struct bucket_array __rcu *buckets[2]; struct bucket_array __rcu *buckets[2];
struct bucket_gens *bucket_gens; struct bucket_gens __rcu *bucket_gens;
unsigned long *buckets_nouse; unsigned long *buckets_nouse;
struct rw_semaphore bucket_lock; struct rw_semaphore bucket_lock;
......
...@@ -2106,7 +2106,7 @@ static void buckets_free_rcu(struct rcu_head *rcu) ...@@ -2106,7 +2106,7 @@ static void buckets_free_rcu(struct rcu_head *rcu)
container_of(rcu, struct bucket_array, rcu); container_of(rcu, struct bucket_array, rcu);
kvpfree(buckets, kvpfree(buckets,
sizeof(struct bucket_array) + sizeof(*buckets) +
buckets->nbuckets * sizeof(struct bucket)); buckets->nbuckets * sizeof(struct bucket));
} }
...@@ -2115,7 +2115,7 @@ static void bucket_gens_free_rcu(struct rcu_head *rcu) ...@@ -2115,7 +2115,7 @@ static void bucket_gens_free_rcu(struct rcu_head *rcu)
struct bucket_gens *buckets = struct bucket_gens *buckets =
container_of(rcu, struct bucket_gens, rcu); container_of(rcu, struct bucket_gens, rcu);
kvpfree(buckets, sizeof(struct bucket_array) + buckets->nbuckets); kvpfree(buckets, sizeof(*buckets) + buckets->nbuckets);
} }
int bch2_dev_buckets_resize(struct bch_fs *c, struct bch_dev *ca, u64 nbuckets) int bch2_dev_buckets_resize(struct bch_fs *c, struct bch_dev *ca, u64 nbuckets)
...@@ -2225,9 +2225,9 @@ int bch2_dev_buckets_resize(struct bch_fs *c, struct bch_dev *ca, u64 nbuckets) ...@@ -2225,9 +2225,9 @@ int bch2_dev_buckets_resize(struct bch_fs *c, struct bch_dev *ca, u64 nbuckets)
kvpfree(buckets_nouse, kvpfree(buckets_nouse,
BITS_TO_LONGS(nbuckets) * sizeof(unsigned long)); BITS_TO_LONGS(nbuckets) * sizeof(unsigned long));
if (bucket_gens) if (bucket_gens)
call_rcu(&old_buckets->rcu, bucket_gens_free_rcu); call_rcu(&bucket_gens->rcu, bucket_gens_free_rcu);
if (buckets) if (buckets)
call_rcu(&old_buckets->rcu, buckets_free_rcu); call_rcu(&buckets->rcu, buckets_free_rcu);
return ret; return ret;
} }
...@@ -2242,6 +2242,8 @@ void bch2_dev_buckets_free(struct bch_dev *ca) ...@@ -2242,6 +2242,8 @@ void bch2_dev_buckets_free(struct bch_dev *ca)
free_fifo(&ca->free[i]); free_fifo(&ca->free[i]);
kvpfree(ca->buckets_nouse, kvpfree(ca->buckets_nouse,
BITS_TO_LONGS(ca->mi.nbuckets) * sizeof(unsigned long)); BITS_TO_LONGS(ca->mi.nbuckets) * sizeof(unsigned long));
kvpfree(rcu_dereference_protected(ca->bucket_gens, 1),
sizeof(struct bucket_gens) + ca->mi.nbuckets);
kvpfree(rcu_dereference_protected(ca->buckets[0], 1), kvpfree(rcu_dereference_protected(ca->buckets[0], 1),
sizeof(struct bucket_array) + sizeof(struct bucket_array) +
ca->mi.nbuckets * sizeof(struct bucket)); ca->mi.nbuckets * sizeof(struct bucket));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment