From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Stefan Berger" Subject: Re: [PATCH v3 07/11] tpm: Replace device number bitmap with IDR Date: Mon, 22 Feb 2016 21:16:53 -0500 Message-ID: <201602230217.u1N2HIL0014602@d03av03.boulder.ibm.com> References: <1455885728-10315-1-git-send-email-stefanb@linux.vnet.ibm.com><1455885728-10315-8-git-send-email-stefanb@linux.vnet.ibm.com> <20160222190629.GE22088@obsidianresearch.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============5796075116313457432==" Return-path: In-Reply-To: <20160222190629.GE22088-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: tpmdd-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org To: Jason Gunthorpe Cc: tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org List-Id: tpmdd-devel@lists.sourceforge.net --===============5796075116313457432== Content-Type: multipart/alternative; boundary="=_alternative 000C90E885257F62_=" --=_alternative 000C90E885257F62_= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="US-ASCII" Jason Gunthorpe wrote on 02/22/2016=20 02:06:29 PM: >=20 > On Fri, Feb 19, 2016 at 07:42:04AM -0500, Stefan Berger wrote: > > + if (chip=5Fnum =3D=3D TPM=5FANY=5FNUM) > > + chip=5Fnext =3D 0; > > + > > + mutex=5Flock(&idr=5Flock); > > + > > + do { > > + if (chip=5Fnum =3D=3D TPM=5FANY=5FNUM) { > > + chip=5Fprev =3D chip=5Fnext; > > + chip =3D idr=5Fget=5Fnext(&dev=5Fnums=5Fidr, &chip=5Fnext); > > + } else > > + chip =3D idr=5Ffind=5Fslowpath(&dev=5Fnums=5Fidr, chip=5Fnum); > > + > > + if (chip && !tpm=5Ftry=5Fget=5Fops(chip)) > > + break; > > + } while (chip=5Fnum =3D=3D TPM=5FANY=5FNUM && chip=5Fprev !=3D chip= =5Fnext); >=20 > This while loop doesn't look very good if tpm=5Ftry=5Fget=5Fops fails? >=20 > Maybe like this? >=20 > struct tpm=5Fchip *tpm=5Fchip=5Ffind=5Fget(int chip=5Fnum) > { > struct tpm=5Fchip *res =3D NULL; >=20 > mutex=5Flock(&idr=5Flock); >=20 > if (chip=5Fnum =3D=3D TPM=5FANY=5FNUM) { > struct tpm=5Fchip *chip; >=20 > chip=5Fnum =3D 0; > do { > chip =3D idr=5Fget=5Fnext(&dev=5Fnums=5Fidr, &chip=5Fnum); > if (res && !tpm=5Ftry=5Fget=5Fops(chip)) { > res =3D chip; > break; > } > } > while (chip); > } else { > res =3D idr=5Ffind=5Fslowpath(&dev=5Fnums=5Fidr, chip=5Fnum); > if (res && tpm=5Ftry=5Fget=5Fops(chip)) > res =3D NULL; > } >=20 > mutex=5Funlock(&idr=5Flock); >=20 > return res; > } mutex=5Flock(&idr=5Flock); if (chip=5Fnum =3D=3D TPM=5FANY=5FNUM) { chip=5Fnum =3D 0; do { chip=5Fprev =3D chip=5Fnum; chip =3D idr=5Fget=5Fnext(&dev=5Fnums=5Fidr, &chip= =5Fnum); if (chip && !tpm=5Ftry=5Fget=5Fops(chip)) { res =3D chip; break; } } while (chip=5Fprev !=3D chip=5Fnum); } else { chip =3D idr=5Ffind=5Fslowpath(&dev=5Fnums=5Fidr, chip=5Fnu= m); if (chip && !tpm=5Ftry=5Fget=5Fops(chip)) res =3D chip; } mutex=5Funlock(&idr=5Flock); FYI: idr=5Fget=5Fnext will return NULL for a chip->dev=5Fnum that has nothi= ng=20 (NULL) registered; we *may* find something after that again. Stefan --=_alternative 000C90E885257F62_= Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="US-ASCII" Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org> wrote on 02/22/2016 02:06:29 PM:


