public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH] io_uring: Remove unneeded NULL check before free
@ 2020-09-24  1:36 Ye Bin
  2020-09-24  9:59 ` Stefano Garzarella
  0 siblings, 1 reply; 2+ messages in thread
From: Ye Bin @ 2020-09-24  1:36 UTC (permalink / raw)
  To: axboe, io-uring; +Cc: Ye Bin

Fixes coccicheck warnig:
fs//io_uring.c:5775:4-9: WARNING: NULL check before some freeing
functions is not needed.
fs//io_uring.c:1617:2-7: WARNING: NULL check before some freeing
functions is not needed.
fs//io_uring.c:3291:2-7: WARNING: NULL check before some freeing
functions is not needed.
fs//io_uring.c:3398:2-7: WARNING: NULL check before some freeing
functions is not needed.

Reported-by: Hulk Robot <[email protected]>
Signed-off-by: Ye Bin <[email protected]>
---
 fs/io_uring.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 815be15c2aee..23f99ffbb480 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -1613,8 +1613,7 @@ static bool io_dismantle_req(struct io_kiocb *req)
 {
 	io_clean_op(req);
 
-	if (req->async_data)
-		kfree(req->async_data);
+	kfree(req->async_data);
 	if (req->file)
 		io_put_file(req, req->file, (req->flags & REQ_F_FIXED_FILE));
 
@@ -3287,8 +3286,7 @@ static int io_read(struct io_kiocb *req, bool force_nonblock,
 	ret = 0;
 out_free:
 	/* it's reportedly faster than delegating the null check to kfree() */
-	if (iovec)
-		kfree(iovec);
+	kfree(iovec);
 	return ret;
 }
 
@@ -3394,8 +3392,7 @@ static int io_write(struct io_kiocb *req, bool force_nonblock,
 	}
 out_free:
 	/* it's reportedly faster than delegating the null check to kfree() */
-	if (iovec)
-		kfree(iovec);
+	kfree(iovec);
 	return ret;
 }
 
@@ -5771,8 +5768,7 @@ static void __io_clean_op(struct io_kiocb *req)
 		case IORING_OP_WRITE_FIXED:
 		case IORING_OP_WRITE: {
 			struct io_async_rw *io = req->async_data;
-			if (io->free_iovec)
-				kfree(io->free_iovec);
+			kfree(io->free_iovec);
 			break;
 			}
 		case IORING_OP_RECVMSG:
-- 
2.16.2.dirty


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] io_uring: Remove unneeded NULL check before free
  2020-09-24  1:36 [PATCH] io_uring: Remove unneeded NULL check before free Ye Bin
@ 2020-09-24  9:59 ` Stefano Garzarella
  0 siblings, 0 replies; 2+ messages in thread
From: Stefano Garzarella @ 2020-09-24  9:59 UTC (permalink / raw)
  To: Ye Bin; +Cc: axboe, io-uring

Hi,
thanks for the patch, but as explained in some comments in the code,
it's seems faster to do the check and avoid to call kfree() in the
critical data path.

On Thu, Sep 24, 2020 at 09:36:06AM +0800, Ye Bin wrote:
> Fixes coccicheck warnig:
> fs//io_uring.c:5775:4-9: WARNING: NULL check before some freeing
> functions is not needed.
> fs//io_uring.c:1617:2-7: WARNING: NULL check before some freeing
> functions is not needed.
> fs//io_uring.c:3291:2-7: WARNING: NULL check before some freeing
> functions is not needed.
> fs//io_uring.c:3398:2-7: WARNING: NULL check before some freeing
> functions is not needed.
> 
> Reported-by: Hulk Robot <[email protected]>
> Signed-off-by: Ye Bin <[email protected]>
> ---
>  fs/io_uring.c | 12 ++++--------
>  1 file changed, 4 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index 815be15c2aee..23f99ffbb480 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
> @@ -1613,8 +1613,7 @@ static bool io_dismantle_req(struct io_kiocb *req)
>  {
>  	io_clean_op(req);
>  
> -	if (req->async_data)
> -		kfree(req->async_data);
> +	kfree(req->async_data);
>  	if (req->file)
>  		io_put_file(req, req->file, (req->flags & REQ_F_FIXED_FILE));
>  
> @@ -3287,8 +3286,7 @@ static int io_read(struct io_kiocb *req, bool force_nonblock,
>  	ret = 0;
>  out_free:
>  	/* it's reportedly faster than delegating the null check to kfree() */
For example here ^

> -	if (iovec)
> -		kfree(iovec);
> +	kfree(iovec);
>  	return ret;
>  }
>  
> @@ -3394,8 +3392,7 @@ static int io_write(struct io_kiocb *req, bool force_nonblock,
>  	}
>  out_free:
>  	/* it's reportedly faster than delegating the null check to kfree() */
> -	if (iovec)
> -		kfree(iovec);
> +	kfree(iovec);
>  	return ret;
>  }
>  
> @@ -5771,8 +5768,7 @@ static void __io_clean_op(struct io_kiocb *req)
>  		case IORING_OP_WRITE_FIXED:
>  		case IORING_OP_WRITE: {
>  			struct io_async_rw *io = req->async_data;
> -			if (io->free_iovec)
> -				kfree(io->free_iovec);
> +			kfree(io->free_iovec);
>  			break;
>  			}
>  		case IORING_OP_RECVMSG:
> -- 
> 2.16.2.dirty
> 

Thanks,
Stefano


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-09-24  9:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-24  1:36 [PATCH] io_uring: Remove unneeded NULL check before free Ye Bin
2020-09-24  9:59 ` Stefano Garzarella

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox