Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932245AbbFIJTo (ORCPT ); Tue, 9 Jun 2015 05:19:44 -0400 Received: from mga02.intel.com ([134.134.136.20]:1340 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752228AbbFIJTf (ORCPT ); Tue, 9 Jun 2015 05:19:35 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,579,1427785200"; d="scan'208";a="739991969" Date: Tue, 9 Jun 2015 12:19:32 +0300 From: Jarkko Sakkinen To: Peter =?iso-8859-1?Q?H=FCwe?= Cc: jgunthorpe@obsidianresearch.com, safford@us.ibm.com, Marcel Selhorst , "moderated list:TPM DEVICE DRIVER" , open list Subject: Re: [PATCH v2] tpm: introduce struct tpm_buf Message-ID: <20150609091932.GC4968@jsakkine-mobl1> References: <1433349555-30868-1-git-send-email-jarkko.sakkinen@linux.intel.com> <201506082239.33639.PeterHuewe@gmx.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <201506082239.33639.PeterHuewe@gmx.de> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1920 Lines: 58 On Mon, Jun 08, 2015 at 10:39:32PM +0200, Peter H?we wrote: > Hi, > > > Am Mittwoch, 3. Juni 2015, 18:39:14 schrieb Jarkko Sakkinen: > > This patch introduces struct tpm_buf that provides a string buffer for > > constructing TPM commands. This allows to construct variable sized TPM > > commands. This feature is needed for TPM 2.0 commands in order to allow > > policy authentication and algorithmic agility. > > > > The commands in the tpm2-cmd.c have been updated to use struct tpm_buf. > > Lots of awkward length calculations could be dropped because the buffer > > knows its length. > > > > The code is is along the lines of the string buffer code in > > security/trusted/trusted.h. > > > > Changes since v1: > > > > - Fixed potential alignment issues in tpm_buf_tag(). > > > > Signed-off-by: Jarkko Sakkinen > > > +static inline void tpm_buf_append(struct tpm_buf *buf, > > + const unsigned char *data, > > + unsigned int len) > > +{ > > + struct tpm_input_header *head = (struct tpm_input_header *) buf->data; > > + > > + BUG_ON((len + tpm_buf_length(buf)) > TPM_BUF_SIZE); > > + > > + memcpy(&buf->data[tpm_buf_length(buf)], data, len); > > + head->length = cpu_to_be32(tpm_buf_length(buf) + len); > > +} > > + > > +static inline void tpm_buf_store(struct tpm_buf *buf, > > + unsigned int pos, > > + const unsigned char *data, > > + unsigned int len) > > +{ > > + BUG_ON((pos + len) > TPM_BUF_SIZE); > > + > > + memcpy(&buf->data[pos], data, len); > > +} > > Don't you have to update the ->length here? No. Store is for placing value in position, not appending to the end. > Thanks, > Peter /Jarkko -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/