linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: jarkko.sakkinen@linux.intel.com (Jarkko Sakkinen)
To: linux-security-module@vger.kernel.org
Subject: [PATCH v2] tpm: use struct tpm_chip for tpm_chip_find_get()
Date: Wed, 25 Oct 2017 22:07:46 +0200	[thread overview]
Message-ID: <20171025200746.svsraubdotjyzt2i@linux.intel.com> (raw)
In-Reply-To: <20171025194633.GB998@obsidianresearch.com>

On Wed, Oct 25, 2017 at 01:46:33PM -0600, Jason Gunthorpe wrote:
> > struct tpm_chip *tpm_chip_find_get(u64 id)
> > {
> > 	struct tpm_chup *chip;
> > 	struct tpm_chip *res = NULL;
> > 	int chip_num = 0;
> > 	int chip_prev;
> > 
> > 	mutex_lock(&idr_lock);
> > 
> > 	do {
> > 		chip_prev = chip_num;
> > 
> > 		chip = idr_get_next(&dev_nums_idr, &chip_num);
> > 
> > 		if (chip && (!id || id == chip->id) && !tpm_try_get_ops(chip)) {
> > 			res = chip;
> > 			break;
> > 		}
> > 	} while (chip_prev != chip_num);
> > 
> > 	mutex_unlock(&idr_lock);
> > 
> > 	return res;
> > }
> 
> ?? The old version was correct, idr_find_slowpath is better than an
> idr_get_next serach if you already know id.
> 
> PrasannaKumar's solution seems right, if we already have chip, then we
> just need to lock it again:
> 
> struct tpm_chip *tpm_chip_find_get(struct tpm_chip *chip)
> {
> 	struct tpm_chip *res = NULL;
> 
> 	mutex_lock(&idr_lock);
> 
> 	if (!chip) {
> 		int chip_num = 0;
> 		int chip_prev;
> 
> 		do {
> 			chip_prev = chip_num;
> 			chip = idr_get_next(&dev_nums_idr, &chip_num);
> 			if (chip && !tpm_try_get_ops(chip)) {
> 				res = chip;
> 				break;
> 			}
> 		} while (chip_prev != chip_num);
> 	} else {
> 		if (!tpm_try_get_ops(chip))
> 			res = chip;
> 	}
> 
> 	mutex_unlock(&idr_lock);
> 
> 	return res;
> }
> 
> Jason

The id has a nice feature that it is unique for one boot cycle you can
even try to get a chip that has been deleted. It has the most stable
properties in the long run.

Address is a reusable identifier in one boot cycle.

/Jarkko
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2017-10-25 20:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-25 11:55 [PATCH v2] tpm: use struct tpm_chip for tpm_chip_find_get() Jarkko Sakkinen
2017-10-25 15:10 ` PrasannaKumar Muralidharan
2017-10-25 19:34   ` Jarkko Sakkinen
2017-10-25 19:46     ` Jason Gunthorpe
2017-10-25 20:07       ` Jarkko Sakkinen [this message]
2017-10-25 20:17         ` Jason Gunthorpe
2017-10-26 10:54           ` Jarkko Sakkinen
2017-10-25 15:22 ` Jason Gunthorpe

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=20171025200746.svsraubdotjyzt2i@linux.intel.com \
    --to=jarkko.sakkinen@linux.intel.com \
    --cc=linux-security-module@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).