From patchwork Mon Oct 16 17:34:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 10009431 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 B4EFE601D5 for ; Mon, 16 Oct 2017 17:35:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A37932865F for ; Mon, 16 Oct 2017 17:35:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9683628689; Mon, 16 Oct 2017 17:35:30 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 54C742865F for ; Mon, 16 Oct 2017 17:35:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755335AbdJPRfR (ORCPT ); Mon, 16 Oct 2017 13:35:17 -0400 Received: from mout.web.de ([212.227.17.12]:64704 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754274AbdJPRfQ (ORCPT ); Mon, 16 Oct 2017 13:35:16 -0400 Received: from [192.168.1.2] ([78.49.107.148]) by smtp.web.de (mrweb101 [213.165.67.124]) with ESMTPSA (Nemesis) id 0Meje0-1dt5as2pyK-00OFgw; Mon, 16 Oct 2017 19:34:58 +0200 Subject: [PATCH 4/4] char/tpm: Less checks in tpm_ibmvtpm_probe() after error detection From: SF Markus Elfring To: linux-integrity@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Andy Shevchenko , Benjamin Herrenschmidt , Corentin Labbe , Jarkko Sakkinen , Jason Gunthorpe , Jerry Snitselaar , Kenneth Goldman , Michael Ellerman , Nayna Jain , Paul Mackerras , =?UTF-8?Q?Peter_H=c3=bcwe?= , Stefan Berger Cc: LKML , kernel-janitors@vger.kernel.org References: <1d3516a2-a8e6-9e95-d438-f115fac84c7f@users.sourceforge.net> Message-ID: <09a2c3a1-1b10-507d-a866-258b570f6da1@users.sourceforge.net> Date: Mon, 16 Oct 2017 19:34:56 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <1d3516a2-a8e6-9e95-d438-f115fac84c7f@users.sourceforge.net> Content-Language: en-GB X-Provags-ID: V03:K0:3+5IEMjvrBHtXW03pFAr9fNZebdZMgZ946p4x2sj3eYx+R7EYao /wizqobuqRjy5/ZbHALgNbp2CayRWqBpqY11qx+bXTNxwDs6QbagRIYGB2F8pOVkhDr1Wle HqH1eUUbHDVYitsOA6rB+2FAGNXcMaTQfJK0xUPj76nucaDrVOQOpOsEAQfz1gjE+K/fuSf 2Y5sEchph+NPGi9FOAG1A== X-UI-Out-Filterresults: notjunk:1; V01:K0:RyKmwl4/Sgg=:mgsJJeIiVhsWwGRl6l4y2o An2BObe1CVUAoxo4yZOnBSNf483VxnJkPsZ5wRgyGo96KeYHelayeAtPPEYqgHtLZQgV0zD0d Socf1kGXtR5xyaIUx+j73cFEOpImZLp6ZMA53yPQSRcrnzHYo4PZbm6iaWK1Pe9PYxHGGxgnc 96h+fpHolEOpDHBMr+g+4XI/TWNEmRGjXRTb2yaW/JvcHtU0BbjTUZ6dfmpJnzfN8i4wk24+a J4opjw4PBJMox5XkcCgYww5HnLeEOL4ULlVjbnS0jMXLM8V7rRobCYJs1wDqj4WkNcCeQWPxM I/wtifX/tEae75zfLinbp1Cu1uqgz1MLdBxHSxdT3nqZ49+15Vs/xZQwwPAMv8bUAQltVUNeA Ut+Y4I5geDrVIQEmo035t2XuHcIikFWpR76WGfPrrcTfbbezIgSQ1OSzlbEUpofqCS6sU3dgo E5fEEEv46HdXgm6G1chB4yoKFL0t33IS8nBVbOJ1r1HxlPG7TTNQy21WII1IO3BakzX8oESa7 WD/vjp5gVHx1a3zZijkmadi4WlsRlQ6/15qZ6oz3QbCHSJ2oOm2U5I8Ucc7E/kJoz1ZKeScvL okKeFUrI9e45fV6kknJeCSYPTF8xl+jXjV1U4fn938WTZB+alfBpPOw7gH7rXeuYBpfNFrm2S 5WC1JNILZHxHcs7JEPaU+9eOGrRqJ9p3adylRhGBCTgDEVidHtiOIcVXABiPiEwBdu7uLjkKa Gfg7nD8BgPfi/ceWnm9BjY9VetUAeHMtkGj3GjFnUq+exDwmqo9MrQXMez3qcMPrQEO23CyvM LsXwBfQaPWgnf5vKuFFwF4anwrtbalmFNGcWSfopGUKtWYC2es= Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Mon, 16 Oct 2017 19:00:34 +0200 Two pointer checks could be repeated by the tpm_ibmvtpm_probe() function during error handling even if the relevant properties can be determined for the involved variables before by source code analysis. * Return directly after a call of the function "kzalloc" failed at the beginning. * Adjust jump targets so that extra checks can be omitted at the end. Signed-off-by: Markus Elfring --- drivers/char/tpm/tpm_ibmvtpm.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/drivers/char/tpm/tpm_ibmvtpm.c b/drivers/char/tpm/tpm_ibmvtpm.c index a4b462a77b99..b8dda7546f64 100644 --- a/drivers/char/tpm/tpm_ibmvtpm.c +++ b/drivers/char/tpm/tpm_ibmvtpm.c @@ -610,7 +610,7 @@ static int tpm_ibmvtpm_probe(struct vio_dev *vio_dev, ibmvtpm = kzalloc(sizeof(*ibmvtpm), GFP_KERNEL); if (!ibmvtpm) - goto cleanup; + return -ENOMEM; ibmvtpm->dev = dev; ibmvtpm->vdev = vio_dev; @@ -619,7 +619,7 @@ static int tpm_ibmvtpm_probe(struct vio_dev *vio_dev, crq_q->crq_addr = (struct ibmvtpm_crq *)get_zeroed_page(GFP_KERNEL); if (!crq_q->crq_addr) { dev_err(dev, "Unable to allocate memory for crq_addr\n"); - goto cleanup; + goto free_tpm; } crq_q->num_entry = CRQ_RES_BUF_SIZE / sizeof(*crq_q->crq_addr); @@ -629,7 +629,7 @@ static int tpm_ibmvtpm_probe(struct vio_dev *vio_dev, if (dma_mapping_error(dev, ibmvtpm->crq_dma_handle)) { dev_err(dev, "dma mapping failed\n"); - goto cleanup; + goto free_page; } rc = plpar_hcall_norets(H_REG_CRQ, vio_dev->unit_address, @@ -683,13 +683,10 @@ static int tpm_ibmvtpm_probe(struct vio_dev *vio_dev, reg_crq_cleanup: dma_unmap_single(dev, ibmvtpm->crq_dma_handle, CRQ_RES_BUF_SIZE, DMA_BIDIRECTIONAL); -cleanup: - if (ibmvtpm) { - if (crq_q->crq_addr) - free_page((unsigned long)crq_q->crq_addr); - kfree(ibmvtpm); - } - +free_page: + free_page((unsigned long)crq_q->crq_addr); +free_tpm: + kfree(ibmvtpm); return rc; }