All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Steffen <Alexander.Steffen@infineon.com>
To: <jarkko.sakkinen@linux.intel.com>, <linux-integrity@vger.kernel.org>
Cc: Alexander Steffen <Alexander.Steffen@infineon.com>
Subject: [RFC][PATCH 1/3] tpm-chip: Move idr_replace calls to appropriate places
Date: Thu, 14 Dec 2017 17:06:12 +0100	[thread overview]
Message-ID: <20171214160614.11808-2-Alexander.Steffen@infineon.com> (raw)
In-Reply-To: <20171214160614.11808-1-Alexander.Steffen@infineon.com>

According to the comments, adding/removing the chip from the list should be
the first/last action in (un)register. But currently it is done in a
subfunction in the middle of the process. Moving the code from the
subfunctions to the appropriate places within (un)register ensures that the
code matches the comments.

Signed-off-by: Alexander Steffen <Alexander.Steffen@infineon.com>
---
 drivers/char/tpm/tpm-chip.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
index a114e8f..25ebe49 100644
--- a/drivers/char/tpm/tpm-chip.c
+++ b/drivers/char/tpm/tpm-chip.c
@@ -321,11 +321,6 @@ static int tpm_add_char_device(struct tpm_chip *chip)
 		}
 	}
 
-	/* Make the chip available. */
-	mutex_lock(&idr_lock);
-	idr_replace(&dev_nums_idr, chip, chip->dev_num);
-	mutex_unlock(&idr_lock);
-
 	return rc;
 }
 
@@ -333,11 +328,6 @@ static void tpm_del_char_device(struct tpm_chip *chip)
 {
 	cdev_device_del(&chip->cdev, &chip->dev);
 
-	/* Make the chip unavailable. */
-	mutex_lock(&idr_lock);
-	idr_replace(&dev_nums_idr, NULL, chip->dev_num);
-	mutex_unlock(&idr_lock);
-
 	/* Make the driver uncallable. */
 	down_write(&chip->ops_sem);
 	if (chip->flags & TPM_CHIP_FLAG_TPM2)
@@ -432,6 +422,11 @@ int tpm_chip_register(struct tpm_chip *chip)
 		return rc;
 	}
 
+	/* Make the chip available. */
+	mutex_lock(&idr_lock);
+	idr_replace(&dev_nums_idr, chip, chip->dev_num);
+	mutex_unlock(&idr_lock);
+
 	return 0;
 }
 EXPORT_SYMBOL_GPL(tpm_chip_register);
@@ -451,6 +446,11 @@ EXPORT_SYMBOL_GPL(tpm_chip_register);
  */
 void tpm_chip_unregister(struct tpm_chip *chip)
 {
+	/* Make the chip unavailable. */
+	mutex_lock(&idr_lock);
+	idr_replace(&dev_nums_idr, NULL, chip->dev_num);
+	mutex_unlock(&idr_lock);
+
 	tpm_del_legacy_sysfs(chip);
 	tpm_bios_log_teardown(chip);
 	if (chip->flags & TPM_CHIP_FLAG_TPM2)
-- 
2.7.4

  reply	other threads:[~2017-12-14 16:07 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-14 16:06 [RFC][PATCH 0/3] Export broken TPMs to user space Alexander Steffen
2017-12-14 16:06 ` Alexander Steffen [this message]
2017-12-14 19:27   ` [RFC][PATCH 1/3] tpm-chip: Move idr_replace calls to appropriate places Jason Gunthorpe
2017-12-15  9:26     ` Alexander.Steffen
2018-01-18 18:38   ` Jarkko Sakkinen
2018-01-18 18:41   ` Jarkko Sakkinen
2017-12-14 16:06 ` [RFC][PATCH 2/3] tpm-chip: Return TPM error codes from auto_startup functions Alexander Steffen
2017-12-14 16:06 ` [RFC][PATCH 3/3] tpm-chip: Export TPM device to user space even when startup failed Alexander Steffen
2017-12-14 19:28   ` Jason Gunthorpe
2018-01-18 18:45   ` Jarkko Sakkinen
2018-01-18 19:24     ` Jason Gunthorpe
2018-01-23 12:39       ` Jarkko Sakkinen
2017-12-15 14:47 ` [RFC][PATCH 0/3] Export broken TPMs to user space Jarkko Sakkinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171214160614.11808-2-Alexander.Steffen@infineon.com \
    --to=alexander.steffen@infineon.com \
    --cc=jarkko.sakkinen@linux.intel.com \
    --cc=linux-integrity@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.