tpmdd-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
Cc: linux-integrity@vger.kernel.org,
	linux-security-module@vger.kernel.org,
	Matt Mackall <mpm@selenic.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	Peter Huewe <peterhuewe@gmx.de>,
	Marcel Selhorst <tpmdd@selhorst.net>,
	Jason Gunthorpe <jgunthorpe@obsidianresearch.com>,
	Mimi Zohar <zohar@linux.vnet.ibm.com>,
	Dmitry Kasatkin <dmitry.kasatkin@gmail.com>,
	James Morris <james.l.morris@oracle.com>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	David Safford <safford@us.ibm.com>,
	David Howells <dhowells@redhat.com>,
	Jerry Snitselaar <jsnitsel@redhat.com>,
	"open list:HARDWARE RANDOM NUMBER GENERATOR CORE"
	<linux-crypto@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>,
	"moderated list:TPM DEVICE DRIVER"
	<tpmdd-devel@lists.sourceforge.net>
Subject: Re: [PATCH v2] tpm: use struct tpm_chip for tpm_chip_find_get()
Date: Wed, 25 Oct 2017 21:34:52 +0200	[thread overview]
Message-ID: <20171025193452.d4qa4dhacfgqejk7@linux.intel.com> (raw)
In-Reply-To: <CANc+2y46q85+G1=9cXKW0R8FpGBqCuzkLnJzvSYFQ1S=ztKGew@mail.gmail.com>

On Wed, Oct 25, 2017 at 08:40:26PM +0530, PrasannaKumar Muralidharan wrote:
> > -struct tpm_chip *tpm_chip_find_get(int chip_num)
> > +struct tpm_chip *tpm_chip_find_get(struct tpm_chip *chip)
> >  {
> > -       struct tpm_chip *chip, *res = NULL;
> > +       struct tpm_chip *res = NULL;
> > +       int chip_num = 0;
> >         int chip_prev;
> >
> >         mutex_lock(&idr_lock);
> >
> > -       if (chip_num == TPM_ANY_NUM) {
> > -               chip_num = 0;
> > +       if (!chip) {
> >                 do {
> >                         chip_prev = chip_num;
> >                         chip = idr_get_next(&dev_nums_idr, &chip_num);
> 
> When chip is not NULL just do tpm_try_get_ops(chip). Current code does
> more things which are not required.

Your observation is right that there is something wrong but conclusions
are incorrect.

It's actually a regression.

If @chip has a value, the code does one iteration of what it is doing in
the first branch of the condition. That is completely bogus semantics to
say the least.

To sort that out I'll introduce a new field to struct tpm_chip:

  u64 id;

This gets a value from a global count every time a chip is created.

The function will become then:

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;
}

Thanks for spotting this out. I'll refine the patch.

/Jarkko

  reply	other threads:[~2017-10-25 19:34 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 [this message]
2017-10-25 19:46     ` Jason Gunthorpe
2017-10-25 20:07       ` Jarkko Sakkinen
     [not found]         ` <20171025200746.svsraubdotjyzt2i-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
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=20171025193452.d4qa4dhacfgqejk7@linux.intel.com \
    --to=jarkko.sakkinen@linux.intel.com \
    --cc=dhowells@redhat.com \
    --cc=dmitry.kasatkin@gmail.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=james.l.morris@oracle.com \
    --cc=jgunthorpe@obsidianresearch.com \
    --cc=jsnitsel@redhat.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=mpm@selenic.com \
    --cc=peterhuewe@gmx.de \
    --cc=prasannatsmkumar@gmail.com \
    --cc=safford@us.ibm.com \
    --cc=serge@hallyn.com \
    --cc=tpmdd-devel@lists.sourceforge.net \
    --cc=tpmdd@selhorst.net \
    --cc=zohar@linux.vnet.ibm.com \
    /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).