tpmdd-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: Colin King <colin.king@canonical.com>
To: Peter Huewe <peterhuewe@gmx.de>,
	Marcel Selhorst <tpmdd@selhorst.net>,
	Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
	Jason Gunthorpe <jgunthorpe@obsidianresearch.com>,
	tpmdd-devel@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] tpm: return -ENODEV if np is not set
Date: Tue, 15 Nov 2016 13:27:22 +0000	[thread overview]
Message-ID: <20161115132722.6963-1-colin.king@canonical.com> (raw)

From: Colin Ian King <colin.king@canonical.com>

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 <colin.king@canonical.com>
---
 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

             reply	other threads:[~2016-11-15 13:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-15 13:27 Colin King [this message]
     [not found] ` <20161115132722.6963-1-colin.king-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
2016-11-15 17:33   ` [PATCH] tpm: return -ENODEV if np is not set Jarkko Sakkinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161115132722.6963-1-colin.king@canonical.com \
    --to=colin.king@canonical.com \
    --cc=jarkko.sakkinen@linux.intel.com \
    --cc=jgunthorpe@obsidianresearch.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterhuewe@gmx.de \
    --cc=tpmdd-devel@lists.sourceforge.net \
    --cc=tpmdd@selhorst.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).