lkml.org 
[lkml]   [2008]   [Dec]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH 1/6] integrity: TPM internel kernel interface
From
Date
> > > +
> > > +/**
> > > + * tpm_pcr_read - read a pcr value
> > > + * @chip_id: tpm chip identifier
> > > + * Upper 2 bytes: ANY, HW_ONLY or SW_ONLY
> > > + * Lower 2 bytes: tpm idx # or AN&
> > > + * @pcr_idx: pcr idx to retrieve
> > > + * @res_buf: TPM_PCR value
> > > + * size of res_buf is 20 bytes (or NULL if you don't care)
> > > + *
> > > + * The TPM driver should be built-in, but for whatever reason it
> > > + * isn't, protect against the chip disappearing, by incrementing
> > > + * the module usage count.
> > > + */
> > > +int tpm_pcr_read(u32 chip_id, int pcr_idx, u8 *res_buf)
> > > +{
> > > + u8 data[READ_PCR_RESULT_SIZE];
> > > + int rc;
> > > + __be32 index;
> > > + int chip_num = chip_id & TPM_CHIP_NUM_MASK;
> > > + struct tpm_chip *chip;
> > > +
> > > + rcu_read_lock();
> > > + chip = tpm_chip_lookup(chip_num, chip_id >> TPM_CHIP_TYPE_SHIFT);
> > > + if (chip == NULL) {
> > > + rcu_read_unlock();
> > > + return -ENODEV;
> > > + }
> > > + if (!try_module_get(chip->dev->driver->owner)) {
> > > + rcu_read_unlock();
> > > + return -ENODEV;
> > > + }
> > > + rcu_read_unlock();
> >
> > This little bit of lookup, check for NULL, and try_module_get() looks
> > cut-n-pasted in the next two functions. Should be consolidated.
> >
>
> Same here.
>
> > Also, if you need to shift down the chip_id every time anyway, why not
> > just do it inside the lookup function?
>
> tpm_chip_lookup() only needs the chip type, not the entire chip_id, so
> its usage is probably clearer if written this way.
>

Wait.. chip_num, the other parameter, depends on chip_id and a
previously defined constant, so, you are right, it's saner to just pass
chip_id to it.. sorry, and thanks. This will be included also on the
next patchset I'm about to send.

Rajiv



\
 
 \ /
  Last update: 2008-12-04 23:33    [from the cache]
©2003-2014 Jasper Spaans. Advertise on this site