Skip to contentSkip to conversation

Fix some issues about ext4-test

PATCH Superseded Ye Bin 1 participant 9 messages Mar 12 ext4 file system

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Ye Bin

author
#0 lore raw

v2 cover Fix some issues about ext4-test

From: Ye Bin <[email protected]>

Diff v2 vs v1:
1. Fix compile warning when disable EXT4_KUNIT_TESTS for patch[1][3];
2. Remove reviewed-by tag for patch[1];

Patch [1]-[2]:
Decoupled mballoc-test and extents-test from ext4. Patch [1] does not have any changes compared to the previously released version, so the reviewed-by is added.
Patch [3-7]:
Bugfix for extents-test.c.
Patch [8]:
Bugfix for mballoc-test.c.

Ye Bin (8):
ext4: fix mballoc-test.c is not compiled when EXT4_KUNIT_TESTS=M
ext4: introduce EXPORT_SYMBOL_FOR_EXT4_TEST() helper
ext4: fix extents-test.c is not compiled when EXT4_KUNIT_TESTS=M
ext4: fix miss unlock 'sb->s_umount' in extents_kunit_init()
ext4: fix miss free super_block in extents_kunit_exit()
ext4: fix the error handling process in extents_kunit_init).
ext4: fix possible null-ptr-deref in extents_kunit_exit()
ext4: fix possible null-ptr-deref in mbt_kunit_exit()

 fs/ext4/Makefile       |   5 +-
 fs/ext4/ext4.h         |   5 ++
 fs/ext4/ext4_extents.h |  12 +++++
 fs/ext4/extents-test.c |  59 ++++++++++++++++--------
 fs/ext4/extents.c      |  38 ++++++++++++---
 fs/ext4/mballoc-test.c |  87 ++++++++++++++++++-----------------
 fs/ext4/mballoc.c      | 102 +++++++++++++++++++++++++++++++++++++++--
 fs/ext4/mballoc.h      |  30 ++++++++++++
 8 files changed, 268 insertions(+), 70 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v2 1/8 ext4: fix mballoc-test.c is not compiled when EXT4_KUNIT_TESTS=M

From: Ye Bin <[email protected]>

Now, only EXT4_KUNIT_TESTS=Y testcase will be compiled in 'mballoc.c'. To solve this issue, the ext4 test code needs to be decoupled. The ext4 test module is compiled into a separate module.

Fixes 7c9fa399a369 ("ext4: add first unit test for ext4_mb_new_blocks_simple in mballoc")
---
 fs/ext4/Makefile       |   4 +-
 fs/ext4/mballoc-test.c |  81 +++++++++++++++----------------
 fs/ext4/mballoc.c      | 105 +++++++++++++++++++++++++++++++++++++++--
 fs/ext4/mballoc.h      |  30 ++++++++++++
 4 files changed, 175 insertions(+), 45 deletions(-)
fs/ext4/Makefile +2 -2
index 72206a292676..d836c3fe311b 100644
@@ -14,7 +14,7 @@ ext4-y	:= balloc.o bitmap.o block_validity.o dir.o ext4_jbd2.o extents.o \
 
 ext4-$(CONFIG_EXT4_FS_POSIX_ACL)	+= acl.o
 ext4-$(CONFIG_EXT4_FS_SECURITY)		+= xattr_security.o
-ext4-inode-test-objs			+= inode-test.o
-obj-$(CONFIG_EXT4_KUNIT_TESTS)		+= ext4-inode-test.o
+ext4-test-objs				+= inode-test.o mballoc-test.o
+obj-$(CONFIG_EXT4_KUNIT_TESTS)		+= ext4-test.o
 ext4-$(CONFIG_FS_VERITY)		+= verity.o
 ext4-$(CONFIG_FS_ENCRYPTION)		+= crypto.o
fs/ext4/mballoc-test.c +41 -40

281 lines not on this page · raw message

fs/ext4/mballoc.c +102 -3

115 lines not on this page · raw message

fs/ext4/mballoc.h +30 -0
index 15a049f05d04..39333ce72cbd 100644
@@ -270,4 +270,34 @@ ext4_mballoc_query_range(
 	ext4_mballoc_query_range_fn	formatter,
 	void				*priv);
 
