platform_device_unregister() will release all resourcesI also changed code into that direction in the recent patch to the tpm_nsc driver. I didn't know whether that memory had to be freed or not. Looking at several other drivers I found that none was freeing it but calling platform_device_put() (which is also called by platform_device_unregiser()) with the memory previously allocated via platform_device_alloc(). Though platform_device_put() calls put_device()
and remove it from the subsystem, then drop reference count by
calling platform_device_put().
We should not call kfree(pdev) after platform_device_unregister(pdev).
Signed-off-by: Axel Lin<axel.lin@xxxxxxxxx>
---
drivers/char/tpm/tpm_nsc.c | 2 --
1 files changed, 0 insertions(+), 2 deletions(-)
diff --git a/drivers/char/tpm/tpm_nsc.c b/drivers/char/tpm/tpm_nsc.c
index 82facc9..4d24648 100644
--- a/drivers/char/tpm/tpm_nsc.c
+++ b/drivers/char/tpm/tpm_nsc.c
@@ -396,8 +396,6 @@ static void __exit cleanup_nsc(void)
if (pdev) {
tpm_nsc_remove(&pdev->dev);
platform_device_unregister(pdev);
- kfree(pdev);
- pdev = NULL;
}
platform_driver_unregister(&nsc_drv);