Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ext4: fix the error handling process in extents_kunit_init).

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")
Signed-off-by: Ye Bin <yebin10@huawei.com>
Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
Link: https://patch.msgid.link/20260330133035.287842-4-yebin@huaweicloud.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>

authored by

Ye Bin and committed by
Theodore Ts'o
17f73c95 f9c1f764

+37 -17
+37 -17
fs/ext4/extents-test.c
··· 225 225 (struct kunit_ext_test_param *)(test->param_value); 226 226 int err; 227 227 228 - sb = sget(&ext_fs_type, NULL, ext_set, 0, NULL); 229 - if (IS_ERR(sb)) 230 - return PTR_ERR(sb); 231 - 232 - sb->s_blocksize = 4096; 233 - sb->s_blocksize_bits = 12; 234 - 235 228 sbi = kzalloc_obj(struct ext4_sb_info); 236 229 if (sbi == NULL) 237 230 return -ENOMEM; 238 231 232 + sb = sget(&ext_fs_type, NULL, ext_set, 0, NULL); 233 + if (IS_ERR(sb)) { 234 + kfree(sbi); 235 + return PTR_ERR(sb); 236 + } 237 + 239 238 sbi->s_sb = sb; 240 239 sb->s_fs_info = sbi; 240 + 241 + sb->s_blocksize = 4096; 242 + sb->s_blocksize_bits = 12; 241 243 242 244 if (!param || !param->disable_zeroout) 243 245 sbi->s_extent_max_zeroout_kb = 32; 244 246 245 - /* setup the mock inode */ 246 - k_ctx.k_ei = kzalloc_obj(struct ext4_inode_info); 247 - if (k_ctx.k_ei == NULL) 248 - return -ENOMEM; 249 - ei = k_ctx.k_ei; 250 - inode = &ei->vfs_inode; 251 - 252 247 err = ext4_es_register_shrinker(sbi); 253 248 if (err) 254 - return err; 249 + goto out_deactivate; 250 + 251 + /* setup the mock inode */ 252 + k_ctx.k_ei = kzalloc_obj(struct ext4_inode_info); 253 + if (k_ctx.k_ei == NULL) { 254 + err = -ENOMEM; 255 + goto out; 256 + } 257 + ei = k_ctx.k_ei; 258 + inode = &ei->vfs_inode; 255 259 256 260 ext4_es_init_tree(&ei->i_es_tree); 257 261 rwlock_init(&ei->i_es_lock); ··· 271 267 inode->i_sb = sb; 272 268 273 269 k_ctx.k_data = kzalloc(EXT_DATA_LEN * 4096, GFP_KERNEL); 274 - if (k_ctx.k_data == NULL) 275 - return -ENOMEM; 270 + if (k_ctx.k_data == NULL) { 271 + err = -ENOMEM; 272 + goto out; 273 + } 276 274 277 275 /* 278 276 * set the data area to a junk value ··· 319 313 up_write(&sb->s_umount); 320 314 321 315 return 0; 316 + 317 + out: 318 + kfree(k_ctx.k_ei); 319 + k_ctx.k_ei = NULL; 320 + 321 + kfree(k_ctx.k_data); 322 + k_ctx.k_data = NULL; 323 + 324 + ext4_es_unregister_shrinker(sbi); 325 + out_deactivate: 326 + deactivate_locked_super(sb); 327 + kfree(sbi); 328 + 329 + return err; 322 330 } 323 331 324 332 /*