+extern int ext4_mb_mark_context(handle_t *handle,
+		struct super_block *sb, bool state,
+		ext4_group_t group, ext4_grpblk_t blkoff,
+		ext4_grpblk_t len, int flags,
+		ext4_grpblk_t *ret_changed);
+#if IS_ENABLED(CONFIG_EXT4_KUNIT_TESTS)
+extern void mb_clear_bits_test(void *bm, int cur, int len);
+extern ext4_fsblk_t
+ext4_mb_new_blocks_simple_test(struct ext4_allocation_request *ar,
+			       int *errp);
+extern int mb_find_next_zero_bit_test(void *addr, int max, int start);
+extern int mb_find_next_bit_test(void *addr, int max, int start);
+extern void mb_clear_bit_test(int bit, void *addr);
+extern int mb_test_bit_test(int bit, void *addr);
+extern int
+ext4_mb_mark_diskspace_used_test(struct ext4_allocation_context *ac,
+				 handle_t *handle);
+extern int mb_mark_used_test(struct ext4_buddy *e4b,
+			     struct ext4_free_extent *ex);
+extern void ext4_mb_generate_buddy_test(struct super_block *sb,
+		void *buddy, void *bitmap, ext4_group_t group,
+		struct ext4_group_info *grp);
+extern int ext4_mb_load_buddy_test(struct super_block *sb,
+		ext4_group_t group, struct ext4_buddy *e4b);
+extern void ext4_mb_unload_buddy_test(struct ext4_buddy *e4b);
+extern void mb_free_blocks_test(struct inode *inode,
+		struct ext4_buddy *e4b, int first, int count);
+extern void ext4_free_blocks_simple_test(struct inode *inode,
+		ext4_fsblk_t block, unsigned long count);
+#endif
 #endif
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH v2 2/8 ext4: introduce EXPORT_SYMBOL_FOR_EXT4_TEST() helper

In reply to Ye Bin

From: Ye Bin <[email protected]>

Introduce EXPORT_SYMBOL_FOR_EXT4_TEST() helper for kuint test.

---
 fs/ext4/ext4.h    | 5 +++++
 fs/ext4/mballoc.c | 3 ---
 2 files changed, 5 insertions(+), 3 deletions(-)
fs/ext4/ext4.h +5 -0
index 4cb2345339ba..8bf2a2ac4787 100644
@@ -3945,6 +3945,11 @@ static inline bool ext4_inode_can_atomic_write(struct inode *inode)
 extern int ext4_block_write_begin(handle_t *handle, struct folio *folio,
 				  loff_t pos, unsigned len,
 				  get_block_t *get_block);
+
+#if IS_ENABLED(CONFIG_EXT4_KUNIT_TESTS)
+#define EXPORT_SYMBOL_FOR_EXT4_TEST(sym) \
+	EXPORT_SYMBOL_FOR_MODULES(sym, "ext4-test")
+#endif
 #endif	/* __KERNEL__ */
 
 #endif	/* _EXT4_H */
fs/ext4/mballoc.c +0 -3
index 842a604ae5db..97b3f0e4c80b 100644
@@ -7193,9 +7193,6 @@ ext4_mballoc_query_range(
 }
 
 #if IS_ENABLED(CONFIG_EXT4_KUNIT_TESTS)
