Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp5197311imm; Tue, 16 Oct 2018 06:43:47 -0700 (PDT) X-Google-Smtp-Source: ACcGV60Xw81Pv8DsfJcd1kK3xS/q2SHRLfCVyu6qoKRm8iwkWj8nobCHCZbmq1qshKxhPoD/oCwF X-Received: by 2002:a63:f448:: with SMTP id p8-v6mr20180676pgk.124.1539697427082; Tue, 16 Oct 2018 06:43:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539697427; cv=none; d=google.com; s=arc-20160816; b=r5mR8/FwSYyk4dXMKudMDHn2R6/pMjstRHvtskTEhfXZEUOlMYQRMGMTxyIN7ECJV3 o/bRGLRBX/y1JltFs7T8Jh0xvRaMy7sUOVsPS+mq6XX6xLQ6/teddcPsEqYc6uo01hER HrdJbZPiqOQqyKbXbS7x0oyFMdfdaWTyyfOd3cyBGE6N1GUoj4H0vivYnqLlC+jIcZTc NAk4Q/fujcOha3Kdz/I3pYQYDjqw7A2Ae0cp5xUUbt3ZuyQLrlZFdvrq2bJHH0HiXrVq f+oocMKK2q3SD5sZX/naAFyj4v5CsQ1E1CJmsXFX/cX7L2u8MAXEIU56phtj+X5e8T9N 8Txg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=CY4/4kpWMs4FCil/VGrtBrtMBJ/sGRJpxXeH4bV3EZY=; b=EsKeW2ctfLrQB/3gZg3+MGxF/zgquEsVbUFCPLOydxFRHUHMHDg10/dbhl9gCoYdtL 4fDeGnzlmx9oyxyGZJhiqGKZRWYLd+6+U2gLD1pQr4JuQsGjCmUC5Z80eF1YEENF5LxF 5kUrIIrclz2CGq8V6Zd8KNMemX+th+gpyN/Ups7N5yJkBVbC7A8RgvT9f4/w1gu8J+CE rHjYxWO8SwaDya4gFmkZGz7WO9W1yNIy0gVThUCGuwRzsLPL8QUH3NfK8SfsP+TDHg8f VF9p+asi74gnsvqqfBzS5WEOlK3sr73pwF+64TSqEURYVmh5oTVTvgp689g6hFJOZq7K JX8Q== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c21-v6si13627983pgg.407.2018.10.16.06.43.31; Tue, 16 Oct 2018 06:43:47 -0700 (PDT) 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727214AbeJPVb7 (ORCPT + 99 others); Tue, 16 Oct 2018 17:31:59 -0400 Received: from mga11.intel.com ([192.55.52.93]:28953 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727002AbeJPVb7 (ORCPT ); Tue, 16 Oct 2018 17:31:59 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Oct 2018 06:41:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,388,1534834800"; d="scan'208";a="92433279" Received: from twinkler-lnx.jer.intel.com ([10.12.91.48]) by orsmga003.jf.intel.com with ESMTP; 16 Oct 2018 06:41:15 -0700 From: Tomas Winkler To: Jarkko Sakkinen , Jason Gunthorpe Cc: Nayna Jain , Alexander Usyskin , Tadeusz Struk , linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Tomas Winkler , stable@vger.kernel.org Subject: [PATCH] tpm: tpm_try_transmit() refactor error flow. Date: Tue, 16 Oct 2018 16:37:16 +0300 Message-Id: <20181016133716.17842-1-tomas.winkler@intel.com> X-Mailer: git-send-email 2.14.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org First, rename out_no_locality to out_locality for bailing out on both tpm_cmd_ready() and tpm_request_locality() failure. Second, ignore the return value of go_to_idle() as it may override the return value of the actual tpm operation, the go_to_idle() error will be caught on any consequent command. Last, fix the wrong 'goto out', that jumped back instead of forward. Cc: stable@vger.kernel.org Fixes: 627448e85c76 ("tpm: separate cmd_ready/go_idle from runtime_pm") Signed-off-by: Tomas Winkler --- drivers/char/tpm/tpm-interface.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c index 129f640424b7..95db630dd722 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -477,13 +477,15 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip, if (need_locality) { rc = tpm_request_locality(chip, flags); - if (rc < 0) - goto out_no_locality; + if (rc < 0) { + need_locality = false; + goto out_locality; + } } rc = tpm_cmd_ready(chip, flags); if (rc) - goto out; + goto out_locality; rc = tpm2_prepare_space(chip, space, ordinal, buf); if (rc) @@ -547,14 +549,13 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip, dev_err(&chip->dev, "tpm2_commit_space: error %d\n", rc); out: - rc = tpm_go_idle(chip, flags); - if (rc) - goto out; + /* may fail but do not override previous error value in rc */ + tpm_go_idle(chip, flags); +out_locality: if (need_locality) tpm_relinquish_locality(chip, flags); -out_no_locality: if (chip->ops->clk_enable != NULL) chip->ops->clk_enable(chip, false); -- 2.14.4