Skip to contentSkip to conversation

tpm: Fix initialization of the cdev

PATCH In review Jason Gunthorpe 2 participants 2 messages Jun 30, 2015 – Jul 1, 2015 TPM device driver

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

Fixes 313d21eeab92 ("tpm: device class for tpm")
---
 drivers/char/tpm/tpm-chip.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Peter, I've only compile tests this. Thanks

drivers/char/tpm/tpm-chip.c +2 -1
index 283f00a7f036..1082d4bb016a 100644
@@ -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;
 }
Signature · 1 line
2.1.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Jason Gunthorpe

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.

Fixes 313d21eeab92 ("tpm: device class for tpm")

Right, when embedding cdev its lifetime should be tied to the lifetime of the enclosing structure.

Quoted 28 lines
---
 drivers/char/tpm/tpm-chip.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Peter, I've only compile tests this. Thanks

drivers/char/tpm/tpm-chip.c +2 -1
index 283f00a7f036..1082d4bb016a 100644
@@ -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;
 }
Signature · 6 lines
2.1.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Signature · 1 line
Dmitry