-#define EXPORT_SYMBOL_FOR_EXT4_TEST(sym) \
-	EXPORT_SYMBOL_FOR_MODULES(sym, "ext4-test")
-
 void mb_clear_bits_test(void *bm, int cur, int len)
 {
 	 mb_clear_bits(bm, cur, len);
Signature · 1 line
2.34.1
author
#3 lore raw

PATCH v2 3/8 ext4: fix extents-test.c is not compiled when EXT4_KUNIT_TESTS=M

In reply to Ye Bin

From: Ye Bin <[email protected]>

Now, only EXT4_KUNIT_TESTS=Y testcase will be compiled in 'extents.c'. To solve this issue, the ext4 test code needs to be decoupled. The 'extents-test' module is compiled into 'ext4-test' module.

Fixes cb1e0c1d1fad ("ext4: kunit tests for extent splitting and conversion")
---
 fs/ext4/Makefile       |  3 ++-
 fs/ext4/ext4_extents.h | 12 ++++++++++++
 fs/ext4/extents-test.c |  8 ++++----
 fs/ext4/extents.c      | 38 ++++++++++++++++++++++++++++++++------
 4 files changed, 50 insertions(+), 11 deletions(-)
fs/ext4/Makefile +2 -1
index d836c3fe311b..3baee4e7c1cf 100644
@@ -14,7 +14,8 @@ ext4-y	:= balloc.o bitmap.o block_validity.o dir.o ext4_jbd2.o extents.o \
 
 ext4-$(CONFIG_EXT4_FS_POSIX_ACL)	+= acl.o
 ext4-$(CONFIG_EXT4_FS_SECURITY)		+= xattr_security.o
-ext4-test-objs				+= inode-test.o mballoc-test.o
+ext4-test-objs				+= inode-test.o mballoc-test.o \
+					   extents-test.o
 obj-$(CONFIG_EXT4_KUNIT_TESTS)		+= ext4-test.o
 ext4-$(CONFIG_FS_VERITY)		+= verity.o
 ext4-$(CONFIG_FS_ENCRYPTION)		+= crypto.o
fs/ext4/ext4_extents.h +12 -0
index c484125d963f..ebaf7cc42430 100644
@@ -264,5 +264,17 @@ static inline void ext4_idx_store_pblock(struct ext4_extent_idx *ix,
 				     0xffff);
 }
 
+extern int __ext4_ext_dirty(const char *where, unsigned int line,
+			    handle_t *handle, struct inode *inode,
+			    struct ext4_ext_path *path);
+extern int ext4_ext_zeroout(struct inode *inode, struct ext4_extent *ex);
+#if IS_ENABLED(CONFIG_EXT4_KUNIT_TESTS)
+extern int ext4_ext_space_root_idx_test(struct inode *inode, int check);
+extern struct ext4_ext_path *ext4_split_convert_extents_test(
+				handle_t *handle, struct inode *inode,
+				struct ext4_map_blocks *map,
+				struct ext4_ext_path *path,
+				int flags, unsigned int *allocated);
+#endif
 #endif /* _EXT4_EXTENTS */
 
fs/ext4/extents-test.c +4 -4
index 7c4690eb7dad..9e055f399167 100644
@@ -280,8 +280,8 @@ static int extents_kunit_init(struct kunit *test)
 	eh->eh_depth = 0;
 	eh->eh_entries = cpu_to_le16(1);
 	eh->eh_magic = EXT4_EXT_MAGIC;
-	eh->eh_max =
-		cpu_to_le16(ext4_ext_space_root_idx(&k_ctx.k_ei->vfs_inode, 0));
+	eh->eh_max = cpu_to_le16(ext4_ext_space_root_idx_test(
+					&k_ctx.k_ei->vfs_inode, 0));
 	eh->eh_generation = 0;
 
 	/*
@@ -384,8 +384,8 @@ static void test_split_convert(struct kunit *test)
 
 	switch (param->type) {
 	case TEST_SPLIT_CONVERT:
-		path = ext4_split_convert_extents(NULL, inode, &map, path,
-						  param->split_flags, NULL);
+		path = ext4_split_convert_extents_test(NULL, inode, &map,
+					path, param->split_flags, NULL);
 		break;
 	case TEST_CREATE_BLOCKS:
 		ext4_map_create_blocks_helper(test, inode, &map, param->split_flags);
fs/ext4/extents.c +32 -6
index ae3804f36535..0942d2ed4603 100644
@@ -184,9 +184,9 @@ static int ext4_ext_get_access(handle_t *handle, struct inode *inode,
  *  - ENOMEM
  *  - EIO
  */
-static int __ext4_ext_dirty(const char *where, unsigned int line,
-			    handle_t *handle, struct inode *inode,
-			    struct ext4_ext_path *path)
+int __ext4_ext_dirty(const char *where, unsigned int line,
+		     handle_t *handle, struct inode *inode,
+		     struct ext4_ext_path *path)
 {
 	int err;
 
@@ -3144,7 +3144,7 @@ static void ext4_zeroout_es(struct inode *inode, struct ext4_extent *ex)
 }
 
 /* FIXME!! we need to try to merge to left or right after zero-out  */
