[PATCH 2/3] rpdfs: Initialize block seqlock before using it and fix memleak

Valerie Aurora <[email protected]> Thu, 19 Mar 2026 10:37:26 +0100
Newsgroups dev.linux.lists.rpdfs-devel
Message-ID <[email protected]>
alloc_data_page() was using bk->seqlock before it was
initialized. Move the lock initializations to before the
alloc_data_page() call and free the block struct if it fails.

Signed-off-by: Valerie Aurora <[email protected]>
---
 fs/rpdfs/block.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/fs/rpdfs/block.c b/fs/rpdfs/block.c
index b614d13f4a2b..825098c0de75 100644
--- a/fs/rpdfs/block.c
+++ b/fs/rpdfs/block.c
@@ -322,19 +322,20 @@ static struct rpdfs_block *alloc_block(bool with_page, gfp_t gfp)
 		goto out;
 	}
 
+	INIT_LIST_HEAD(&bk->lru_head);
+	atomic64_set(&bk->refcount, 0);
+	seqlock_init(&bk->seqlock);
+	init_waitqueue_head(&bk->waitq);
+	INIT_LIST_HEAD(&bk->dirty_head);
+
 	if (with_page) {
 		ret = alloc_data_page(bk, gfp);
 		if (ret < 0) {
+			kfree(bk);
 			bk = ERR_PTR(ret);
 			goto out;
 		}
 	}
-
-	INIT_LIST_HEAD(&bk->lru_head);
-	atomic64_set(&bk->refcount, 0);
-	seqlock_init(&bk->seqlock);
-	init_waitqueue_head(&bk->waitq);
-	INIT_LIST_HEAD(&bk->dirty_head);
 out:
 	return bk;
 }
-- 
2.49.0