* [PATCH] fs: io_uring: remove NULL check before kfree
@ 2022-06-14 9:13 Dongliang Mu
2022-06-14 9:26 ` Muchun Song
0 siblings, 1 reply; 3+ messages in thread
From: Dongliang Mu @ 2022-06-14 9:13 UTC (permalink / raw)
To: Jens Axboe, Pavel Begunkov; +Cc: mudongliang, io-uring, linux-kernel
From: mudongliang <[email protected]>
kfree can handle NULL pointer as its argument.
According to coccinelle isnullfree check, remove NULL check
before kfree operation.
Signed-off-by: mudongliang <[email protected]>
---
fs/io_uring.c | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 3aab4182fd89..bec47eae2a9b 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -3159,8 +3159,7 @@ static void io_free_batch_list(struct io_ring_ctx *ctx,
if ((req->flags & REQ_F_POLLED) && req->apoll) {
struct async_poll *apoll = req->apoll;
- if (apoll->double_poll)
- kfree(apoll->double_poll);
+ kfree(apoll->double_poll);
list_add(&apoll->poll.wait.entry,
&ctx->apoll_cache);
req->flags &= ~REQ_F_POLLED;
@@ -4499,8 +4498,7 @@ static int io_read(struct io_kiocb *req, unsigned int issue_flags)
kiocb_done(req, ret, issue_flags);
out_free:
/* it's faster to check here then delegate to kfree */
- if (iovec)
- kfree(iovec);
+ kfree(iovec);
return 0;
}
@@ -4602,8 +4600,7 @@ static int io_write(struct io_kiocb *req, unsigned int issue_flags)
}
out_free:
/* it's reportedly faster than delegating the null check to kfree() */
- if (iovec)
- kfree(iovec);
+ kfree(iovec);
return ret;
}
@@ -6227,8 +6224,7 @@ static int io_sendmsg(struct io_kiocb *req, unsigned int issue_flags)
req_set_fail(req);
}
/* fast path, check for non-NULL to avoid function call */
- if (kmsg->free_iov)
- kfree(kmsg->free_iov);
+ kfree(kmsg->free_iov);
req->flags &= ~REQ_F_NEED_CLEANUP;
if (ret >= 0)
ret += sr->done_io;
@@ -6481,8 +6477,7 @@ static int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
}
/* fast path, check for non-NULL to avoid function call */
- if (kmsg->free_iov)
- kfree(kmsg->free_iov);
+ kfree(kmsg->free_iov);
req->flags &= ~REQ_F_NEED_CLEANUP;
if (ret >= 0)
ret += sr->done_io;
--
2.35.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] fs: io_uring: remove NULL check before kfree
2022-06-14 9:13 [PATCH] fs: io_uring: remove NULL check before kfree Dongliang Mu
@ 2022-06-14 9:26 ` Muchun Song
2022-06-14 9:29 ` Dongliang Mu
0 siblings, 1 reply; 3+ messages in thread
From: Muchun Song @ 2022-06-14 9:26 UTC (permalink / raw)
To: Dongliang Mu; +Cc: Jens Axboe, Pavel Begunkov, mudongliang, io-uring, LKML
On Tue, Jun 14, 2022 at 5:14 PM Dongliang Mu <[email protected]> wrote:
>
> From: mudongliang <[email protected]>
>
> kfree can handle NULL pointer as its argument.
> According to coccinelle isnullfree check, remove NULL check
> before kfree operation.
>
> Signed-off-by: mudongliang <[email protected]>
> ---
> fs/io_uring.c | 15 +++++----------
> 1 file changed, 5 insertions(+), 10 deletions(-)
>
> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index 3aab4182fd89..bec47eae2a9b 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
> @@ -3159,8 +3159,7 @@ static void io_free_batch_list(struct io_ring_ctx *ctx,
> if ((req->flags & REQ_F_POLLED) && req->apoll) {
> struct async_poll *apoll = req->apoll;
>
> - if (apoll->double_poll)
> - kfree(apoll->double_poll);
> + kfree(apoll->double_poll);
> list_add(&apoll->poll.wait.entry,
> &ctx->apoll_cache);
> req->flags &= ~REQ_F_POLLED;
> @@ -4499,8 +4498,7 @@ static int io_read(struct io_kiocb *req, unsigned int issue_flags)
> kiocb_done(req, ret, issue_flags);
> out_free:
> /* it's faster to check here then delegate to kfree */
I am feeling you are not on the right way. See the comment
here.
Thanks.
> - if (iovec)
> - kfree(iovec);
> + kfree(iovec);
> return 0;
> }
>
> @@ -4602,8 +4600,7 @@ static int io_write(struct io_kiocb *req, unsigned int issue_flags)
> }
> out_free:
> /* it's reportedly faster than delegating the null check to kfree() */
See here.
> - if (iovec)
> - kfree(iovec);
> + kfree(iovec);
> return ret;
> }
>
> @@ -6227,8 +6224,7 @@ static int io_sendmsg(struct io_kiocb *req, unsigned int issue_flags)
> req_set_fail(req);
> }
> /* fast path, check for non-NULL to avoid function call */
here.
> - if (kmsg->free_iov)
> - kfree(kmsg->free_iov);
> + kfree(kmsg->free_iov);
> req->flags &= ~REQ_F_NEED_CLEANUP;
> if (ret >= 0)
> ret += sr->done_io;
> @@ -6481,8 +6477,7 @@ static int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
> }
>
> /* fast path, check for non-NULL to avoid function call */
And here.
> - if (kmsg->free_iov)
> - kfree(kmsg->free_iov);
> + kfree(kmsg->free_iov);
> req->flags &= ~REQ_F_NEED_CLEANUP;
> if (ret >= 0)
> ret += sr->done_io;
> --
> 2.35.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] fs: io_uring: remove NULL check before kfree
2022-06-14 9:26 ` Muchun Song
@ 2022-06-14 9:29 ` Dongliang Mu
0 siblings, 0 replies; 3+ messages in thread
From: Dongliang Mu @ 2022-06-14 9:29 UTC (permalink / raw)
To: Muchun Song; +Cc: Dongliang Mu, Jens Axboe, Pavel Begunkov, io-uring, LKML
On Tue, Jun 14, 2022 at 5:26 PM Muchun Song <[email protected]> wrote:
>
> On Tue, Jun 14, 2022 at 5:14 PM Dongliang Mu <[email protected]> wrote:
> >
> > From: mudongliang <[email protected]>
> >
> > kfree can handle NULL pointer as its argument.
> > According to coccinelle isnullfree check, remove NULL check
> > before kfree operation.
> >
> > Signed-off-by: mudongliang <[email protected]>
> > ---
> > fs/io_uring.c | 15 +++++----------
> > 1 file changed, 5 insertions(+), 10 deletions(-)
> >
> > diff --git a/fs/io_uring.c b/fs/io_uring.c
> > index 3aab4182fd89..bec47eae2a9b 100644
> > --- a/fs/io_uring.c
> > +++ b/fs/io_uring.c
> > @@ -3159,8 +3159,7 @@ static void io_free_batch_list(struct io_ring_ctx *ctx,
> > if ((req->flags & REQ_F_POLLED) && req->apoll) {
> > struct async_poll *apoll = req->apoll;
> >
> > - if (apoll->double_poll)
> > - kfree(apoll->double_poll);
> > + kfree(apoll->double_poll);
> > list_add(&apoll->poll.wait.entry,
> > &ctx->apoll_cache);
> > req->flags &= ~REQ_F_POLLED;
> > @@ -4499,8 +4498,7 @@ static int io_read(struct io_kiocb *req, unsigned int issue_flags)
> > kiocb_done(req, ret, issue_flags);
> > out_free:
> > /* it's faster to check here then delegate to kfree */
>
> I am feeling you are not on the right way. See the comment
> here.
Thanks for your reply. I ignore them previously. Any method to make
coccicheck ignore such cases?
>
> Thanks.
>
> > - if (iovec)
> > - kfree(iovec);
> > + kfree(iovec);
> > return 0;
> > }
> >
> > @@ -4602,8 +4600,7 @@ static int io_write(struct io_kiocb *req, unsigned int issue_flags)
> > }
> > out_free:
> > /* it's reportedly faster than delegating the null check to kfree() */
>
> See here.
>
> > - if (iovec)
> > - kfree(iovec);
> > + kfree(iovec);
> > return ret;
> > }
> >
> > @@ -6227,8 +6224,7 @@ static int io_sendmsg(struct io_kiocb *req, unsigned int issue_flags)
> > req_set_fail(req);
> > }
> > /* fast path, check for non-NULL to avoid function call */
>
> here.
>
> > - if (kmsg->free_iov)
> > - kfree(kmsg->free_iov);
> > + kfree(kmsg->free_iov);
> > req->flags &= ~REQ_F_NEED_CLEANUP;
> > if (ret >= 0)
> > ret += sr->done_io;
> > @@ -6481,8 +6477,7 @@ static int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
> > }
> >
> > /* fast path, check for non-NULL to avoid function call */
>
> And here.
>
> > - if (kmsg->free_iov)
> > - kfree(kmsg->free_iov);
> > + kfree(kmsg->free_iov);
> > req->flags &= ~REQ_F_NEED_CLEANUP;
> > if (ret >= 0)
> > ret += sr->done_io;
> > --
> > 2.35.1
> >
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-06-14 9:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-14 9:13 [PATCH] fs: io_uring: remove NULL check before kfree Dongliang Mu
2022-06-14 9:26 ` Muchun Song
2022-06-14 9:29 ` Dongliang Mu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox