ntfs: use kzalloc_flex() for FILE_NAME attributes
Hyunchul Lee
maintainerPATCH 1/1 ntfs: use kzalloc_flex() for FILE_NAME attributes
Allocate the variable-length FILE_NAME attributes with kzalloc_flex() and use struct_size() to calculate the attribute length.
Signed-off-by Hyunchul Lee <[email protected]>
--- fs/ntfs/namei.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
fs/ntfs/namei.c +4 -5
@@ -672,8 +672,8 @@ static struct ntfs_inode *__ntfs_create(const struct mnt_idmap *idmap, struct in }/* Create FILE_NAME attribute. */ - fn_len =sizeof (struct file_name_attr ) + name_len *sizeof (__le16); - fn =kzalloc (fn_len,GFP_NOFS ); + fn_len =struct_size (fn, file_name, name_len); + fn =kzalloc_flex (*fn, file_name, name_len,GFP_NOFS );if (!fn) { err = -ENOMEM ; goto err_out;
@@ -1387,9 +1387,8 @@ static int __ntfs_link(struct ntfs_inode *ni, struct ntfs_inode *dir_ni, }/* Create FILE_NAME attribute. */ - fn_len =sizeof (struct file_name_attr ) + name_len *sizeof (__le16); - - fn =kzalloc (fn_len,GFP_NOFS ); + fn_len =struct_size (fn, file_name, name_len); + fn =kzalloc_flex (*fn, file_name, name_len,GFP_NOFS );if (!fn) { err = -ENOMEM ; goto err_out;
Signature · 1 line
2.43.0
Quoted 25 lines · Hyunchul Lee
Allocate the variable-length
FILE_NAMEattributes withkzalloc_flex()and usestruct_size()to calculate the attribute length.Signed-off-by Hyunchul Lee <[email protected]>--- fs/ntfs/namei.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)fs/ntfs/namei.c +2
-2@@ -672,8 +672,8 @@ static struct ntfs_inode *__ntfs_create(const struct mnt_idmap *idmap, struct in }/* Create FILE_NAME attribute. */ - fn_len =sizeof (struct file_name_attr ) + name_len *sizeof (__le16); - fn =kzalloc (fn_len,GFP_NOFS ); + fn_len =struct_size (fn, file_name, name_len); + fn =kzalloc_flex (*fn, file_name, name_len,GFP_NOFS );if (!fn) { err = -ENOMEM ; goto err_out;@@ -1387,9 +1387,8 @@ static int __ntfs_link(struct ntfs_inode *ni, struct ntfs_inode *dir_ni, }
fs/ntfs/namei.c static int __ntfs_link(struct ntfs_inode *ni, struct ntfs_inode *dir_ni, · line 1394
Quoted 10 lines
fs/ntfs/namei.c +2
-3/* Create FILE_NAME attribute. */ - fn_len =sizeof (struct file_name_attr ) + name_len *sizeof (__le16); - - fn =kzalloc (fn_len,GFP_NOFS ); + fn_len =struct_size (fn, file_name, name_len); + fn =kzalloc_flex (*fn, file_name, name_len,GFP_NOFS );if (!fn) { err = -ENOMEM ; goto err_out;
Looks good to me.
Reviewed-by Baolin Liu <[email protected]>
Quoted 5 lines · Hyunchul Lee
Allocate the variable-length
FILE_NAMEattributes withkzalloc_flex()and usestruct_size()to calculate the attribute length.Signed-off-by Hyunchul Lee <[email protected]>
Applied it to #ntfs-next.
Thanks.