ntfs: Fix two minor issues in namei.c
Subsystems (2)
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
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
@@ -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
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:1091ntfs_mkdir()warn:
passing zero to 'ERR_PTR'Signed-off-by Ethan Tidmore <[email protected]>
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@@ -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
PATCH 2/2 ntfs: Remove impossible condition
In reply to Ethan TidmoreThe 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
@@ -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
Re: [PATCH 2/2] ntfs: Remove impossible condition
Quoted 9 lines · Ethan Tidmore
The variable
name_lenis checked to see if it's larger than the macroNTFS_MAX_NAME_LENhowever this condition is impossible becausename_lenis of type u8 andNTFS_MAX_NAME_LENis hardcoded to be 255.Detected by Smatch:
fs/ntfs/namei.c:1175__ntfs_link()warn:
impossible condition '(name_len> 255) => (0-255 > 255)'Signed-off-by Ethan Tidmore <[email protected]>
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@@ -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
Quoted 6 lines · Ethan Tidmore
Here are two non-bug issues but should be fixed.
Ethan Tidmore (2):
ntfs: ReplaceERR_PTR(0)with NULL
ntfs: Remove impossible condition
Applied it to #ntfs-next.
Thanks!