Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp996055imj; Thu, 7 Feb 2019 15:37:35 -0800 (PST) X-Google-Smtp-Source: AHgI3IaqDyfiHk393jNnKq9uh5sqoCm+ppQe9yPQ3QofBmISOymr/uAKMsJq6RvQErdWB1LLNUXX X-Received: by 2002:a62:5c1:: with SMTP id 184mr18731231pff.165.1549582655591; Thu, 07 Feb 2019 15:37:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549582655; cv=none; d=google.com; s=arc-20160816; b=fhphBoTthZIIfuTf1B1WfxtE4Dcse/eHGgN331WauzSuvIN/1LBpmYAHaLWnrWZRr/ eXSn4+QTgN9N0WePR/ZbQ/C7uyYy+G6ai4Aa5aheZAoEKwEWVJvaV5b5/LgUVd2xyCdJ QaYuebxAxu7IgMSpxOhunkXe9M0oCmM2/ed0d9ckOMIV+zI0j9iG/81Cg+QY7+6FeY3x 1PXNw9sXQWFMmAACeZt2ZQFIylw2EvYnz5uOYSJFr0I9vOCIqAZA++BTYpBpdliXs4T2 A5mStzOWcVwnhuioN1LVgVD74P4pWx4Zk7I6EtO9j/1zFjgG//a9kT/0bXEtUIF5G2vx Ucng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :from:references:cc:to:subject; bh=+Yrj5CtgJCyYnGTePEf/JKFlUAr3m2VK/v3go6LKUks=; b=QbQFdKmXkZ851Z7zQQ0onjxXfxSKUis/zwX7hgyJYmbiB8p/qmFNm/g5tY+KvW33qr SFhYvD9p8ZrRHxpDt9A2TqlHiq3GGLWwv18KTiNdjuZ0oVyzGyd4+eJqGi0yFirY1MNv gjki/fNbg5dYv26ATm9KcZ65872h8BrmvsBn8aTkckH5CJSSCNLIgwBJ1Q0B1iWKCjXM ZalxiCbBfwvTVxH4IEDXsGftsITrXKSryNhNqszkNxVcgQaxRkJS7uXfpo3LyQPgp+lZ RUl8mGN4pyuGLvfWR0kyDyzP/94jnSwc8BKlDJreczIN3KxKOkiBlbA4jVuyUdZH0JZ/ VmkA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f9si373749plb.415.2019.02.07.15.37.20; Thu, 07 Feb 2019 15:37:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726905AbfBGXhH (ORCPT + 99 others); Thu, 7 Feb 2019 18:37:07 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:39298 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726401AbfBGXhH (ORCPT ); Thu, 7 Feb 2019 18:37:07 -0500 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x17NSphq126110 for ; Thu, 7 Feb 2019 18:37:06 -0500 Received: from e35.co.us.ibm.com (e35.co.us.ibm.com [32.97.110.153]) by mx0a-001b2d01.pphosted.com with ESMTP id 2qgvekn2w9-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 07 Feb 2019 18:37:05 -0500 Received: from localhost by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 7 Feb 2019 23:37:05 -0000 Received: from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16) by e35.co.us.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 7 Feb 2019 23:37:01 -0000 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x17Nb00B28246100 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Feb 2019 23:37:00 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BE5B77805E; Thu, 7 Feb 2019 23:37:00 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7D5627805F; Thu, 7 Feb 2019 23:36:59 +0000 (GMT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Thu, 7 Feb 2019 23:36:59 +0000 (GMT) Subject: Re: [PATCH v11 08/16] tpm: clean up tpm_try_transmit() error handling flow To: Jarkko Sakkinen , linux-integrity@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, Peter Huewe , Jason Gunthorpe , Tomas Winkler , Tadeusz Struk , Stefan Berger , Nayna Jain References: <20190205224723.19671-1-jarkko.sakkinen@linux.intel.com> <20190205224723.19671-9-jarkko.sakkinen@linux.intel.com> From: Stefan Berger Date: Thu, 7 Feb 2019 18:36:59 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 In-Reply-To: <20190205224723.19671-9-jarkko.sakkinen@linux.intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-MW X-TM-AS-GCONF: 00 x-cbid: 19020723-0012-0000-0000-00001706CB6A X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010556; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000279; SDB=6.01157811; UDB=6.00604070; IPR=6.00938342; MB=3.00025484; MTD=3.00000008; XFM=3.00000015; UTC=2019-02-07 23:37:03 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19020723-0013-0000-0000-0000561E826A Message-Id: <5203f941-9516-0e91-7dc7-d5b9892c82ec@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-02-07_15:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902070168 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/5/19 5:47 PM, Jarkko Sakkinen wrote: > Move locking, locality handling and power management to tpm_transmit() > in order to simplify the flow. > > Signed-off-by: Jarkko Sakkinen > Reviewed-by: Stefan Berger > Tested-by: Stefan Berger > Reviewed-by: Jerry Snitselaar > Reviewed-by: James Bottomley > --- > drivers/char/tpm/tpm-interface.c | 94 +++++++++++++++----------------- > drivers/char/tpm/tpm.h | 1 + > drivers/char/tpm/tpm2-space.c | 2 +- > 3 files changed, 45 insertions(+), 52 deletions(-) > > diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c > index c28ffef92f1a..f5f5224f68b0 100644 > --- a/drivers/char/tpm/tpm-interface.c > +++ b/drivers/char/tpm/tpm-interface.c > @@ -167,7 +167,6 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip, struct tpm_space *space, > ssize_t len = 0; > u32 count, ordinal; > unsigned long stop; > - bool need_locality; > > rc = tpm_validate_command(chip, space, buf, bufsiz); > if (rc == -EINVAL) > @@ -197,37 +196,16 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip, struct tpm_space *space, > return -E2BIG; > } > > - if (!(flags & TPM_TRANSMIT_UNLOCKED) && !(flags & TPM_TRANSMIT_NESTED)) > - mutex_lock(&chip->tpm_mutex); > - > - if (chip->ops->clk_enable != NULL) > - chip->ops->clk_enable(chip, true); > - > - /* Store the decision as chip->locality will be changed. */ > - need_locality = chip->locality == -1; > - > - if (need_locality) { > - rc = tpm_request_locality(chip, flags); > - if (rc < 0) { > - need_locality = false; > - goto out_locality; > - } > - } > - > - rc = tpm_cmd_ready(chip, flags); > - if (rc) > - goto out_locality; > - > rc = tpm2_prepare_space(chip, space, ordinal, buf); > if (rc) > - goto out; > + return rc; > > rc = chip->ops->send(chip, buf, count); > if (rc < 0) { > if (rc != -EPIPE) > dev_err(&chip->dev, > "%s: tpm_send: error %d\n", __func__, rc); > - goto out; > + goto out_rc; > } > > if (chip->flags & TPM_CHIP_FLAG_IRQ) > @@ -243,7 +221,7 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip, struct tpm_space *space, > if (chip->ops->req_canceled(chip, status)) { > dev_err(&chip->dev, "Operation Canceled\n"); > rc = -ECANCELED; > - goto out; > + goto out_rc; > } > > tpm_msleep(TPM_TIMEOUT_POLL); > @@ -253,40 +231,20 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip, struct tpm_space *space, > chip->ops->cancel(chip); > dev_err(&chip->dev, "Operation Timed out\n"); > rc = -ETIME; > - goto out; > + goto out_rc; > > out_recv: > len = chip->ops->recv(chip, buf, bufsiz); > if (len < 0) { > rc = len; > - dev_err(&chip->dev, > - "tpm_transmit: tpm_recv: error %d\n", rc); > - goto out; > - } else if (len < TPM_HEADER_SIZE) { > + dev_err(&chip->dev, "tpm_transmit: tpm_recv: error %d\n", rc); > + } else if (len < TPM_HEADER_SIZE || len != be32_to_cpu(header->length)) > rc = -EFAULT; > - goto out; > - } Add an else branch here for 'rc = 0' because it is otherwise set from 'rc = chip->ops->send(chip, buf, count);'. Or add it further above...