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: 732297 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 ozlabs.org (Postfix) with ESMTPS id 3vVP6X48g0z9s7K for ; Sat, 25 Feb 2017 08:16:20 +1100 (AEDT) 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-Spam-Score: -1.6 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 AWL AWL: Adjusted score from AWL reputation of From: address 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 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); }