From patchwork Sat Oct 1 19:25:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 677419 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 3smdZk0vtvz9s5w for ; Sun, 2 Oct 2016 06:26:06 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=sfs-ml-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1bqPv8-0006Iv-UH; Sat, 01 Oct 2016 19:26:02 +0000 Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1bqPv7-0006Ip-Sr for tpmdd-devel@lists.sourceforge.net; Sat, 01 Oct 2016 19:26:01 +0000 X-ACL-Warn: Received: from mga03.intel.com ([134.134.136.65]) by sog-mx-2.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1bqPv7-0004hs-1Q for tpmdd-devel@lists.sourceforge.net; Sat, 01 Oct 2016 19:26:01 +0000 Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga103.jf.intel.com with ESMTP; 01 Oct 2016 12:25:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,428,1473145200"; d="scan'208";a="15294801" Received: from vdussau1-mobl2.ger.corp.intel.com (HELO localhost) ([10.252.5.8]) by fmsmga005.fm.intel.com with ESMTP; 01 Oct 2016 12:25:55 -0700 From: Jarkko Sakkinen To: Peter Huewe Date: Sat, 1 Oct 2016 22:25:26 +0300 Message-Id: <1475349926-476-4-git-send-email-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1475349926-476-1-git-send-email-jarkko.sakkinen@linux.intel.com> References: <1475349926-476-1-git-send-email-jarkko.sakkinen@linux.intel.com> X-Spam-Score: -3.1 (---) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -3.1 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain 0.0 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1bqPv7-0004hs-1Q Cc: "moderated list:TPM DEVICE DRIVER" , open list Subject: [tpmdd-devel] [PATCH RESEND 3/3] tpm: drop tpm1_chip_register(/unregister) 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 Check for TPM2 chip in tpm_sysfs_add_device, tpm_bios_log_setup and tpm_bios_log_teardown in order to make code flow cleaner and to enable to implement TPM 2.0 support later on. This is partially derived from the commit by Nayna Jain with the extension that also tpm1_chip_register is dropped. Signed-off-by: Jarkko Sakkinen --- drivers/char/tpm/tpm-chip.c | 31 +++++-------------------------- drivers/char/tpm/tpm-sysfs.c | 3 +++ drivers/char/tpm/tpm_eventlog.c | 6 ++++++ 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index a56b609..eac1f10 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -276,28 +276,6 @@ static void tpm_del_char_device(struct tpm_chip *chip) up_write(&chip->ops_sem); } -static int tpm1_chip_register(struct tpm_chip *chip) -{ - int rc; - - if (chip->flags & TPM_CHIP_FLAG_TPM2) - return 0; - - tpm_sysfs_add_device(chip); - - rc = tpm_bios_log_setup(chip); - - return rc; -} - -static void tpm1_chip_unregister(struct tpm_chip *chip) -{ - if (chip->flags & TPM_CHIP_FLAG_TPM2) - return; - - tpm_bios_log_teardown(chip); -} - static void tpm_del_legacy_sysfs(struct tpm_chip *chip) { struct attribute **i; @@ -364,7 +342,9 @@ int tpm_chip_register(struct tpm_chip *chip) return rc; } - rc = tpm1_chip_register(chip); + tpm_sysfs_add_device(chip); + + rc = tpm_bios_log_setup(chip); if (rc) return rc; @@ -372,7 +352,7 @@ int tpm_chip_register(struct tpm_chip *chip) rc = tpm_add_char_device(chip); if (rc) { - tpm1_chip_unregister(chip); + tpm_bios_log_teardown(chip); return rc; } @@ -407,8 +387,7 @@ void tpm_chip_unregister(struct tpm_chip *chip) return; tpm_del_legacy_sysfs(chip); - - tpm1_chip_unregister(chip); + tpm_bios_log_teardown(chip); tpm_del_char_device(chip); } EXPORT_SYMBOL_GPL(tpm_chip_unregister); diff --git a/drivers/char/tpm/tpm-sysfs.c b/drivers/char/tpm/tpm-sysfs.c index a76ab4a..1eca5ec 100644 --- a/drivers/char/tpm/tpm-sysfs.c +++ b/drivers/char/tpm/tpm-sysfs.c @@ -284,6 +284,9 @@ static const struct attribute_group tpm_dev_group = { void tpm_sysfs_add_device(struct tpm_chip *chip) { + if (chip->flags & TPM_CHIP_FLAG_TPM2) + return; + /* The sysfs routines rely on an implicit tpm_try_get_ops, device_del * is called before ops is null'd and the sysfs core synchronizes this * removal so that no callbacks are running or can run again diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c index f5e1d06..c57b981 100644 --- a/drivers/char/tpm/tpm_eventlog.c +++ b/drivers/char/tpm/tpm_eventlog.c @@ -373,6 +373,9 @@ int tpm_bios_log_setup(struct tpm_chip *chip) const char *name = dev_name(&chip->dev); unsigned int cnt; + if (chip->flags & TPM_CHIP_FLAG_TPM2) + return 0; + cnt = 0; chip->bios_dir[cnt] = securityfs_create_dir(name, NULL); @@ -410,6 +413,9 @@ void tpm_bios_log_teardown(struct tpm_chip *chip) { int i; + if (chip->flags & TPM_CHIP_FLAG_TPM2) + return; + for (i = (TPM_NUM_EVENT_LOG_FILES - 1); i >= 0; i--) { if (chip->bios_dir[i]) securityfs_remove(chip->bios_dir[i]);