From patchwork Fri Feb 24 21:16:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 9591171 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 CC031601AE for ; Fri, 24 Feb 2017 21:16:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB2842895D for ; Fri, 24 Feb 2017 21:16:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B010A28965; Fri, 24 Feb 2017 21:16:16 +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 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 3704F2895D for ; Fri, 24 Feb 2017 21:16:16 +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 1chNDr-0005Id-5y; Fri, 24 Feb 2017 21:16:15 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1chNDq-0005IY-1J for tpmdd-devel@lists.sourceforge.net; Fri, 24 Feb 2017 21:16:14 +0000 Received-SPF: pass (sog-mx-1.v43.ch3.sourceforge.com: domain of obsidianresearch.com designates 184.70.90.242 as permitted sender) client-ip=184.70.90.242; envelope-from=jgunthorpe@obsidianresearch.com; helo=quartz.orcorp.ca; Received: from quartz.orcorp.ca ([184.70.90.242]) by sog-mx-1.v43.ch3.sourceforge.com with esmtps (TLSv1:AES128-SHA:128) (Exim 4.76) id 1chNDp-0000Ef-4w for tpmdd-devel@lists.sourceforge.net; Fri, 24 Feb 2017 21:16:14 +0000 Received: from [10.0.0.156] (helo=jggl.edm.orcorp.ca) by quartz.orcorp.ca with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1chNDj-0001Jx-5g; Fri, 24 Feb 2017 14:16:07 -0700 Received: from jgg by jggl.edm.orcorp.ca with local (Exim 4.86_2) (envelope-from ) id 1chNDj-0007bd-3a; Fri, 24 Feb 2017 14:16:07 -0700 Date: Fri, 24 Feb 2017 14:16:07 -0700 From: Jason Gunthorpe To: Jarkko Sakkinen Message-ID: <20170224211607.GB28016@obsidianresearch.com> References: <20170223211914.GA12752@obsidianresearch.com> <20170224174354.w5e2v3nxntod72je@intel.com> <20170224205949.u63xb5qhqzd7lqtp@intel.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170224205949.u63xb5qhqzd7lqtp@intel.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Broken-Reverse-DNS: no host name found for IP address 10.0.0.156 X-Headers-End: 1chNDp-0000Ef-4w Cc: linux-security-module@vger.kernel.org, tpmdd-devel@lists.sourceforge.net Subject: Re: [tpmdd-devel] [PATCH] tpm: Use the right clean up after cdev_add completes 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: , Errors-To: tpmdd-devel-bounces@lists.sourceforge.net X-Virus-Scanned: ClamAV using ClamSMTP On Fri, Feb 24, 2017 at 10:59:50PM +0200, Jarkko Sakkinen wrote: > On Fri, Feb 24, 2017 at 07:43:54PM +0200, Jarkko Sakkinen wrote: > > On Thu, Feb 23, 2017 at 02:19:14PM -0700, Jason Gunthorpe wrote: > > > Once cdev_add is done the device node is visible to user space and > > > could have been opened. Thus we have to go through the locking > > > process in tpm_del_char_device if device_add fails. > > > > > > Fixes: 2c91ce8523a ("tpm: fix the rollback in tpm_chip_register()") > > > Signed-off-by: Jason Gunthorpe > > > > Pushed. > > It would make easier to merge this with resource manager commits if > there was instead > > void tpm_chip_shutdown(struct tpm_chip *chip) > { > /* Make the driver uncallable. */ > down_write(&chip->ops_sem); > if (chip->flags & TPM_CHIP_FLAG_TPM2) > tpm2_shutdown(chip, TPM2_SU_CLEAR); > chip->ops = NULL; > up_write(&chip->ops_sem); > } > > And you would call this instead of wiring into tpm_del_char_device. Hum.. I think this direction in the RM patch would be more maintainable.. Otherwise tpm_add_char_device has very complicated error handling. ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index c82acf0a6e7353..444cf2495ef0e0 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -353,18 +353,26 @@ int tpm_chip_register(struct tpm_chip *chip) tpm_add_ppi(chip); rc = tpm_add_char_device(chip); - if (rc) { - tpm_bios_log_teardown(chip); - return rc; - } + if (rc) + goto err_add_char; + + rc = tpm_add_rm_char_device(chip); + if (rc) + goto err_add_rm_char; rc = tpm_add_legacy_sysfs(chip); - if (rc) { - tpm_chip_unregister(chip); - return rc; - } + if (rc) + goto err_add_legacy_sysfs; return 0; + +err_add_legacy_sysfs: + tpm_del_rm_char_device(chip); +err_add_rm_char: + tpm_del_char_device(chip, true); +err_add_char: + tpm_bios_log_teardown(chip); + return rc; } EXPORT_SYMBOL_GPL(tpm_chip_register); @@ -384,6 +392,7 @@ EXPORT_SYMBOL_GPL(tpm_chip_register); void tpm_chip_unregister(struct tpm_chip *chip) { tpm_del_legacy_sysfs(chip); + tpm_del_rm_char_device(chip); tpm_bios_log_teardown(chip); tpm_del_char_device(chip, true); }