linux-stable/drivers/base
David Gow 3bcc4c2a09 drivers: base: Free devm resources when unregistering a device
[ Upstream commit 699fb50d99 ]

In the current code, devres_release_all() only gets called if the device
has a bus and has been probed.

This leads to issues when using bus-less or driver-less devices where
the device might never get freed if a managed resource holds a reference
to the device. This is happening in the DRM framework for example.

We should thus call devres_release_all() in the device_del() function to
make sure that the device-managed actions are properly executed when the
device is unregistered, even if it has neither a bus nor a driver.

This is effectively the same change than commit 2f8d16a996 ("devres:
release resources on device_del()") that got reverted by commit
a525a3ddea ("driver core: free devres in device_release") over
memory leaks concerns.

This patch effectively combines the two commits mentioned above to
release the resources both on device_del() and device_release() and get
the best of both worlds.

Fixes: a525a3ddea ("driver core: free devres in device_release")
Signed-off-by: David Gow <davidgow@google.com>
Signed-off-by: Maxime Ripard <mripard@kernel.org>
Link: https://lore.kernel.org/r/20230720-kunit-devm-inconsistencies-test-v3-3-6aa7e074f373@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-09-13 09:48:31 +02:00
..
firmware_loader firmware_loader: Fix a NULL vs IS_ERR() check 2023-05-31 20:31:00 +01:00
power PM: sleep: wakeirq: fix wake irq arming 2023-08-03 10:26:13 +02:00
regmap regmap: rbtree: Use alloc_flags for memory allocations 2023-09-13 09:48:01 +02:00
test driver core: test_async: fix an error code 2023-09-13 09:48:29 +02:00
Kconfig driver core: Add CONFIG_FW_DEVLINK_SYNC_STATE_TIMEOUT 2023-03-28 18:45:59 +02:00
Makefile genirq: Get rid of GENERIC_MSI_IRQ_DOMAIN 2022-11-17 15:15:20 +01:00
arch_numa.c mm: percpu: add generic pcpu_populate_pte() function 2022-01-20 08:52:52 +02:00
arch_topology.c arch_topology: Remove early cacheinfo error message if -ENOENT 2023-04-14 10:13:38 +01:00
attribute_container.c driver core: attribute_container: fix W=1 warnings 2021-05-14 13:37:10 +02:00
auxiliary.c driver core: make struct bus_type.uevent() take a const * 2023-01-27 13:45:52 +01:00
base.h driver core: class: make class_register() take a const * 2023-04-03 21:42:46 +02:00
bus.c driver core: bus: constify bus_get() 2023-03-23 13:21:24 +01:00
cacheinfo.c drivers: base: cacheinfo: Update cpu_map_populated during CPU Hotplug 2023-05-31 20:36:47 +01:00
class.c driver core: class: properly reference count class_dev_iter() 2023-05-19 11:03:36 +01:00
component.c drivers: base: component: fix memory leak with using debugfs_lookup() 2023-02-08 13:33:10 +01:00
container.c
core.c drivers: base: Free devm resources when unregistering a device 2023-09-13 09:48:31 +02:00
cpu.c x86/srso: Add a Speculative RAS Overflow mitigation 2023-08-08 20:04:51 +02:00
dd.c driver core: Call dma_cleanup() on the test_remove path 2023-09-13 09:48:29 +02:00
devcoredump.c driver core: class: mark the struct class for sysfs callbacks as constant 2023-03-29 07:54:58 +02:00
devres.c devres: Pass unique name of the resource to devm_add_action() 2023-03-10 09:06:22 +01:00
devtmpfs.c driver core: clean up the logic to determine which /sys/dev/ directory to use 2023-03-31 17:45:07 +02:00
driver.c driver core: create bus_is_registered() 2023-02-09 10:43:35 +01:00
firmware.c
hypervisor.c
init.c init: Initialize noop_backing_dev_info early 2022-06-16 10:55:57 +02:00
isa.c bus: Make remove callback return void 2021-07-21 11:53:42 +02:00
map.c driver: base: Prefer unsigned int to bare use of unsigned 2021-07-21 17:30:09 +02:00
memory.c drivers/base/memory: Fix comments for phys_index_show() 2023-01-20 14:15:00 +01:00
module.c
node.c mm: memory-failure: add memory failure stats to sysfs 2023-02-02 22:33:28 -08:00
physical_location.c driver core: location: Free struct acpi_pld_info *pld before return false 2023-01-20 14:20:30 +01:00
physical_location.h driver core: physical_location.h remove extern from function prototypes 2023-03-24 15:35:48 +01:00
pinctrl.c
platform-msi.c genirq/msi, platform-msi: Ensure that MSI descriptors are unreferenced 2023-03-02 18:09:44 +01:00
platform.c driver core: platform: simplify __platform_driver_probe() 2023-02-01 14:08:10 +01:00
property.c drivers: fwnode: fix fwnode_irq_get[_byname]() 2023-07-19 16:36:37 +02:00
soc.c base: soc: populate machine name in soc_device_register if empty 2023-03-29 12:21:23 +02:00
swnode.c driver core: make kobj_type structures constant 2023-02-08 13:34:30 +01:00
syscore.c
topology.c drivers/base: fix userspace break from using bin_attributes for cpumap and cpulist 2022-07-15 17:36:33 +02:00
trace.c devres: Enable trace events 2021-06-15 17:14:36 +02:00
trace.h devres: Enable trace events 2021-06-15 17:14:36 +02:00
transport_class.c drivers: base: transport_class: fix resource leak when transport_add_device() fails 2023-01-20 14:22:53 +01:00