From patchwork Thu Dec 21 23:13:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Azhar Shaikh X-Patchwork-Id: 10128521 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 6BAF06019C for ; Thu, 21 Dec 2017 23:13:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E34C27F7F for ; Thu, 21 Dec 2017 23:13:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 520D828699; Thu, 21 Dec 2017 23:13:43 +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=ham 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 B662327F7F for ; Thu, 21 Dec 2017 23:13:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755533AbdLUXNm (ORCPT ); Thu, 21 Dec 2017 18:13:42 -0500 Received: from mga14.intel.com ([192.55.52.115]:35242 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755507AbdLUXNk (ORCPT ); Thu, 21 Dec 2017 18:13:40 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Dec 2017 15:13:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,438,1508828400"; d="scan'208";a="18024958" Received: from otc-chromeosbuild-1.jf.intel.com ([10.54.30.145]) by orsmga001.jf.intel.com with ESMTP; 21 Dec 2017 15:13:39 -0800 From: Azhar Shaikh To: jarkko.sakkinen@linux.intel.com, jgg@ziepe.ca, javierm@redhat.com, peterhuewe@gmx.de Cc: linux-security-module@vger.kernel.org, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, azhar.shaikh@intel.com Subject: [PATCH v2] tpm: Fix the driver cleanup code Date: Thu, 21 Dec 2017 15:13:39 -0800 Message-Id: <1513898019-164487-1-git-send-email-azhar.shaikh@intel.com> X-Mailer: git-send-email 1.9.1 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 Commit 3c1701339284353c41 ("tpm: Keep CLKRUN enabled throughout the duration of transmit_cmd()") added code which accessed chip->ops, even after it was set to NULL in tpm_del_char_device(), called from tpm_chip_unregister() in error / driver exit paths. So fix this code. Fixes: 3c1701339284353c41 ("tpm: Keep CLKRUN enabled throughout the duration of transmit_cmd()") Suggested-by: Javier Martinez Canillas Suggested-by: Jason Gunthorpe Signed-off-by: Azhar Shaikh Reviewed-by: Jason Gunthorpe --- Changes in v2: - Remove TPM_CHIP_FLAG_DO_NOT_CLEAR_OPS flag, instead call tpm_tis_clkrun_enable() directly in tpm_tis_remove() - Add comment to tpm_tis_clkrun_enable() drivers/char/tpm/tpm_tis.c | 6 ------ drivers/char/tpm/tpm_tis_core.c | 29 +++++++++++++++++------------ 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c index d29add49b033..c847fc69a2fc 100644 --- a/drivers/char/tpm/tpm_tis.c +++ b/drivers/char/tpm/tpm_tis.c @@ -275,9 +275,6 @@ static void tpm_tis_pnp_remove(struct pnp_dev *dev) tpm_chip_unregister(chip); tpm_tis_remove(chip); - if (is_bsw()) - iounmap(priv->ilb_base_addr); - } static struct pnp_driver tis_pnp_driver = { @@ -329,9 +326,6 @@ static int tpm_tis_plat_remove(struct platform_device *pdev) tpm_chip_unregister(chip); tpm_tis_remove(chip); - if (is_bsw()) - iounmap(priv->ilb_base_addr); - return 0; } diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index c2227983ed88..519e4a78c8f8 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -37,6 +37,8 @@ */ #define TPM_POLL_SLEEP 1 /* msec */ +static void tpm_tis_clkrun_enable(struct tpm_chip *chip, bool value); + static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask, bool check_cancel, bool *canceled) { @@ -716,8 +718,7 @@ void tpm_tis_remove(struct tpm_chip *chip) u32 interrupt; int rc; - if (chip->ops->clk_enable != NULL) - chip->ops->clk_enable(chip, true); + tpm_tis_clkrun_enable(chip, true); rc = tpm_tis_read32(priv, reg, &interrupt); if (rc < 0) @@ -725,8 +726,10 @@ void tpm_tis_remove(struct tpm_chip *chip) tpm_tis_write32(priv, reg, ~TPM_GLOBAL_INT_ENABLE & interrupt); - if (chip->ops->clk_enable != NULL) - chip->ops->clk_enable(chip, false); + tpm_tis_clkrun_enable(chip, false); + + if (priv->ilb_base_addr) + iounmap(priv->ilb_base_addr); } EXPORT_SYMBOL_GPL(tpm_tis_remove); @@ -736,6 +739,9 @@ void tpm_tis_remove(struct tpm_chip *chip) * @chip: TPM chip to use * @value: 1 - Disable CLKRUN protocol, so that clocks are free running * 0 - Enable CLKRUN protocol + * + * Call this function directly in tpm_tis_remove() in error or driver removal + * path, since the chip->ops is set to NULL in tpm_chip_unregister(). */ static void tpm_tis_clkrun_enable(struct tpm_chip *chip, bool value) { @@ -922,21 +928,20 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, } rc = tpm_chip_register(chip); - if (rc && is_bsw()) - iounmap(priv->ilb_base_addr); + if (rc) + goto out_err; if (chip->ops->clk_enable != NULL) chip->ops->clk_enable(chip, false); - return rc; -out_err: - tpm_tis_remove(chip); - if (is_bsw()) - iounmap(priv->ilb_base_addr); + return 0; - if (chip->ops->clk_enable != NULL) +out_err: + if ((chip->ops != NULL) && (chip->ops->clk_enable != NULL)) chip->ops->clk_enable(chip, false); + tpm_tis_remove(chip); + return rc; } EXPORT_SYMBOL_GPL(tpm_tis_core_init);