Commit 28559959 authored by Jonas Rabenstein's avatar Jonas Rabenstein Committed by Jens Axboe

block: sed-opal: split generation of bytestring header and content

Split the header generation from the (normal) memcpy part if a
bytestring is copied into the command buffer. This allows in-place
generation of the bytestring content. For example, copy_from_user may be
used without an intermediate buffer.
Signed-off-by: default avatarJonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
Signed-off-by: default avatarDavid Kozub <zub@linux.fjfi.cvut.cz>
Reviewed-by: default avatarScott Bauer <sbauer@plzdonthack.me>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarJon Derrick <jonathan.derrick@intel.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent b2f9c6eb
...@@ -580,15 +580,11 @@ static void add_token_u64(int *err, struct opal_dev *cmd, u64 number) ...@@ -580,15 +580,11 @@ static void add_token_u64(int *err, struct opal_dev *cmd, u64 number)
add_token_u8(err, cmd, number >> (len * 8)); add_token_u8(err, cmd, number >> (len * 8));
} }
static void add_token_bytestring(int *err, struct opal_dev *cmd, static u8 *add_bytestring_header(int *err, struct opal_dev *cmd, size_t len)
const u8 *bytestring, size_t len)
{ {
size_t header_len = 1; size_t header_len = 1;
bool is_short_atom = true; bool is_short_atom = true;
if (*err)
return;
if (len & ~SHORT_ATOM_LEN_MASK) { if (len & ~SHORT_ATOM_LEN_MASK) {
header_len = 2; header_len = 2;
is_short_atom = false; is_short_atom = false;
...@@ -596,7 +592,7 @@ static void add_token_bytestring(int *err, struct opal_dev *cmd, ...@@ -596,7 +592,7 @@ static void add_token_bytestring(int *err, struct opal_dev *cmd,
if (!can_add(err, cmd, header_len + len)) { if (!can_add(err, cmd, header_len + len)) {
pr_debug("Error adding bytestring: end of buffer.\n"); pr_debug("Error adding bytestring: end of buffer.\n");
return; return NULL;
} }
if (is_short_atom) if (is_short_atom)
...@@ -604,9 +600,19 @@ static void add_token_bytestring(int *err, struct opal_dev *cmd, ...@@ -604,9 +600,19 @@ static void add_token_bytestring(int *err, struct opal_dev *cmd,
else else
add_medium_atom_header(cmd, true, false, len); add_medium_atom_header(cmd, true, false, len);
memcpy(&cmd->cmd[cmd->pos], bytestring, len); return &cmd->cmd[cmd->pos];
cmd->pos += len; }
static void add_token_bytestring(int *err, struct opal_dev *cmd,
const u8 *bytestring, size_t len)
{
u8 *start;
start = add_bytestring_header(err, cmd, len);
if (!start)
return;
memcpy(start, bytestring, len);
cmd->pos += len;
} }
static int build_locking_range(u8 *buffer, size_t length, u8 lr) static int build_locking_range(u8 *buffer, size_t length, u8 lr)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment