From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754154AbcKORdz (ORCPT ); Tue, 15 Nov 2016 12:33:55 -0500 Received: from mga07.intel.com ([134.134.136.100]:39845 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752270AbcKORdx (ORCPT ); Tue, 15 Nov 2016 12:33:53 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,495,1473145200"; d="scan'208";a="1085594446" Date: Tue, 15 Nov 2016 09:33:53 -0800 From: Jarkko Sakkinen To: Colin King Cc: Peter Huewe , Marcel Selhorst , Jason Gunthorpe , tpmdd-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: Re: [PATCH] tpm: return -ENODEV if np is not set Message-ID: <20161115173353.cnslmlqvwsp73wt3@intel.com> References: <20161115132722.6963-1-colin.king@canonical.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20161115132722.6963-1-colin.king@canonical.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.6.2-neo (2016-08-21) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 15, 2016 at 01:27:22PM +0000, Colin King wrote: > From: Colin Ian King > > device_node np contains a garbage value from the stack and it > is only set if chip->dev.parent->of_node is not null. Thus the > check for a null np won't spot a garbage value of np from the > stack if chip->dev.parent->of_node is null and if np contains > an garbage non-null value. > > I believe the correct fix is to return -ENODEV if and only if > chip->dev.parent->of_node is null. > > Found with static analysis by CoverityScan, CID 1377755 > > Signed-off-by: Colin Ian King Reviewed-by: Jarkko Sakkinen /Jarkko > --- > drivers/char/tpm/tpm_of.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/char/tpm/tpm_of.c b/drivers/char/tpm/tpm_of.c > index 3af829f..1426590 100644 > --- a/drivers/char/tpm/tpm_of.c > +++ b/drivers/char/tpm/tpm_of.c > @@ -31,7 +31,7 @@ int read_log_of(struct tpm_chip *chip) > log = &chip->log; > if (chip->dev.parent->of_node) > np = chip->dev.parent->of_node; > - if (!np) > + else > return -ENODEV; > > sizep = of_get_property(np, "linux,sml-size", NULL); > -- > 2.10.2 >