Skip to content

Commit d5e9836

Browse files
tobluxtytso
authored andcommitted
ext4: use struct_size() to improve ext4_htree_store_dirent()
Inline and use struct_size() to calculate the number of bytes to allocate for new_fn and remove the local variable len. Reviewed-by: Jan Kara <[email protected]> Signed-off-by: Thorsten Blum <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent de183b2 commit d5e9836

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

fs/ext4/dir.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,14 +471,13 @@ int ext4_htree_store_dirent(struct file *dir_file, __u32 hash,
471471
struct rb_node **p, *parent = NULL;
472472
struct fname *fname, *new_fn;
473473
struct dir_private_info *info;
474-
int len;
475474

476475
info = dir_file->private_data;
477476
p = &info->root.rb_node;
478477

479478
/* Create and allocate the fname structure */
480-
len = sizeof(struct fname) + ent_name->len + 1;
481-
new_fn = kzalloc(len, GFP_KERNEL);
479+
new_fn = kzalloc(struct_size(new_fn, name, ent_name->len + 1),
480+
GFP_KERNEL);
482481
if (!new_fn)
483482
return -ENOMEM;
484483
new_fn->hash = hash;

0 commit comments

Comments
 (0)