-static int ext4_ext_zeroout(struct inode *inode, struct ext4_extent *ex)
+int ext4_ext_zeroout(struct inode *inode, struct ext4_extent *ex)
 {
 	ext4_fsblk_t ee_pblock;
 	unsigned int ee_len;
@@ -6238,6 +6238,32 @@ int ext4_ext_clear_bb(struct inode *inode)
 	return 0;
 }
 
-#ifdef CONFIG_EXT4_KUNIT_TESTS
-#include "extents-test.c"
+#if IS_ENABLED(CONFIG_EXT4_KUNIT_TESTS)
+int ext4_ext_space_root_idx_test(struct inode *inode, int check)
+{
+	return ext4_ext_space_root_idx(inode, check);
+}
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_ext_space_root_idx_test);
+
+struct ext4_ext_path *ext4_split_convert_extents_test(handle_t *handle,
+			struct inode *inode, struct ext4_map_blocks *map,
+			struct ext4_ext_path *path, int flags,
+			unsigned int *allocated)
+{
+	return ext4_split_convert_extents(handle, inode, map, path,
+					  flags, allocated);
+}
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_split_convert_extents_test);
+
+EXPORT_SYMBOL_FOR_EXT4_TEST(__ext4_ext_dirty);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_ext_zeroout);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_register_shrinker);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_map_create_blocks);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_init_tree);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_lookup_extent);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_insert_extent);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_ext_insert_extent);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_find_extent);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_issue_zeroout);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_map_query_blocks);
 #endif
Signature · 1 line
2.34.1
author
#4 lore raw

PATCH v2 4/8 ext4: fix miss unlock 'sb->s_umount' in extents_kunit_init()

In reply to Ye Bin

From: Ye Bin <[email protected]>

There's warning as follows when do ext4 kunit test:
WARNING: kunit_try_catch/15923 still has locks held!
7.0.0-rc3-next-20260309-00028-g73f965a1bbb1-dirty #281 Tainted: G E N
1 lock held by kunit_try_catch/15923:
#0: ffff888139f860e0 (&type->s_umount_key#70/1){+.+.}-{4:4}, at: alloc_super.constprop.0+0x172/0xa90

Call Trace:
 <TASK>
 dump_stack_lvl+0x180/0x1b0
 debug_check_no_locks_held+0xc8/0xd0
 do_exit+0x1502/0x2b20
 kthread+0x3a9/0x540
 ret_from_fork+0xa76/0xdf0
 ret_from_fork_asm+0x1a/0x30

As sget() will return 'sb' which holds 's->s_umount' lock. However, "extents-test" miss unlock this lock.
So unlock 's->s_umount' in the end of extents_kunit_init().

Fixes cb1e0c1d1fad ("ext4: kunit tests for extent splitting and conversion")
---
 fs/ext4/extents-test.c | 2 ++
 1 file changed, 2 insertions(+)
fs/ext4/extents-test.c +2 -0
index 9e055f399167..5a5016ea1ecc 100644
@@ -307,6 +307,8 @@ static int extents_kunit_init(struct kunit *test)
 	kunit_activate_static_stub(test, ext4_ext_zeroout, ext4_ext_zeroout_stub);
 	kunit_activate_static_stub(test, ext4_issue_zeroout,
 				   ext4_issue_zeroout_stub);
+	up_write(&sb->s_umount);
+
 	return 0;
 }
 
Signature · 1 line
2.34.1
author
#5 lore raw

PATCH v2 5/8 ext4: fix miss free super_block in extents_kunit_exit()

In reply to Ye Bin

From: Ye Bin <[email protected]>

There's issue as follows:
ODEBUG: free active (active state 0) object: ffff88812f2d68a0 object type: percpu_counter hint: 0x0

 <TASK>
 debug_check_no_obj_freed+0x3d9/0x4d0
 kfree+0x2bb/0x6c0
 extents_kunit_exit+0x65/0x90 [ext4_test]
 kunit_try_run_case_cleanup+0xbc/0x100 [kunit]
 kunit_generic_run_threadfn_adapter+0x89/0x100 [kunit]
 kthread+0x408/0x540
 ret_from_fork+0xa76/0xdf0
 ret_from_fork_asm+0x1a/0x30

