From: Jonas Rabenstein Date: Thu, 14 Feb 2019 00:16:02 +0000 (+0100) Subject: block: sed-opal: split generation of bytestring header and content X-Git-Tag: v5.4-rc1~945^2~103 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=285599590e2e1f067d56a5855244e95f6303b28f;p=platform%2Fkernel%2Flinux-rpi.git 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: Jonas Rabenstein Signed-off-by: David Kozub Reviewed-by: Scott Bauer Reviewed-by: Christoph Hellwig Reviewed-by: Jon Derrick Signed-off-by: Jens Axboe --- diff --git a/block/sed-opal.c b/block/sed-opal.c index 1f24620..ad66d1d 100644 --- a/block/sed-opal.c +++ b/block/sed-opal.c @@ -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)); } -static void add_token_bytestring(int *err, struct opal_dev *cmd, - const u8 *bytestring, size_t len) +static u8 *add_bytestring_header(int *err, struct opal_dev *cmd, size_t len) { size_t header_len = 1; bool is_short_atom = true; - if (*err) - return; - if (len & ~SHORT_ATOM_LEN_MASK) { header_len = 2; is_short_atom = false; @@ -596,7 +592,7 @@ static void add_token_bytestring(int *err, struct opal_dev *cmd, if (!can_add(err, cmd, header_len + len)) { pr_debug("Error adding bytestring: end of buffer.\n"); - return; + return NULL; } if (is_short_atom) @@ -604,9 +600,19 @@ static void add_token_bytestring(int *err, struct opal_dev *cmd, else add_medium_atom_header(cmd, true, false, len); - memcpy(&cmd->cmd[cmd->pos], bytestring, len); - cmd->pos += len; + return &cmd->cmd[cmd->pos]; +} +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)