free_device_res() frees dynamically allocated resources allocated during
device lifetime. These are no longer needed when the device is
unregistered, so we can free them in unregister_device(). With this
free_device_res() might be called multiple times, so set
dev->deferred_probe_reason to NULL after freeing it to avoid double
frees.

Signed-off-by: Sascha Hauer <[email protected]>
---
 drivers/base/driver.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index eefed4b1a5..753e06963b 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -335,6 +335,8 @@ int unregister_device(struct device *old_dev)
        if (np && np->dev == old_dev)
                np->dev = NULL;
 
+       free_device_res(old_dev);
+
        return 0;
 }
 EXPORT_SYMBOL(unregister_device);
@@ -352,6 +354,7 @@ void free_device_res(struct device *dev)
        free(dev->unique_name);
        dev->unique_name = NULL;
        free(dev->deferred_probe_reason);
+       dev->deferred_probe_reason = NULL;
 }
 EXPORT_SYMBOL(free_device_res);
 
-- 
2.47.3


Reply via email to