The above issue was caused because the super_block cleanup process was not properly performed.
Therefore, deactivate_super() is called in extents_kunit_exit() to cleanup the super_block.

Fixes cb1e0c1d1fad ("ext4: kunit tests for extent splitting and conversion")
---
 fs/ext4/extents-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/extents-test.c +1 -1
index 5a5016ea1ecc..70d84c0a18e2 100644
@@ -144,7 +144,7 @@ static void extents_kunit_exit(struct kunit *test)
 {
 	struct ext4_sb_info *sbi = k_ctx.k_ei->vfs_inode.i_sb->s_fs_info;
 
-	kfree(sbi);
+	deactivate_super(sbi->s_sb);
 	kfree(k_ctx.k_ei);
 	kfree(k_ctx.k_data);
 }
Signature · 1 line
2.34.1
author
#6 lore raw

PATCH v2 6/8 ext4: fix the error handling process in extents_kunit_init).

In reply to Ye Bin

From: Ye Bin <[email protected]>

The error processing in extents_kunit_init() is improper, causing resource leakage.
Reconstruct the error handling process to prevent potential resource leaks

Fixes cb1e0c1d1fad ("ext4: kunit tests for extent splitting and conversion")
---
 fs/ext4/extents-test.c | 41 +++++++++++++++++++++++++++++------------
 1 file changed, 29 insertions(+), 12 deletions(-)
fs/ext4/extents-test.c +29 -12
index 70d84c0a18e2..7e2796f72d45 100644
@@ -222,33 +222,37 @@ static int extents_kunit_init(struct kunit *test)
 		(struct kunit_ext_test_param *)(test->param_value);
 	int err;
 
-	sb = sget(&ext_fs_type, NULL, ext_set, 0, NULL);
-	if (IS_ERR(sb))
-		return PTR_ERR(sb);
-
-	sb->s_blocksize = 4096;
-	sb->s_blocksize_bits = 12;
-
 	sbi = kzalloc_obj(struct ext4_sb_info);
 	if (sbi == NULL)
 		return -ENOMEM;
 
+	sb = sget(&ext_fs_type, NULL, ext_set, 0, NULL);
+	if (IS_ERR(sb)) {
+		kfree(sbi);
+		return PTR_ERR(sb);
+	}
+
 	sbi->s_sb = sb;
 	sb->s_fs_info = sbi;
 
+	sb->s_blocksize = 4096;
+	sb->s_blocksize_bits = 12;
+
 	if (!param || !param->disable_zeroout)
 		sbi->s_extent_max_zeroout_kb = 32;
 
 	/* setup the mock inode */
 	k_ctx.k_ei = kzalloc_obj(struct ext4_inode_info);
-	if (k_ctx.k_ei == NULL)
-		return -ENOMEM;
+	if (k_ctx.k_ei == NULL) {
+		err = -ENOMEM;
+		goto out_deactivate;
+	}
 	ei = k_ctx.k_ei;
 	inode = &ei->vfs_inode;
 
 	err = ext4_es_register_shrinker(sbi);
 	if (err)
-		return err;
+		goto out_deactivate;
 
 	ext4_es_init_tree(&ei->i_es_tree);
 	rwlock_init(&ei->i_es_lock);
@@ -264,8 +268,10 @@ static int extents_kunit_init(struct kunit *test)
 	inode->i_sb = sb;
 
 	k_ctx.k_data = kzalloc(EXT_DATA_LEN * 4096, GFP_KERNEL);
