From: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
To: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Cc: tpmdd-devel@lists.sourceforge.net,
Peter Huewe <peterhuewe@gmx.de>,
Marcel Selhorst <tpmdd@selhorst.net>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 01/12] tpm: prepare TPM driver for adding TPM2 support
Date: Wed, 24 Sep 2014 10:49:49 -0600 [thread overview]
Message-ID: <20140924164949.GC8898@obsidianresearch.com> (raw)
In-Reply-To: <1411549562-24242-2-git-send-email-jarkko.sakkinen@linux.intel.com>
On Wed, Sep 24, 2014 at 12:05:51PM +0300, Jarkko Sakkinen wrote:
> * Separated allocation and registeration into two functions:
> * tpm_chip_alloc()
> * tpm_chip_register()
Okay, this is a nice start!
I had intended tpm-interface.c to hold these 'chip' functions and the
other cmd related functions to be moved out into tpm-cmds.c (or
tpm1-cmds?), which is more symmetrical with what you are doing with
tpm2-cmds. Does that seem reasonable?
It doesn't make sense to leave some chip related stuff in
tpm-interface mixed with cmd stuff, I'd prefer to see a clean split if
you are going to split them.
> +struct tpm_chip *tpm_chip_alloc(struct device *dev,
> + const struct tpm_class_ops *ops)
> +{
I want to see a clear description of what the unwind procedures are
for each step using the new API, and kdoc on all the new API functions
drivers are expected to use.
> +int tpm_chip_register(struct tpm_chip *chip)
> +{
> + int rc;
All the common startup functions need to be done here too: get
timeouts, self test, etc.
> + rc = tpm_dev_add_device(chip);
> + if (rc)
> + return rc;
> +
> + rc = tpm_sysfs_add_device(chip);
> + if (rc)
> + goto del_misc;
> +
> + rc = tpm_add_ppi(&chip->dev->kobj);
> + if (rc)
> + goto del_sysfs;
> +
> + if (!chip->tpm2)
> + chip->bios_dir = tpm_bios_log_setup(chip->devname);
What about failure of tpm_bios_log_setup?
> /*
> * Called from tpm_<specific>.c probe function only for devices
> * the driver has determined it should claim. Prior to calling
> @@ -1081,61 +1019,19 @@ struct tpm_chip *tpm_register_hardware(struct device *dev,
> const struct tpm_class_ops *ops)
> {
> struct tpm_chip *chip;
> + int rc;
>
> - /* Driver specific per-device data */
> - chip = kzalloc(sizeof(*chip), GFP_KERNEL);
> -
> - if (chip == NULL)
> + chip = tpm_chip_alloc(dev, ops);
> + if (!chip)
> return NULL;
I think tpm_chip_alloc should return an ERR_PTR..
> - mutex_init(&chip->tpm_mutex);
> - INIT_LIST_HEAD(&chip->list);
> -
> - chip->ops = ops;
> - chip->dev_num = find_first_zero_bit(dev_mask, TPM_NUM_DEVICES);
> -
> - if (chip->dev_num >= TPM_NUM_DEVICES) {
> - dev_err(dev, "No available tpm device numbers\n");
> - goto out_free;
> + rc = tpm_chip_register(chip);
> + if (rc) {
> + put_device(chip->dev);
> + kfree(chip);
No, open coding this is not a good unwind, and this is not correct
anyhow, it looks like it will double free chip...
This is where things got stuck for me too, the unwind is where all the
problems are and I think the solution is to make the alloc paths
completely different between new and old.
We really want tpmm_chip_alloc for the new style path (so drivers have
no unwind) and the old style path .. I don't know what is correct
there, but the safest thing is to stay exactly the same.
Also, please split this patch into moving stuff into tmp1-cmds.c and
then patching to add functionality.
Jason
next prev parent reply other threads:[~2014-09-24 16:50 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-24 9:05 [PATCH v1 00/12] tpm: TPM2 support Jarkko Sakkinen
2014-09-24 9:05 ` [PATCH v1 01/12] tpm: prepare TPM driver for adding " Jarkko Sakkinen
2014-09-24 16:49 ` Jason Gunthorpe [this message]
2014-09-24 9:05 ` [PATCH v1 02/12] tpm: TPM2 support for tpm_calc_ordinal_durations() Jarkko Sakkinen
2014-09-24 9:05 ` [PATCH v1 03/12] tpm: TPM2 support for tpm_pcr_read() Jarkko Sakkinen
2014-09-24 16:53 ` Jason Gunthorpe
2014-09-24 19:43 ` Jarkko Sakkinen
2014-09-24 20:14 ` Peter Hüwe
2014-09-24 20:16 ` Jason Gunthorpe
2014-09-24 9:05 ` [PATCH v1 04/12] tpm: TPM2 support for tpm_do_selftest() Jarkko Sakkinen
2014-09-24 9:05 ` [PATCH v1 05/12] tpm: added tpm2_get_tpm_pt() Jarkko Sakkinen
2014-09-24 9:05 ` [PATCH v1 06/12] tpm: TPM2 support for tpm_pcr_extend() Jarkko Sakkinen
2014-09-24 9:05 ` [PATCH v1 07/12] tpm: TPM2 support for tpm_get_random() Jarkko Sakkinen
2014-09-24 9:05 ` [PATCH v1 08/12] tpm: TPM2 support for tpm_startup() Jarkko Sakkinen
2014-09-24 9:05 ` [PATCH v1 09/12] tpm: TPM2 support for tpm_gen_interrupt() Jarkko Sakkinen
2014-09-24 9:06 ` [PATCH v1 10/12] tpm: TPM 2.0 FIFO Interface Jarkko Sakkinen
2014-09-24 16:59 ` Jason Gunthorpe
2014-09-24 19:30 ` Jarkko Sakkinen
2014-09-24 9:06 ` [PATCH v1 11/12] tpm: Driver for TPM 2.0 CRB Interface Jarkko Sakkinen
2014-09-24 17:05 ` Jason Gunthorpe
2014-09-24 19:28 ` Jarkko Sakkinen
2014-09-25 13:56 ` Jarkko Sakkinen
2014-09-24 9:06 ` [PATCH v1 12/12] tpm: TPM2 sysfs attributes Jarkko Sakkinen
2014-09-24 17:13 ` Jason Gunthorpe
2014-09-24 17:34 ` [tpmdd-devel] " Stefan Berger
2014-09-24 17:59 ` Jason Gunthorpe
2014-09-24 18:50 ` Jarkko Sakkinen
2014-09-24 20:39 ` Peter Hüwe
2014-09-24 20:50 ` Jason Gunthorpe
2014-09-24 18:36 ` Peter Hüwe
2014-09-24 19:02 ` Jarkko Sakkinen
2014-09-24 20:19 ` Jason Gunthorpe
2014-09-24 20:35 ` Peter Hüwe
2014-09-24 20:46 ` Jason Gunthorpe
2014-09-26 17:19 ` Jarkko Sakkinen
2014-09-30 20:07 ` [tpmdd-devel] " Jarkko Sakkinen
2014-09-30 20:12 ` Jason Gunthorpe
2014-10-02 12:30 ` Jarkko Sakkinen
2014-09-24 17:28 ` [PATCH v1 00/12] tpm: TPM2 support Jarkko Sakkinen
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=20140924164949.GC8898@obsidianresearch.com \
--to=jgunthorpe@obsidianresearch.com \
--cc=jarkko.sakkinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=peterhuewe@gmx.de \
--cc=tpmdd-devel@lists.sourceforge.net \
--cc=tpmdd@selhorst.net \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.