diff mbox series

[4/6] ext4: remove unneeded check in get_dx_countlimit

Message ID 20241219110027.1440876-5-shikemeng@huaweicloud.com
State New
Headers show
Series Fix and cleanups to ext4 namei.c | expand

Commit Message

Kemeng Shi Dec. 19, 2024, 11 a.m. UTC
The "offset" is always non-NULL, remove unneeded NULL check of "offset".

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 fs/ext4/namei.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Ojaswin Mujoo Dec. 20, 2024, 12:51 p.m. UTC | #1
On Thu, Dec 19, 2024 at 07:00:25PM +0800, Kemeng Shi wrote:
> The "offset" is always non-NULL, remove unneeded NULL check of "offset".
> 
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>

Hi Kemeng,

I know the current callers don't pass NULL but I think we should still
keep the check around just in case, to avoid NULL dereferences in
future. I don't think there's any harm in keeping it

Regards,
ojaswin

> ---
>  fs/ext4/namei.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
> index 33670cebdedc..07a1bb570deb 100644
> --- a/fs/ext4/namei.c
> +++ b/fs/ext4/namei.c
> @@ -434,8 +434,7 @@ static struct dx_countlimit *get_dx_countlimit(struct inode *inode,
>  	} else
>  		return NULL;
>  
> -	if (offset)
> -		*offset = count_offset;
> +	*offset = count_offset;
>  	return (struct dx_countlimit *)(((void *)dirent) + count_offset);
>  }
>  
> -- 
> 2.30.0
>
Zhang Yi Dec. 21, 2024, 7:44 a.m. UTC | #2
On 2024/12/19 19:00, Kemeng Shi wrote:
> The "offset" is always non-NULL, remove unneeded NULL check of "offset".
> 
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>

I agree with Ojaswin, the check strengthens the function, and I'd
suggest that we'd better to keep it for now.

Thanks,
Yi.

> ---
>  fs/ext4/namei.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
> index 33670cebdedc..07a1bb570deb 100644
> --- a/fs/ext4/namei.c
> +++ b/fs/ext4/namei.c
> @@ -434,8 +434,7 @@ static struct dx_countlimit *get_dx_countlimit(struct inode *inode,
>  	} else
>  		return NULL;
>  
> -	if (offset)
> -		*offset = count_offset;
> +	*offset = count_offset;
>  	return (struct dx_countlimit *)(((void *)dirent) + count_offset);
>  }
>
Kemeng Shi Dec. 24, 2024, 12:10 p.m. UTC | #3
on 12/20/2024 8:51 PM, Ojaswin Mujoo wrote:
> On Thu, Dec 19, 2024 at 07:00:25PM +0800, Kemeng Shi wrote:
>> The "offset" is always non-NULL, remove unneeded NULL check of "offset".
>>
>> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
> 
> Hi Kemeng,
> 
> I know the current callers don't pass NULL but I think we should still
> keep the check around just in case, to avoid NULL dereferences in
> future. I don't think there's any harm in keeping it
> 
Sure, no insistant on this and will drop this in next version.

Thanks,
Kemeng

> Regards,
> ojaswin
> 
>> ---
>>  fs/ext4/namei.c | 3 +--
>>  1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
>> index 33670cebdedc..07a1bb570deb 100644
>> --- a/fs/ext4/namei.c
>> +++ b/fs/ext4/namei.c
>> @@ -434,8 +434,7 @@ static struct dx_countlimit *get_dx_countlimit(struct inode *inode,
>>  	} else
>>  		return NULL;
>>  
>> -	if (offset)
>> -		*offset = count_offset;
>> +	*offset = count_offset;
>>  	return (struct dx_countlimit *)(((void *)dirent) + count_offset);
>>  }
>>  
>> -- 
>> 2.30.0
>>
>
Kemeng Shi Dec. 24, 2024, 12:16 p.m. UTC | #4
on 12/21/2024 3:44 PM, Zhang Yi wrote:
> On 2024/12/19 19:00, Kemeng Shi wrote:
>> The "offset" is always non-NULL, remove unneeded NULL check of "offset".
>>
>> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
> 
> I agree with Ojaswin, the check strengthens the function, and I'd
> suggest that we'd better to keep it for now.
Sure, will drop this in next version.

Thanks,
Kemeng
> 
> Thanks,
> Yi.
> 
>> ---
>>  fs/ext4/namei.c | 3 +--
>>  1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
>> index 33670cebdedc..07a1bb570deb 100644
>> --- a/fs/ext4/namei.c
>> +++ b/fs/ext4/namei.c
>> @@ -434,8 +434,7 @@ static struct dx_countlimit *get_dx_countlimit(struct inode *inode,
>>  	} else
>>  		return NULL;
>>  
>> -	if (offset)
>> -		*offset = count_offset;
>> +	*offset = count_offset;
>>  	return (struct dx_countlimit *)(((void *)dirent) + count_offset);
>>  }
>>  
>
diff mbox series

Patch

diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 33670cebdedc..07a1bb570deb 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -434,8 +434,7 @@  static struct dx_countlimit *get_dx_countlimit(struct inode *inode,
 	} else
 		return NULL;
 
-	if (offset)
-		*offset = count_offset;
+	*offset = count_offset;
 	return (struct dx_countlimit *)(((void *)dirent) + count_offset);
 }