From: Chaitanya Kulkarni <kch@nvidia.com>
To: <hare@suse.de>
Cc: <linux-nvme@lists.infradead.org>, <hch@lst.de>,
<sagi@grimberg.me>, Chaitanya Kulkarni <kch@nvidia.com>
Subject: [PATCH 2/3] nvmet_auth: use common helper for buffer alloc
Date: Mon, 22 May 2023 01:37:12 -0700 [thread overview]
Message-ID: <20230522083713.107001-3-kch@nvidia.com> (raw)
In-Reply-To: <20230522083713.107001-1-kch@nvidia.com>
Add a common helper to factor out buffer allocation in
nvmet_execute_auth_send() and nvmet_execute_auth_receive().
Only functional change in this patch is transfer buffer allocation is
moved before nvmet_check_transfer_len() and it is freed if when
nvmet_check_transfer_len() fails. But similar allocation and free is
used in error unwind path in nvme code and it is not in fast path, so
it shuold be fine.
Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
drivers/nvme/target/fabrics-cmd-auth.c | 43 ++++++++++++--------------
1 file changed, 19 insertions(+), 24 deletions(-)
diff --git a/drivers/nvme/target/fabrics-cmd-auth.c b/drivers/nvme/target/fabrics-cmd-auth.c
index 6ad322b3d0a9..ad8e914ae56f 100644
--- a/drivers/nvme/target/fabrics-cmd-auth.c
+++ b/drivers/nvme/target/fabrics-cmd-auth.c
@@ -29,6 +29,18 @@ static u16 nvmet_auth_check_secp_spsp(struct nvmet_req *req)
return NVME_SC_SUCCESS;
}
+static u16 nvmet_auth_alloc_transfer_buffer(struct nvmet_req *req, void **buf,
+ u32 *len)
+{
+ *len = le32_to_cpu(req->cmd->auth_receive.al);
+ if (!*len) {
+ req->error_loc = offsetof(struct nvmf_auth_receive_command, al);
+ return NVME_SC_INVALID_FIELD | NVME_SC_DNR;
+ }
+ *buf = kmalloc(*len, GFP_KERNEL);
+ return *buf ? NVME_SC_SUCCESS : NVME_SC_INTERNAL;
+}
+
static void nvmet_auth_expired_work(struct work_struct *work)
{
struct nvmet_sq *sq = container_of(to_delayed_work(work),
@@ -207,25 +219,16 @@ void nvmet_execute_auth_send(struct nvmet_req *req)
status = nvmet_auth_check_secp_spsp(req);
if (status)
goto done;
-
- tl = le32_to_cpu(req->cmd->auth_send.tl);
- if (!tl) {
- status = NVME_SC_INVALID_FIELD | NVME_SC_DNR;
- req->error_loc =
- offsetof(struct nvmf_auth_send_command, tl);
+ status = nvmet_auth_alloc_transfer_buffer(req, &d, &tl);
+ if (status)
goto done;
- }
+
if (!nvmet_check_transfer_len(req, tl)) {
pr_debug("%s: transfer length mismatch (%u)\n", __func__, tl);
+ kfree(d);
return;
}
- d = kmalloc(tl, GFP_KERNEL);
- if (!d) {
- status = NVME_SC_INTERNAL;
- goto done;
- }
-
status = nvmet_copy_from_sgl(req, 0, d, tl);
if (status)
goto done_kfree;
@@ -440,23 +443,15 @@ void nvmet_execute_auth_receive(struct nvmet_req *req)
status = nvmet_auth_check_secp_spsp(req);
if (status)
goto done;
- al = le32_to_cpu(req->cmd->auth_receive.al);
- if (!al) {
- status = NVME_SC_INVALID_FIELD | NVME_SC_DNR;
- req->error_loc =
- offsetof(struct nvmf_auth_receive_command, al);
+ status = nvmet_auth_alloc_transfer_buffer(req, &d, &al);
+ if (status)
goto done;
- }
if (!nvmet_check_transfer_len(req, al)) {
pr_debug("%s: transfer length mismatch (%u)\n", __func__, al);
+ kfree(d);
return;
}
- d = kmalloc(al, GFP_KERNEL);
- if (!d) {
- status = NVME_SC_INTERNAL;
- goto done;
- }
pr_debug("%s: ctrl %d qid %d step %x\n", __func__,
ctrl->cntlid, req->sq->qid, req->sq->dhchap_step);
switch (req->sq->dhchap_step) {
--
2.40.0
next prev parent reply other threads:[~2023-05-22 8:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-22 8:37 [PATCH 0/3] nvmet-auth: auth send / receive cleanup Chaitanya Kulkarni
2023-05-22 8:37 ` [PATCH 1/3] nvmet-auth: use common helper to check secp/spsp Chaitanya Kulkarni
2023-05-23 6:55 ` Christoph Hellwig
2023-05-22 8:37 ` Chaitanya Kulkarni [this message]
2023-05-23 6:56 ` [PATCH 2/3] nvmet_auth: use common helper for buffer alloc Christoph Hellwig
2023-05-22 8:37 ` [PATCH 3/3] nvmet-auth: use helper for auth send/recv cmd prep Chaitanya Kulkarni
2023-05-23 6:56 ` Christoph Hellwig
2023-05-23 8:33 ` Chaitanya Kulkarni
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=20230522083713.107001-3-kch@nvidia.com \
--to=kch@nvidia.com \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
/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