From patchwork Sun Oct 2 07:39:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Winkler, Tomas" X-Patchwork-Id: 9359567 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 E7BDC60459 for ; Sun, 2 Oct 2016 07:41:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BBE5928BD5 for ; Sun, 2 Oct 2016 07:41:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ACBB128C4D; Sun, 2 Oct 2016 07:41: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 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 47D3B28BD5 for ; Sun, 2 Oct 2016 07:41:42 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1bqbP1-0005QZ-Tr; Sun, 02 Oct 2016 07:41:39 +0000 Received: from sog-mx-4.v43.ch3.sourceforge.com ([172.29.43.194] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1bqbP0-0005QT-66 for tpmdd-devel@lists.sourceforge.net; Sun, 02 Oct 2016 07:41:38 +0000 Received-SPF: pass (sog-mx-4.v43.ch3.sourceforge.com: domain of intel.com designates 192.55.52.93 as permitted sender) client-ip=192.55.52.93; envelope-from=tomas.winkler@intel.com; helo=mga11.intel.com; Received: from mga11.intel.com ([192.55.52.93]) by sog-mx-4.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1bqbOz-0007Os-89 for tpmdd-devel@lists.sourceforge.net; Sun, 02 Oct 2016 07:41:38 +0000 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP; 02 Oct 2016 00:41:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.31,431,1473145200"; d="scan'208"; a="1039255443" Received: from twinkler-lnx.jer.intel.com ([10.12.87.167]) by orsmga001.jf.intel.com with ESMTP; 02 Oct 2016 00:41:28 -0700 From: Tomas Winkler To: tpmdd-devel@lists.sourceforge.net, Jason Gunthorpe , Jarkko Sakkinen Date: Sun, 2 Oct 2016 10:39:31 +0300 Message-Id: <1475393971-12715-1-git-send-email-tomas.winkler@intel.com> X-Mailer: git-send-email 2.7.4 X-Headers-End: 1bqbOz-0007Os-89 Cc: linux-kernel@vger.kernel.org Subject: [tpmdd-devel] [PATCH] tpm: don't destroy chip device prematurely X-BeenThere: tpmdd-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Tpm Device Driver maintainance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: tpmdd-devel-bounces@lists.sourceforge.net X-Virus-Scanned: ClamAV using ClamSMTP In tpm_del_char_device device_del is called prior to tpm2_shutdown where it is still used. Fortunately, so far chip->dev was used only for printouts int tpm2_shutdown flow, hence system didn't crash. But with the introduction of runtime power management it will result in shutting down the parent device while it still in use. Fixes: 20e0152393b41 ("tpm: fix crash in tpm_tis deinitialization") Signed-off-by: Tomas Winkler Tested-by: Jarkko Sakkinen Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm-chip.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index e5950131bd90..b1cb0aae8e66 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -261,7 +261,6 @@ static int tpm_add_char_device(struct tpm_chip *chip) static void tpm_del_char_device(struct tpm_chip *chip) { cdev_del(&chip->cdev); - device_del(&chip->dev); /* Make the chip unavailable. */ mutex_lock(&idr_lock); @@ -274,6 +273,8 @@ static void tpm_del_char_device(struct tpm_chip *chip) tpm2_shutdown(chip, TPM2_SU_CLEAR); chip->ops = NULL; up_write(&chip->ops_sem); + + device_del(&chip->dev); } static int tpm1_chip_register(struct tpm_chip *chip)