Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934268AbcKWTjl (ORCPT ); Wed, 23 Nov 2016 14:39:41 -0500 Received: from quartz.orcorp.ca ([184.70.90.242]:43295 "EHLO quartz.orcorp.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933363AbcKWTjj (ORCPT ); Wed, 23 Nov 2016 14:39:39 -0500 Date: Wed, 23 Nov 2016 12:37:00 -0700 From: Jason Gunthorpe To: Nayna Jain Cc: tpmdd-devel@lists.sourceforge.net, peterhuewe@gmx.de, tpmdd@selhorst.net, jarkko.sakkinen@linux.intel.com, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 2/3] tpm: enhance read_log_of() to support Physical TPM event log Message-ID: <20161123193700.GA13927@obsidianresearch.com> References: <1479922057-8752-1-git-send-email-nayna@linux.vnet.ibm.com> <1479922057-8752-3-git-send-email-nayna@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1479922057-8752-3-git-send-email-nayna@linux.vnet.ibm.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Broken-Reverse-DNS: no host name found for IP address 10.0.0.151 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1352 Lines: 44 On Wed, Nov 23, 2016 at 12:27:36PM -0500, Nayna Jain wrote: > sizep = of_get_property(np, "linux,sml-size", NULL); > + if (of_property_match_string(np, "compatible", "IBM,vtpm") < 0) > + log_size = be32_to_cpup(sizep); > + else > + log_size = *sizep; > + Uh, no, sizep can be null at this point: > basep = of_get_property(np, "linux,sml-base", NULL); > if (sizep == NULL && basep == NULL) > return -ENODEV; > if (sizep == NULL || basep == NULL) > return -EIO; Move the if here. > - if (*sizep == 0) { > + if (log_size == 0) { > dev_warn(&chip->dev, "%s: Event log area empty\n", __func__); > return -EIO; > } > > - log->bios_event_log = kmalloc(*sizep, GFP_KERNEL); > + log->bios_event_log = kmalloc(log_size, GFP_KERNEL); > if (!log->bios_event_log) > return -ENOMEM; > > - log->bios_event_log_end = log->bios_event_log + *sizep; > + log->bios_event_log_end = log->bios_event_log + log_size; > > - memcpy(log->bios_event_log, __va(*basep), *sizep); > + if (of_property_match_string(np, "compatible", "IBM,vtpm") < 0) > + memcpy(chip->log.bios_event_log, __va(be64_to_cpup(basep)), > + log_size); > + else > + memcpy(chip->log.bios_event_log, __va(*basep), > log_size); And move the conditional swap of basep up to be along side sizep as well (ie get rid of the second of_property_match_string) Jason