= >
> On Fri, Feb 19, 2016 at 07:42:04AM -0500, Stefan Berger wrote= :
> > +   if (chip=5Fnum =3D=3D TPM=5FANY=5FNUM)
> >= +      chip=5Fnext =3D 0;
> > +
> > + &nb= sp; mutex=5Flock(&idr=5Flock);
> > +
> > +   do = {
> > +      if (chip=5Fnum =3D=3D TPM=5FANY=5FNUM)= {
> > +         chip=5Fprev =3D chip=5Fnext;<= br>> > +         chip =3D idr=5Fget=5Fnext(&d= ev=5Fnums=5Fidr, &chip=5Fnext);
> > +      } else
> > +=         chip =3D idr=5Ffind=5Fslowpath(&dev=5Fnums= =5Fidr, chip=5Fnum);
> > +
> > +      if (chip &am= p;& !tpm=5Ftry=5Fget=5Fops(chip))
> > +       &= nbsp; break;
> > +   } while (chip=5Fnum =3D=3D TPM=5FANY=5FN= UM && chip=5Fprev !=3D chip=5Fnext);
>
> This while loop doesn't look very good = if tpm=5Ftry=5Fget=5Fops fails?
>
> Maybe like this?
> <= br>> struct tpm=5Fchip *tpm=5Fchip=5Ffind=5Fget(int chip=5Fnum)
> = {
>    struct tpm=5Fchip *res =3D NULL;
>
> &n= bsp;  mutex=5Flock(&idr=5Flock);
>
>    if = (chip=5Fnum =3D=3D TPM=5FANY=5FNUM) {
>       struct t= pm=5Fchip *chip;
>
>       chip=5Fnum =3D 0;>       do {
>          c= hip =3D idr=5Fget=5Fnext(&dev=5Fnums=5Fidr, &chip=5Fnum);
>          if (res &&a= mp; !tpm=5Ftry=5Fget=5Fops(chip)) {
>             res =3D chip;
> &= nbsp;           break;
>      = ;    }
>       }
>      = ; while (chip);
>    } else {
>       = res =3D idr=5Ffind=5Fslowpath(&dev=5Fnums=5Fidr, chip=5Fnum);
> &= nbsp;     if (res && tpm=5Ftry=5Fget=5Fops(chip))
>=          res =3D NULL;
>    }
= >
>    mutex=5Funlock(&idr=5Flock);
>
>= ;    return res;
> }


        mutex=5Flock(&idr=5Floc= k);

    &nbs= p;   if(chip=5Fnum =3D=3D TPM=5FANY=5FNUM) {
                chip=5Fnum =3D 0;
        &= nbsp;       do {
&nbs= p;                       chip=5Fprev =3D chip=5Fnum= ;
      &nb= sp;                 chip =3D idr=5Fget=5Fnext(= &dev=5Fnums=5Fidr, &chip=5Fnum);
  &= nbsp;                     if (chip && !tpm=5Ftry=5Fget=5Fops(chip)) {
  =                               res =3D chip;
   = ;                             break;
   = ;                     }
                }while (chip= =5Fprev !=3D chip=5Fnum);
=         }else <= /font>{
                chip =3D idr=5Ffind=5Fslowpath(&dev=5Fnums=5Fidr, = chip=5Fnum);

   =             if (chip && !tpm=5Ftry=5Fget=5Fops(chip= ))
      &n= bsp;                 res =3D chip;
       
}

        mutex=5Funlock(= &idr=5Flock);



FYI: idr=5Fget= =5Fnext will return NULL for a chip->dev=5Fnum that has nothing (NULL) registered; we *may* find something after that again.

   Stefan

--=_alternative 000C90E885257F62_=-- --===============5796075116313457432== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------------ Site24x7 APM Insight: Get Deep Visibility into Application Performance APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month Monitor end-to-end web transactions and take corrective actions now Troubleshoot faster and improve end-user experience. Signup Now! http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140 --===============5796075116313457432== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ tpmdd-devel mailing list tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org https://lists.sourceforge.net/lists/listinfo/tpmdd-devel --===============5796075116313457432==--