[PATCH] ocfs2: remove unnecessary NULL check in ocfs2_grab_folios()

Dan Carpenter posted 1 patch 1 month, 2 weeks ago
fs/ocfs2/alloc.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
[PATCH] ocfs2: remove unnecessary NULL check in ocfs2_grab_folios()
Posted by Dan Carpenter 1 month, 2 weeks ago
Smatch complains that checking "folios" for NULL doesn't make sense
because it has already been dereferenced at this point.  Really passing a
NULL "folios" pointer to ocfs2_grab_folios() doesn't make sense, and
fortunately none of the callers do that.  Delete the unnecessary NULL
check.

Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 fs/ocfs2/alloc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
index 821cb7874685..162711cc5b20 100644
--- a/fs/ocfs2/alloc.c
+++ b/fs/ocfs2/alloc.c
@@ -6928,8 +6928,7 @@ static int ocfs2_grab_folios(struct inode *inode, loff_t start, loff_t end,
 
 out:
 	if (ret != 0) {
-		if (folios)
-			ocfs2_unlock_and_free_folios(folios, numfolios);
+		ocfs2_unlock_and_free_folios(folios, numfolios);
 		numfolios = 0;
 	}
 
-- 
2.47.2
Re: [PATCH] ocfs2: remove unnecessary NULL check in ocfs2_grab_folios()
Posted by Joseph Qi 1 month, 2 weeks ago

On 2025/8/19 17:41, Dan Carpenter wrote:
> Smatch complains that checking "folios" for NULL doesn't make sense
> because it has already been dereferenced at this point.  Really passing a
> NULL "folios" pointer to ocfs2_grab_folios() doesn't make sense, and
> fortunately none of the callers do that.  Delete the unnecessary NULL
> check.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

Acked-by: Joseph Qi <joseph.qi@linux.alibaba.com>
> ---
>  fs/ocfs2/alloc.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
> index 821cb7874685..162711cc5b20 100644
> --- a/fs/ocfs2/alloc.c
> +++ b/fs/ocfs2/alloc.c
> @@ -6928,8 +6928,7 @@ static int ocfs2_grab_folios(struct inode *inode, loff_t start, loff_t end,
>  
>  out:
>  	if (ret != 0) {
> -		if (folios)
> -			ocfs2_unlock_and_free_folios(folios, numfolios);
> +		ocfs2_unlock_and_free_folios(folios, numfolios);
>  		numfolios = 0;
>  	}
>
Re: [External] : [PATCH] ocfs2: remove unnecessary NULL check in ocfs2_grab_folios()
Posted by Mark Tinguely 1 month, 2 weeks ago
On 8/19/25 4:41 AM, Dan Carpenter wrote:
> Smatch complains that checking "folios" for NULL doesn't make sense
> because it has already been dereferenced at this point.  Really passing a
> NULL "folios" pointer to ocfs2_grab_folios() doesn't make sense, and
> fortunately none of the callers do that.  Delete the unnecessary NULL
> check.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
>   fs/ocfs2/alloc.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
> index 821cb7874685..162711cc5b20 100644
> --- a/fs/ocfs2/alloc.c
> +++ b/fs/ocfs2/alloc.c
> @@ -6928,8 +6928,7 @@ static int ocfs2_grab_folios(struct inode *inode, loff_t start, loff_t end,
>   
>   out:
>   	if (ret != 0) {
> -		if (folios)
> -			ocfs2_unlock_and_free_folios(folios, numfolios);
> +		ocfs2_unlock_and_free_folios(folios, numfolios);
>   		numfolios = 0;
>   	}
>   

Reviewed-by: Mark Tinguely <mark.tinguely@oracle.com>