linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: chenxiang <chenxiang66@hisilicon.com>
To: <bcrl@kvack.org>, <viro@zeniv.linux.org.uk>
Cc: <linux-aio@kvack.org>, <linux-fsdevel@vger.kernel.org>,
	<linuxarm@huawei.com>, Xiang Chen <chenxiang66@hisilicon.com>
Subject: [PATCH] aio: Adjust the position of get_reqs_available() in aio_get_req()
Date: Thu, 20 Jan 2022 14:42:26 +0800	[thread overview]
Message-ID: <1642660946-60244-1-git-send-email-chenxiang66@hisilicon.com> (raw)

From: Xiang Chen <chenxiang66@hisilicon.com>

Right now allocating aio_kiocb is in front of get_reqs_available(),
then need to free aio_kiocb if get_reqs_available() is failed.
Put get_reqs_availabe() in front of allocating aio_kiocb to avoid
freeing aio_kiocb if get_reqs_available() is failed.

Signed-off-by: Xiang Chen <chenxiang66@hisilicon.com>
---
 fs/aio.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/fs/aio.c b/fs/aio.c
index 9c81cf611d65..79f8ea31a696 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -1025,14 +1025,12 @@ static inline struct aio_kiocb *aio_get_req(struct kioctx *ctx)
 {
 	struct aio_kiocb *req;
 
-	req = kmem_cache_alloc(kiocb_cachep, GFP_KERNEL);
-	if (unlikely(!req))
+	if (unlikely(!get_reqs_available(ctx)))
 		return NULL;
 
-	if (unlikely(!get_reqs_available(ctx))) {
-		kmem_cache_free(kiocb_cachep, req);
+	req = kmem_cache_alloc(kiocb_cachep, GFP_KERNEL);
+	if (unlikely(!req))
 		return NULL;
-	}
 
 	percpu_ref_get(&ctx->reqs);
 	req->ki_ctx = ctx;
-- 
2.33.0


             reply	other threads:[~2022-01-20  6:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-20  6:42 chenxiang [this message]
2022-01-20  9:03 ` [PATCH] aio: Adjust the position of get_reqs_available() in aio_get_req() Christoph Hellwig
2022-01-20 11:33   ` chenxiang (M)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1642660946-60244-1-git-send-email-chenxiang66@hisilicon.com \
    --to=chenxiang66@hisilicon.com \
    --cc=bcrl@kvack.org \
    --cc=linux-aio@kvack.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).