-	if (k_ctx.k_data == NULL)
-		return -ENOMEM;
+	if (k_ctx.k_data == NULL) {
+		err = -ENOMEM;
+		goto out_deactivate;
+	}
 
 	/*
 	 * set the data area to a junk value
@@ -310,6 +316,17 @@ static int extents_kunit_init(struct kunit *test)
 	up_write(&sb->s_umount);
 
 	return 0;
+
+out_deactivate:
+	kfree(k_ctx.k_ei);
+	k_ctx.k_ei = NULL;
+
+	kfree(k_ctx.k_data);
+	k_ctx.k_data = NULL;
+
+	deactivate_locked_super(sb);
+
+	return err;
 }
 
 /*
Signature · 1 line
2.34.1
author
#7 lore raw

PATCH v2 7/8 ext4: fix possible null-ptr-deref in extents_kunit_exit()

In reply to Ye Bin

From: Ye Bin <[email protected]>

There's issue as follows:

KASAN: null-ptr-deref in range [0x00000000000002c0-0x00000000000002c7]
Tainted: [E]=UNSIGNED_MODULE, [N]=TEST
RIP: 0010:extents_kunit_exit+0x2e/0xc0 [ext4_test]
Call Trace:
 <TASK>
 kunit_try_run_case_cleanup+0xbc/0x100 [kunit]
 kunit_generic_run_threadfn_adapter+0x89/0x100 [kunit]
 kthread+0x408/0x540
 ret_from_fork+0xa76/0xdf0
 ret_from_fork_asm+0x1a/0x30

Above issue happens as extents_kunit_init() init testcase failed. So test if testcase is inited success.

Fixes cb1e0c1d1fad ("ext4: kunit tests for extent splitting and conversion")
---
 fs/ext4/extents-test.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/ext4/extents-test.c +5 -1
index 7e2796f72d45..b1ea37e74f12 100644
@@ -142,8 +142,12 @@ static struct file_system_type ext_fs_type = {
 
 static void extents_kunit_exit(struct kunit *test)
 {
-	struct ext4_sb_info *sbi = k_ctx.k_ei->vfs_inode.i_sb->s_fs_info;
+	struct ext4_sb_info *sbi;
 
+	if (!k_ctx.k_ei)
+		return;
+
+	sbi = k_ctx.k_ei->vfs_inode.i_sb->s_fs_info;
 	deactivate_super(sbi->s_sb);
 	kfree(k_ctx.k_ei);
 	kfree(k_ctx.k_data);
Signature · 1 line
2.34.1
author
#8 lore raw

PATCH v2 8/8 ext4: fix possible null-ptr-deref in mbt_kunit_exit()

In reply to Ye Bin

From: Ye Bin <[email protected]>

There's issue as follows:
# test_new_blocks_simple: failed to initialize: -12

KASAN: null-ptr-deref in range [0x0000000000000638-0x000000000000063f]
Tainted: [E]=UNSIGNED_MODULE, [N]=TEST
RIP: 0010:mbt_kunit_exit+0x5e/0x3e0 [ext4_test]
Call Trace:
 <TASK>
 kunit_try_run_case_cleanup+0xbc/0x100 [kunit]
 kunit_generic_run_threadfn_adapter+0x89/0x100 [kunit]
 kthread+0x408/0x540
 ret_from_fork+0xa76/0xdf0
 ret_from_fork_asm+0x1a/0x30

If mbt_kunit_init() init testcase failed will lead to null-ptr-deref. So add test if 'sb' is inited success in mbt_kunit_exit().

Fixes 7c9fa399a369 ("ext4: add first unit test for ext4_mb_new_blocks_simple in mballoc")
---
 fs/ext4/mballoc-test.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/ext4/mballoc-test.c +5 -1
index c75b91ae0cf0..90ed505fa4b1 100644
@@ -362,7 +362,6 @@ static int mbt_kunit_init(struct kunit *test)
 		return ret;
 	}
 
-	test->priv = sb;
 	kunit_activate_static_stub(test,
 				   ext4_read_block_bitmap_nowait,
 				   ext4_read_block_bitmap_nowait_stub);
@@ -383,6 +382,8 @@ static int mbt_kunit_init(struct kunit *test)
 		return -ENOMEM;
 	}
 
+	test->priv = sb;
+
 	return 0;
 }
 
@@ -390,6 +391,9 @@ static void mbt_kunit_exit(struct kunit *test)
 {
 	struct super_block *sb = (struct super_block *)test->priv;
 
+	if (!sb)
+		return;
+
 	mbt_mb_release(sb);
 	mbt_ctx_release(sb);
 	mbt_ext4_free_super_block(sb);
Signature · 1 line
2.34.1