Commit 76dba1fe authored by Liao Yuanhong's avatar Liao Yuanhong Committed by Theodore Ts'o
Browse files

ext4: use kmalloc_array() for array space allocation



Replace kmalloc(size * sizeof) with kmalloc_array() for safer memory
allocation and overflow prevention.

Cc: stable@kernel.org
Signed-off-by: default avatarLiao Yuanhong <liaoyuanhong@vivo.com>
Link: https://patch.msgid.link/20250811125816.570142-1-liaoyuanhong@vivo.com


Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent 02c7f721
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -589,7 +589,8 @@ int ext4_init_orphan_info(struct super_block *sb)
	}
	oi->of_blocks = inode->i_size >> sb->s_blocksize_bits;
	oi->of_csum_seed = EXT4_I(inode)->i_csum_seed;
	oi->of_binfo = kmalloc(oi->of_blocks*sizeof(struct ext4_orphan_block),
	oi->of_binfo = kmalloc_array(oi->of_blocks,
				     sizeof(struct ext4_orphan_block),
				     GFP_KERNEL);
	if (!oi->of_binfo) {
		ret = -ENOMEM;