[PATCH 2/2] ntfs: Remove impossible condition

Ethan Tidmore posted 2 patches 1 month, 1 week ago
[PATCH 2/2] ntfs: Remove impossible condition
Posted by Ethan Tidmore 1 month, 1 week ago
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)'

Signed-off-by: Ethan Tidmore <ethantidmore06@gmail.com>
---
 fs/ntfs/namei.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/fs/ntfs/namei.c b/fs/ntfs/namei.c
index cecfaabfbfe7..2952b377dda2 100644
--- a/fs/ntfs/namei.c
+++ b/fs/ntfs/namei.c
@@ -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;
-- 
2.53.0
Re: [PATCH 2/2] ntfs: Remove impossible condition
Posted by Hyunchul Lee 1 month, 1 week ago
On Wed, Feb 25, 2026 at 10:03:55PM -0600, Ethan Tidmore wrote:
> 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)'
> 
> Signed-off-by: Ethan Tidmore <ethantidmore06@gmail.com>

Looks good to me. Thanks for the patch.

Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com>

> ---
>  fs/ntfs/namei.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/fs/ntfs/namei.c b/fs/ntfs/namei.c
> index cecfaabfbfe7..2952b377dda2 100644
> --- a/fs/ntfs/namei.c
> +++ b/fs/ntfs/namei.c
> @@ -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;
> -- 
> 2.53.0
> 

-- 
Thanks,
Hyunchul