From 37b09cf2aacc884a88e86c833334eb0f92983f7e Mon Sep 17 00:00:00 2001
From: Suraj Sonawane <surajsonawane0215@gmail.com>
Date: Sun, 10 Nov 2024 15:32:19 +0530
Subject: [PATCH] v5KMSAN: fix uninit-value in bch2_copygc

fix

Signed-off-by: Suraj Sonawane <surajsonawane0215@gmail.com>
---
 fs/bcachefs/movinggc.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/fs/bcachefs/movinggc.c b/fs/bcachefs/movinggc.c
index d658be90f..2f43d9ec7 100644
--- a/fs/bcachefs/movinggc.c
+++ b/fs/bcachefs/movinggc.c
@@ -158,6 +158,20 @@ static int bch2_copygc_get_buckets(struct moving_context *ctxt,
 
 	move_buckets_wait(ctxt, buckets_in_flight, false);
 
+	if (!buckets_in_flight || !buckets_in_flight->nr) {
+		// Initialize the structure
+		buckets_in_flight->nr = 0;
+		buckets_in_flight->sectors = 0;
+		buckets_in_flight->first = NULL;
+		buckets_in_flight->last = NULL;
+
+		// Explicitly initialize the hash table instead of memset
+		ret = rhashtable_init(&buckets_in_flight->table, &bch_move_bucket_params);
+		if (ret) {
+			return ret;
+		}
+	}
+
 	ret = bch2_btree_write_buffer_tryflush(trans);
 	if (bch2_err_matches(ret, EROFS))
 		return ret;
-- 
2.34.1