Skip to contentSkip to conversation

ntfs: Fix two minor issues in namei.c

PATCH Applied Ethan Tidmore 3 participants 6 messages Feb 26

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover ntfs: Fix two minor issues in namei.c

Here are two non-bug issues but should be fixed.

Ethan Tidmore (2):
ntfs: Replace ERR_PTR(0) with NULL
ntfs: Remove impossible condition

 fs/ntfs/namei.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
Signature · 1 line
2.53.0
#1 lore raw

PATCH 1/2 ntfs: Replace ERR_PTR(0) with NULL

The variable err is confirmed to be 0 and then never reassigned in the success path. The function then returns with ERR_PTR(err) which just equals NULL and can be misleading.

Detected by Smatch:
fs/ntfs/namei.c:1091 ntfs_mkdir() warn:
passing zero to 'ERR_PTR'

---
 fs/ntfs/namei.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ntfs/namei.c +1 -1
index a21eeaec57b4..cecfaabfbfe7 100644
@@ -1088,7 +1088,7 @@ static struct dentry *ntfs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
 	}
 
 	d_instantiate_new(dentry, VFS_I(ni));
-	return ERR_PTR(err);
+	return NULL;
 }
 
 static int ntfs_rmdir(struct inode *dir, struct dentry *dentry)
Signature · 1 line
2.53.0
maintainer Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] ntfs: Replace ERR_PTR(0) with NULL

Quoted 9 lines · Ethan Tidmore

The variable err is confirmed to be 0 and then never reassigned in the success path. The function then returns with ERR_PTR(err) which just equals NULL and can be misleading.

Detected by Smatch:
fs/ntfs/namei.c:1091 ntfs_mkdir() warn:
passing zero to 'ERR_PTR'

Looks good to me. Thanks for the patch.

Quoted 20 lines
---
 fs/ntfs/namei.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ntfs/namei.c +1 -1
index a21eeaec57b4..cecfaabfbfe7 100644
@@ -1088,7 +1088,7 @@ static struct dentry *ntfs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
 	}
 
 	d_instantiate_new(dentry, VFS_I(ni));
-	return ERR_PTR(err);
+	return NULL;
 }
 
 static int ntfs_rmdir(struct inode *dir, struct dentry *dentry)
Signature · 1 line
2.53.0
Signature · 2 lines
Thanks,
Hyunchul
#3 lore raw

PATCH 2/2 ntfs: Remove impossible condition

In reply to Ethan Tidmore

The variable name_len is checked to see if it's larger than the macro NTFS_MAX_NAME_LEN however this condition is impossible because name_len is of type u8 and NTFS_MAX_NAME_LEN is hardcoded to be 255.

Detected by Smatch:
fs/ntfs/namei.c:1175 __ntfs_link() warn:
impossible condition '(name_len > 255) => (0-255 > 255)'

---
 fs/ntfs/namei.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
fs/ntfs/namei.c +1 -4
index cecfaabfbfe7..2952b377dda2 100644
@@ -1172,10 +1172,7 @@ 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);
-	if (name_len > NTFS_MAX_NAME_LEN) {
-		err = -EIO;
-		goto err_out;
-	}
+
 	fn = kzalloc(fn_len, GFP_NOFS);
 	if (!fn) {
 		err = -ENOMEM;
Signature · 1 line
2.53.0
maintainer Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] ntfs: Remove impossible condition

Quoted 9 lines · Ethan Tidmore

The variable name_len is checked to see if it's larger than the macro NTFS_MAX_NAME_LEN however this condition is impossible because name_len is of type u8 and NTFS_MAX_NAME_LEN is hardcoded to be 255.

Detected by Smatch:
fs/ntfs/namei.c:1175 __ntfs_link() warn:
impossible condition '(name_len > 255) => (0-255 > 255)'

Looks good to me. Thanks for the patch.

Quoted 23 lines
---
 fs/ntfs/namei.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
fs/ntfs/namei.c +1 -4
index cecfaabfbfe7..2952b377dda2 100644
@@ -1172,10 +1172,7 @@ 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);
-	if (name_len > NTFS_MAX_NAME_LEN) {
-		err = -EIO;
-		goto err_out;
-	}
+
 	fn = kzalloc(fn_len, GFP_NOFS);
 	if (!fn) {
 		err = -ENOMEM;
Signature · 1 line
2.53.0
Signature · 2 lines
Thanks,
Hyunchul
maintainer Applied
#5 lore raw
In reply to Ethan Tidmore
Quoted 6 lines · Ethan Tidmore

Here are two non-bug issues but should be fixed.

Ethan Tidmore (2):
ntfs: Replace ERR_PTR(0) with NULL
ntfs: Remove impossible condition

Applied it to #ntfs-next.
Thanks!