Skip to contentSkip to conversation

io_uring: Remove unneeded NULL check before free

PATCH In review Ye Bin 2 participants 2 messages Sep 24, 2020

Subsystems (2)
lore
Share & tools
lore

Ye Bin

author
#0 lore raw

PATCH 1/1 io_uring: Remove unneeded NULL check before free

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.

---
 fs/io_uring.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
fs/io_uring.c +4 -8
index 815be15c2aee..23f99ffbb480 100644
@@ -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:
Signature · 1 line
2.16.2.dirty
#1 lore raw

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.

Quoted 31 lines · 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.

---
 fs/io_uring.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
fs/io_uring.c +1 -2
index 815be15c2aee..23f99ffbb480 100644
@@ -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));
 

fs/io_uring.c static int io_read(struct io_kiocb *req, bool force_nonblock, · line 3288

Quoted 3 lines
fs/io_uring.c +0 -0
@@ -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 ^

Quoted 29 lines
fs/io_uring.c +3 -6
-	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:
Signature · 1 line
2.16.2.dirty

Thanks,
Stefano