From: alison.schofield@intel.com
To: Ben Widawsky <ben.widawsky@intel.com>,
Dan Williams <dan.j.williams@intel.com>,
Ira Weiny <ira.weiny@intel.com>,
Vishal Verma <vishal.l.verma@intel.com>
Cc: Alison Schofield <alison.schofield@intel.com>,
linux-cxl@vger.kernel.org, kernel test robot <lkp@intel.com>,
Dan Carpenter <dan.carpenter@oracle.com>
Subject: [PATCH] cxl/mbox: Handle variable size output while still signed
Date: Fri, 8 Apr 2022 20:13:12 -0700 [thread overview]
Message-ID: <20220409031312.1220512-1-alison.schofield@intel.com> (raw)
From: Alison Schofield <alison.schofield@intel.com>
A mailbox command output size value of (-1) means that a device
may return a variable sized output for that command. The device
defines a maximum payload size, so the driver will allocate enough
memory to receive that maximum payload for these commands.
A recent code refactoring moved the check for variable sized output
to occur after the signedness is discarded from the output size.
Move the check to occur while still operating on the signed output
size variable.
Smatch warn: unsigned 'out_size' is never less than 0
Fixes: be0d0ce77aa3 ("cxl/mbox: Move build of user mailbox cmd to a helper funct
ions")
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Alison Schofield <alison.schofield@intel.com>
---
drivers/cxl/core/mbox.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c
index 8a8388599a85..987703ae1fe3 100644
--- a/drivers/cxl/core/mbox.c
+++ b/drivers/cxl/core/mbox.c
@@ -258,6 +258,7 @@ static int cxl_mbox_cmd_ctor(struct cxl_mbox_cmd *mbox,
*mbox = (struct cxl_mbox_cmd) {
.opcode = opcode,
.size_in = in_size,
+ .size_out = out_size,
};
if (in_size) {
@@ -274,12 +275,6 @@ static int cxl_mbox_cmd_ctor(struct cxl_mbox_cmd *mbox,
}
}
- /* Prepare to handle a full payload for variable sized output */
- if (out_size < 0)
- mbox->size_out = cxlds->payload_size;
- else
- mbox->size_out = out_size;
-
if (mbox->size_out) {
mbox->payload_out = kvzalloc(mbox->size_out, GFP_KERNEL);
if (!mbox->payload_out) {
@@ -320,7 +315,6 @@ static int cxl_to_mem_cmd_raw(struct cxl_mem_command *mem_cmd,
.info = {
.id = CXL_MEM_COMMAND_ID_RAW,
.size_in = send_cmd->in.size,
- .size_out = send_cmd->out.size,
},
.opcode = send_cmd->raw.opcode
};
@@ -365,7 +359,6 @@ static int cxl_to_mem_cmd(struct cxl_mem_command *mem_cmd,
.id = info->id,
.flags = info->flags,
.size_in = send_cmd->in.size,
- .size_out = send_cmd->out.size,
},
.opcode = c->opcode
};
@@ -417,6 +410,12 @@ static int cxl_validate_cmd_from_user(struct cxl_mbox_cmd *mbox_cmd,
if (rc)
return rc;
+ /* Prepare to handle a full payload for variable sized output */
+ if (send_cmd->out.size < 0)
+ mem_cmd.info.size_out = cxlds->payload_size;
+ else
+ mem_cmd.info.size_out = send_cmd->out.size;
+
/* Sanitize and construct a cxl_mbox_cmd */
return cxl_mbox_cmd_ctor(mbox_cmd, cxlds, mem_cmd.opcode,
mem_cmd.info.size_in, mem_cmd.info.size_out,
base-commit: 7dc1d11d7abae52aada5340fb98885f0ddbb7c37
--
2.31.1
next reply other threads:[~2022-04-09 3:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-09 3:13 alison.schofield [this message]
2022-04-12 23:00 ` [PATCH] cxl/mbox: Handle variable size output while still signed Dan Williams
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=20220409031312.1220512-1-alison.schofield@intel.com \
--to=alison.schofield@intel.com \
--cc=ben.widawsky@intel.com \
--cc=dan.carpenter@oracle.com \
--cc=dan.j.williams@intel.com \
--cc=ira.weiny@intel.com \
--cc=linux-cxl@vger.kernel.org \
--cc=lkp@intel.com \
--cc=vishal.l.verma@intel.com \
/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