From patchwork Tue May 30 22:05:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 9760919 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8FAFD60375 for ; Thu, 1 Jun 2017 19:20:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7EB48284F9 for ; Thu, 1 Jun 2017 19:20:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 73A4528504; Thu, 1 Jun 2017 19:20:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3573B28508 for ; Thu, 1 Jun 2017 19:20:02 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1dGVdZ-0003WZ-EW; Thu, 01 Jun 2017 19:20:01 +0000 Received: from sog-mx-3.v43.ch3.sourceforge.com ([172.29.43.193] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1dFq1x-0005Lh-GD for tpmdd-devel@lists.sourceforge.net; Tue, 30 May 2017 22:54:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:MIME-Version:Message-ID:Subject:Cc:To:From:Date; bh=LCS+2EBI0wVS3fSEGKTlx2nHy1vNV+Lhncy/NQphC6w=; b=M1PmUmt+MRkISDh06YOLQKohkM3iXw9sGfJFl1SUBtcZWTbBgyx2rGapPnk+0yv+ueqr6ZL2TT6SM521Jp3s8SzlPGdvEoIEeplKwQR+eJI9o3xt5FJV9+2+5xQ9pkgYDBeNOS93lMERMmx1nPgMn6Ecj80W5RROKJVdjnt+EM8=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x; h=Content-Type:MIME-Version:Message-ID:Subject:Cc:To:From:Date; bh=LCS+2EBI0wVS3fSEGKTlx2nHy1vNV+Lhncy/NQphC6w=; b=c7OYMIB1nFbGN8TXuY9EqnNwflT0bNa9lvAR4UA/iWoTLYXHQUjmaZkAwdnzKPZ1edypYUuthAQD6rIQVSbAXGzs9U1w2aQPY4zdYMpFb7vgx/BT8Ccjt/MmRsd4/bR0469Oi3kih+1WT+ktxSzKw/E+4h19CMX/hVmrheScC2c=; Received-SPF: pass (sog-mx-3.v43.ch3.sourceforge.com: domain of embeddedor.com designates 192.185.192.34 as permitted sender) client-ip=192.185.192.34; envelope-from=garsilva@embeddedor.com; helo=gateway30.websitewelcome.com; Received: from gateway30.websitewelcome.com ([192.185.192.34]) by sog-mx-3.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1dFq1w-0007pc-Ie for tpmdd-devel@lists.sourceforge.net; Tue, 30 May 2017 22:54:25 +0000 Received: from cm4.websitewelcome.com (unknown [108.167.139.16]) by gateway30.websitewelcome.com (Postfix) with ESMTP id D8A15543AB for ; Tue, 30 May 2017 17:05:22 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cm4.websitewelcome.com with id Sm5M1v01A0V9LXg01m5Nbk; Tue, 30 May 2017 17:05:22 -0500 Received: from [189.152.214.95] (port=59360 helo=embeddedgus) by gator4166.hostgator.com with esmtpa (Exim 4.87) (envelope-from ) id 1dFpGT-00086p-KC; Tue, 30 May 2017 17:05:21 -0500 Date: Tue, 30 May 2017 17:05:20 -0500 From: "Gustavo A. R. Silva" To: Peter Huewe , Marcel Selhorst , Jarkko Sakkinen , Jason Gunthorpe Message-ID: <20170530220520.GA8713@embeddedgus> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - lists.sourceforge.net X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 189.152.214.95 X-Exim-ID: 1dFpGT-00086p-KC X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedgus) [189.152.214.95]:59360 X-Source-Auth: garsilva@embeddedor.com X-Email-Count: 5 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Headers-End: 1dFq1w-0007pc-Ie X-Mailman-Approved-At: Thu, 01 Jun 2017 19:19:58 +0000 Subject: [tpmdd-devel] [PATCH] char: tpm: fix potential null pointer dereference X-BeenThere: tpmdd-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: Tpm Device Driver maintainance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tpmdd-devel@lists.sourceforge.net, "Gustavo A. R. Silva" , linux-kernel@vger.kernel.org Errors-To: tpmdd-devel-bounces@lists.sourceforge.net X-Virus-Scanned: ClamAV using ClamSMTP NULL check at line 376: if (!chip) {, implies chip might be NULL. Function dev_get_drvdata() dereference pointer chip. Move pointer tmp_dev assignment after the NULL check. Addresses-Coverity-ID: 1397648 Signed-off-by: Gustavo A. R. Silva --- drivers/char/tpm/st33zp24/st33zp24.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/char/tpm/st33zp24/st33zp24.c b/drivers/char/tpm/st33zp24/st33zp24.c index 4d1dc8b..f45e8c7 100644 --- a/drivers/char/tpm/st33zp24/st33zp24.c +++ b/drivers/char/tpm/st33zp24/st33zp24.c @@ -367,7 +367,7 @@ static irqreturn_t tpm_ioserirq_handler(int irq, void *dev_id) static int st33zp24_send(struct tpm_chip *chip, unsigned char *buf, size_t len) { - struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev); + struct st33zp24_dev *tpm_dev; u32 status, i, size, ordinal; int burstcnt = 0; int ret; @@ -382,6 +382,7 @@ static int st33zp24_send(struct tpm_chip *chip, unsigned char *buf, if (ret < 0) return ret; + tpm_dev = dev_get_drvdata(&chip->dev); status = st33zp24_status(chip); if ((status & TPM_STS_COMMAND_READY) == 0) { st33zp24_cancel(chip);