Skip to content

Commit

Permalink
tpm: Fix initialization of the cdev
Browse files Browse the repository at this point in the history
When a cdev is contained in a dynamic structure the cdev parent kobj
should be set to the kobj that controls the lifetime of the enclosing
structure. In TPM's case this is the embedded struct device.

Also, cdev_init 0's the whole structure, so all sets must be after,
not before. This fixes module ref counting and cdev.

Cc: <stable@vger.kernel.org>
Fixes: 313d21e ("tpm: device class for tpm")
Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
Reviewed-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Peter Huewe <peterhuewe@gmx.de>
  • Loading branch information
jgunthorpe authored and PeterHuewe committed Jul 13, 2015
1 parent b3bddff commit ba0ef85
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/char/tpm/tpm-chip.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ struct tpm_chip *tpmm_chip_alloc(struct device *dev,

device_initialize(&chip->dev);

chip->cdev.owner = chip->pdev->driver->owner;
cdev_init(&chip->cdev, &tpm_fops);
chip->cdev.owner = chip->pdev->driver->owner;
chip->cdev.kobj.parent = &chip->dev.kobj;

return chip;
}
Expand Down

0 comments on commit ba0ef85

Please sign in to comment.