Skip to contentSkip to conversation

ntfs: use kzalloc_flex() for FILE_NAME attributes

PATCH Applied Hyunchul Lee 3 participants 3 messages Nov 20 NTFS filesystem

lore
Share & tools
lore

Hyunchul Lee

author maintainer
#0 lore raw

PATCH 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.

---
 fs/ntfs/namei.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
fs/ntfs/namei.c +4 -5
index 67f1d7eecf2b..f3c6911a1bc1 100644
@@ -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
Reviewed-by Baolin Liu on v1 1/1
#1 lore raw
Quoted 25 lines · Hyunchul Lee

Allocate the variable-length FILE_NAME attributes with kzalloc_flex() and use struct_size() to calculate the attribute length.

---
  fs/ntfs/namei.c | 9 ++++-----
  1 file changed, 4 insertions(+), 5 deletions(-)
fs/ntfs/namei.c +2 -2
index 67f1d7eecf2b..f3c6911a1bc1 100644
@@ -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.