lkml.org 
[lkml]   [2021]   [Feb]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v4] tpm: fix reference counting for struct tpm_chip
On Tue, Feb 16, 2021 at 08:53:42AM -0400, Jason Gunthorpe wrote:
> On Tue, Feb 16, 2021 at 01:31:00AM +0100, Lino Sanfilippo wrote:
> >
> > +static int tpm_add_tpm2_char_device(struct tpm_chip *chip)

BTW, this naming is crap.

- 2x tpm
- char is useless

-> tpm2_add_device


> > +{
> > + int rc;
> > +
> > + device_initialize(&chip->devs);
> > + chip->devs.parent = chip->dev.parent;
> > + chip->devs.class = tpmrm_class;
> > +
> > + rc = dev_set_name(&chip->devs, "tpmrm%d", chip->dev_num);
> > + if (rc)
> > + goto out_put_devs;

Right, and empty line missing here.

> > + /*
> > + * get extra reference on main device to hold on behalf of devs.
> > + * This holds the chip structure while cdevs is in use. The
> > + * corresponding put is in the tpm_devs_release.
> > + */
> > + get_device(&chip->dev);
> > + chip->devs.release = tpm_devs_release;
> > + chip->devs.devt =
> > + MKDEV(MAJOR(tpm_devt), chip->dev_num + TPM_NUM_DEVICES);

Isn't this less than 100 chars?

> > + cdev_init(&chip->cdevs, &tpmrm_fops);
> > + chip->cdevs.owner = THIS_MODULE;
> > +
> > + rc = cdev_device_add(&chip->cdevs, &chip->devs);
> > + if (rc) {
> > + dev_err(&chip->devs,
> > + "unable to cdev_device_add() %s, major %d, minor %d, err=%d\n",
> > + dev_name(&chip->devs), MAJOR(chip->devs.devt),
> > + MINOR(chip->devs.devt), rc);
> > + goto out_put_devs;
> > + }
> > +
> > + return 0;
> > +
> > +out_put_devs:
> > + put_device(&chip->devs);
>
> I'd rather you organize this so chip->devs.release and the get_device
> is always sent instead of having the possiblity for a put_device that
> doesn't call release

/Jarkko

\
 
 \ /
  Last update: 2021-02-17 11:38    [W:0.090 / U:0.728 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site