From patchwork Tue Aug 21 15:57:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 10571923 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1C4E0921 for ; Tue, 21 Aug 2018 15:57:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A8532A976 for ; Tue, 21 Aug 2018 15:57:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F30582A97A; Tue, 21 Aug 2018 15:57:12 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 A22902A966 for ; Tue, 21 Aug 2018 15:57:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728083AbeHUTRx (ORCPT ); Tue, 21 Aug 2018 15:17:53 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45102 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726967AbeHUTRx (ORCPT ); Tue, 21 Aug 2018 15:17:53 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 364EA402178A; Tue, 21 Aug 2018 15:57:11 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-123-147.rdu2.redhat.com [10.10.123.147]) by smtp.corp.redhat.com (Postfix) with ESMTP id 447D77D4DC; Tue, 21 Aug 2018 15:57:10 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 03/23] TPM: Provide a platform driver for the user emulator driver From: David Howells To: denkenz@gmail.com, jarkko.sakkinen@linux.intel.com, jejb@linux.vnet.ibm.com Cc: keyrings@vger.kernel.org, linux-integrity@vger.kernel.org, tpmdd-devel@lists.sourceforge.net, linux-security-module@vger.kernel.org Date: Tue, 21 Aug 2018 16:57:09 +0100 Message-ID: <153486702979.13066.16900998092976336647.stgit@warthog.procyon.org.uk> In-Reply-To: <153486700916.13066.12870860668352070081.stgit@warthog.procyon.org.uk> References: <153486700916.13066.12870860668352070081.stgit@warthog.procyon.org.uk> User-Agent: StGit/unknown-version MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 21 Aug 2018 15:57:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 21 Aug 2018 15:57:11 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'dhowells@redhat.com' RCPT:'' 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 Provide a platform driver for the user emulator driver. This seems to be necessary to stop tpm_chip_find_get() from blowing up because it assumes unconditionally that any device will have a driver attached: if (try_module_get(pos->dev->driver->owner)) { However, this doesn't then work right because if I remove the TPM device and re-add it, the tpm ID isn't recycled (ie, /dev/tpm0 becomes unavailable and the new TPM is /dev/tpm1). Signed-off-by: David Howells --- drivers/char/tpm/tpm_user_emul.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/char/tpm/tpm_user_emul.c b/drivers/char/tpm/tpm_user_emul.c index b96350592bca..e5b13358c71e 100644 --- a/drivers/char/tpm/tpm_user_emul.c +++ b/drivers/char/tpm/tpm_user_emul.c @@ -656,17 +656,39 @@ static struct miscdevice tpm_user_dev = { .fops = &tpm_user_fops, }; +static struct platform_driver tpm_user_drv = { + .driver = { + .name = "tpm_user", + .owner = THIS_MODULE, + /* .pm = &tpm_user_pm, -- do we need pm since there's no h/w? */ + }, +}; + /* * Initialise a device */ static __init int tpm_user_mod_init(void) { - return misc_register(&tpm_user_dev); + int ret; + + ret = platform_driver_register(&tpm_user_drv); + if (ret < 0) + return ret; + + ret = misc_register(&tpm_user_dev); + if (ret < 0) + goto error_dev; + return 0; + +error_dev: + platform_driver_unregister(&tpm_user_drv); + return ret; } device_initcall(tpm_user_mod_init); static __exit void tpm_user_mod_exit(void) { misc_deregister(&tpm_user_dev); + platform_driver_unregister(&tpm_user_drv); } module_exit(tpm_user_mod_exit);