Received: by 10.213.65.68 with SMTP id h4csp18595imn; Mon, 19 Mar 2018 18:05:08 -0700 (PDT) X-Google-Smtp-Source: AG47ELt0ERT29f0ZeyBmfgy8IokIQUTGPyBS9XsvaPpRzgPbekySAPFzpR33imOAFdmMKtgR5+QV X-Received: by 10.99.97.130 with SMTP id v124mr10546244pgb.351.1521507908212; Mon, 19 Mar 2018 18:05:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521507908; cv=none; d=google.com; s=arc-20160816; b=yBz0TObpWxQ/kduaDpz4KZW+QuozYiqGEk/RPVXdO9tWBuKBe9A0OCTWu+UJyboJXe DbzpOS9PF0e4rM7IEi1UteHRvoVTpzYZ49UlwVcXU3gitQJHbYe+i8DHXrrKYGkJ2ho+ u0AjROZmvhTcVHKeOQv/b17MirYbK09XVL6GjPDjitk35AwOLUhzqiR23UGsV10q9qmm 2prJdXlo/cIVV27Sf61BUHYIeQEONnwQrdIFA2ysB0P5Cic7l/0in128xxWU/AlOS3ql o+HlBaJV1Sr3ycSe0ohhzJFNBuuNuZU7fwLu5hGhR15dxGbqrCHWDQ//TfR4tVSVtLjJ n6vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=anEyk1Mtr2MA/mTKpMzFVWNUgVegd127h3RWgVVlR4c=; b=GS/FHcBDkZ49JvMTo8Lqj1Duyt5AI/aWwjfmx1GrNRwhjDr6Hni8QlYSfQVMAj2ibm srKDgJf4OgdoKA1KQqiYBc4nXZNqaosP9kUjAu4K9p2bAJu0GeyATD1AcaJDSJWJYowO GQGXCOIewX3CE21xEmqrVCSdOBrNj62V1hmdl0vYqUVIDn/OhnBj585io5hmpwBT2Ecx Kx4Oa3UR8KoHWErAPvPghgSDLV5PsosPihE/bjNHIoUYNDNY6Za0Gtz9tNiOkkJF/APB avZoHETBfaZrg6mK3JNNmYHqBjXfvh9XWcN7FltRt87QPWbGwIcPC345O8Z93njPg0rx JIhw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f62-v6si418741plb.313.2018.03.19.18.04.54; Mon, 19 Mar 2018 18:05:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S970500AbeCSSiK (ORCPT + 99 others); Mon, 19 Mar 2018 14:38:10 -0400 Received: from mx-rz-2.rrze.uni-erlangen.de ([131.188.11.21]:51359 "EHLO mx-rz-2.rrze.uni-erlangen.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032127AbeCSSiB (ORCPT ); Mon, 19 Mar 2018 14:38:01 -0400 Received: from mx-rz-2.rrze.uni-erlangen.de (mx-rz-2.rrze.uni-erlangen.de [IPv6:2001:638:a000:1025::15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx-rz-2.rrze.uni-erlangen.de (Postfix) with ESMTPS id 404lDk2mYwzPjpJ; Mon, 19 Mar 2018 19:37:58 +0100 (CET) Authentication-Results: mx-rz-2.rrze.uni-erlangen.de; dkim=none reason="no signature"; dkim-adsp=none (unprotected policy); dkim-atps=neutral X-Quarantine-ID: X-Virus-Scanned: amavisd-new at boeck2.rrze.uni-erlangen.de (RRZE) X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-RRZE-Flag: Not-Spam X-RRZE-Submit-IP: 2003:d5:3db:1800:60b5:55d8:d757:229 Received: from fau.de (p200300D503DB180060B555D8D7570229.dip0.t-ipconnect.de [IPv6:2003:d5:3db:1800:60b5:55d8:d757:229]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: U2FsdGVkX18zT4xKt/m7oWrY0jzzM58FpafSYqYCFYc=) by smtp-auth.uni-erlangen.de (Postfix) with ESMTPSA id 404lDg0PHkzPk7s; Mon, 19 Mar 2018 19:37:55 +0100 (CET) From: Jonas Rabenstein To: Jonas Rabenstein , Scott Bauer , Jonathan Derrick , Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Christoph Hellwig Subject: [PATCH v2 06/11] block: sed-opal: split generation of bytestring header and content Date: Mon, 19 Mar 2018 19:36:48 +0100 Message-Id: <0f5fe62576e70de12515e323ca5c0a45ef92832d.1521482296.git.jonas.rabenstein@studium.uni-erlangen.de> X-Mailer: git-send-email 2.16.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 diff --git a/block/sed-opal.c b/block/sed-opal.c index 9b6f14e7aeb1..fc10f81d4892 100644 --- a/block/sed-opal.c +++ b/block/sed-opal.c @@ -581,14 +581,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; + char *start; if (len & ~SHORT_ATOM_LEN_MASK) { header_len = 2; @@ -597,17 +594,27 @@ 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) add_short_atom_header(cmd, true, false, len); else add_medium_atom_header(cmd, true, false, len); - - memcpy(&cmd->cmd[cmd->pos], bytestring, len); + start = &cmd->cmd[cmd->pos]; cmd->pos += len; + return start; +} +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); } static int build_locking_range(u8 *buffer, size_t length, u8 lr) -- 2.16.1