Skip to content

Commit ba0ef85

Browse files
jgunthorpePeterHuewe
authored andcommitted
tpm: Fix initialization of the cdev
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: <[email protected]> Fixes: 313d21e ("tpm: device class for tpm") Signed-off-by: Jason Gunthorpe <[email protected]> Reviewed-by: Dmitry Torokhov <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Tested-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Peter Huewe <[email protected]>
1 parent b3bddff commit ba0ef85

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/char/tpm/tpm-chip.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ struct tpm_chip *tpmm_chip_alloc(struct device *dev,
129129

130130
device_initialize(&chip->dev);
131131

132-
chip->cdev.owner = chip->pdev->driver->owner;
133132
cdev_init(&chip->cdev, &tpm_fops);
133+
chip->cdev.owner = chip->pdev->driver->owner;
134+
chip->cdev.kobj.parent = &chip->dev.kobj;
134135

135136
return chip;
136137
}

0 commit comments

Comments
 (0)