diff options
author | Ming Lei <tom.leiming@gmail.com> | 2012-07-24 13:42:29 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-08-16 13:32:07 -0400 |
commit | a525a3ddeaca69f405d98442ab3c0746e53168dc (patch) | |
tree | 51198c610f85622549fd679bb3cf3e1940844829 /drivers/base | |
parent | 2221f6ef71d4b89ed56a233cc0200bbe9b84a385 (diff) |
driver core: free devres in device_release
device_del can happen anytime, so once it happens,
the devres of the device will be freed inside device_del, but
drivers can't know it has been deleted and may still add
resources into the device, so memory leak is caused.
This patch moves the devres_release_all to fix the problem.
Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/base')
-rw-r--r-- | drivers/base/core.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/drivers/base/core.c b/drivers/base/core.c index f338037a4f3d..c8fe4a563866 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c | |||
@@ -184,6 +184,17 @@ static void device_release(struct kobject *kobj) | |||
184 | struct device *dev = kobj_to_dev(kobj); | 184 | struct device *dev = kobj_to_dev(kobj); |
185 | struct device_private *p = dev->p; | 185 | struct device_private *p = dev->p; |
186 | 186 | ||
187 | /* | ||
188 | * Some platform devices are driven without driver attached | ||
189 | * and managed resources may have been acquired. Make sure | ||
190 | * all resources are released. | ||
191 | * | ||
192 | * Drivers still can add resources into device after device | ||
193 | * is deleted but alive, so release devres here to avoid | ||
194 | * possible memory leak. | ||
195 | */ | ||
196 | devres_release_all(dev); | ||
197 | |||
187 | if (dev->release) | 198 | if (dev->release) |
188 | dev->release(dev); | 199 | dev->release(dev); |
189 | else if (dev->type && dev->type->release) | 200 | else if (dev->type && dev->type->release) |
@@ -1196,13 +1207,6 @@ void device_del(struct device *dev) | |||
1196 | bus_remove_device(dev); | 1207 | bus_remove_device(dev); |
1197 | driver_deferred_probe_del(dev); | 1208 | driver_deferred_probe_del(dev); |
1198 | 1209 | ||
1199 | /* | ||
1200 | * Some platform devices are driven without driver attached | ||
1201 | * and managed resources may have been acquired. Make sure | ||
1202 | * all resources are released. | ||
1203 | */ | ||
1204 | devres_release_all(dev); | ||
1205 | |||
1206 | /* Notify the platform of the removal, in case they | 1210 | /* Notify the platform of the removal, in case they |
1207 | * need to do anything... | 1211 | * need to do anything... |
1208 | */ | 1212 | */ |