linux-stable/drivers/base
Herve Codina 9406d598a1 driver core: Introduce device_link_wait_removal()
commit 0462c56c29 upstream.

The commit 80dd33cf72 ("drivers: base: Fix device link removal")
introduces a workqueue to release the consumer and supplier devices used
in the devlink.
In the job queued, devices are release and in turn, when all the
references to these devices are dropped, the release function of the
device itself is called.

Nothing is present to provide some synchronisation with this workqueue
in order to ensure that all ongoing releasing operations are done and
so, some other operations can be started safely.

For instance, in the following sequence:
  1) of_platform_depopulate()
  2) of_overlay_remove()

During the step 1, devices are released and related devlinks are removed
(jobs pushed in the workqueue).
During the step 2, OF nodes are destroyed but, without any
synchronisation with devlink removal jobs, of_overlay_remove() can raise
warnings related to missing of_node_put():
  ERROR: memory leak, expected refcount 1 instead of 2

Indeed, the missing of_node_put() call is going to be done, too late,
from the workqueue job execution.

Introduce device_link_wait_removal() to offer a way to synchronize
operations waiting for the end of devlink removals (i.e. end of
workqueue jobs).
Also, as a flushing operation is done on the workqueue, the workqueue
used is moved from a system-wide workqueue to a local one.

Cc: stable@vger.kernel.org
Signed-off-by: Herve Codina <herve.codina@bootlin.com>
Tested-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
Reviewed-by: Nuno Sa <nuno.sa@analog.com>
Reviewed-by: Saravana Kannan <saravanak@google.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://lore.kernel.org/r/20240325152140.198219-2-herve.codina@bootlin.com
Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-04-10 16:28:32 +02:00
..
firmware_loader firmware_loader: Fix memory leak in firmware upload 2022-09-01 17:47:27 +02:00
power PM: sleep: wakeirq: fix wake irq warning in system suspend 2024-04-03 15:19:30 +02:00
regmap regmap: fix bogus error on regcache_sync success 2023-12-13 18:39:20 +01:00
test driver core: test_async: fix an error code 2023-09-13 09:42:53 +02:00
Kconfig devtmpfs: mount with noexec and nosuid 2021-12-30 13:54:42 +01:00
Makefile driver core: Add sysfs support for physical location of a device 2022-04-27 09:51:57 +02:00
arch_numa.c arm64: irq: set the correct node for VMAP stack 2024-02-05 20:12:46 +00:00
arch_topology.c RISC-V Patches for the 6.1 Merge Window, Part 1 2022-10-09 13:24:01 -07:00
attribute_container.c driver core: attribute_container: fix W=1 warnings 2021-05-14 13:37:10 +02:00
auxiliary.c Documentation/auxiliary_bus: Move the text into the code 2021-12-03 16:41:50 +01:00
base.h driver core: remove make_class_name declaration 2022-09-09 10:49:54 +02:00
bus.c driver: base: fix UAF when driver_attach failed 2022-05-19 19:28:42 +02:00
cacheinfo.c drivers: base: cacheinfo: Fix shared_cpu_map changes in event of CPU hotplug 2023-06-09 10:34:17 +02:00
class.c class: fix possible memory leak in __class_register() 2022-12-31 13:32:38 +01:00
component.c drivers: base: component: fix memory leak with using debugfs_lookup() 2023-03-11 13:55:39 +01:00
container.c
core.c driver core: Introduce device_link_wait_removal() 2024-04-10 16:28:32 +02:00
cpu.c x86/rfds: Mitigate Register File Data Sampling (RFDS) 2024-03-15 10:48:21 -04:00
dd.c driver core: Release all resources during unbind before updating device links 2023-11-28 17:07:13 +00:00
devcoredump.c devcoredump: Send uevent once devcd is ready 2023-12-13 18:39:28 +01:00
devres.c devres: Slightly optimize alloc_dr() 2022-09-01 18:17:14 +02:00
devtmpfs.c devtmpfs: fix the dangling pointer of global devtmpfsd thread 2022-06-27 16:41:13 +02:00
driver.c driver core: fix driver_set_override() issue with empty strings 2022-09-05 13:01:34 +02: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 mm/memory_hotplug: add missing mem_hotplug_lock 2024-01-10 17:10:33 +01:00
module.c
node.c base/node.c: initialize the accessor list before registering 2024-01-25 15:27:46 -08:00
physical_location.c driver core: location: Free struct acpi_pld_info *pld before return false 2023-03-10 09:33:33 +01:00
physical_location.h driver core: Add sysfs support for physical location of a device 2022-04-27 09:51:57 +02:00
pinctrl.c
platform-msi.c platform-msi: Export symbol platform_msi_create_irq_domain() 2022-09-28 14:21:05 +01:00
platform.c platform: Provide a remove callback that returns no value 2023-05-24 17:32:43 +01:00
property.c device property: Allow const parameter to dev_fwnode() 2024-01-05 15:18:40 +01:00
soc.c base: soc: Make soc_device_match() simpler and easier to read 2022-03-18 14:28:07 +01:00
swnode.c software node: Let args be NULL in software_node_get_reference_args 2024-01-25 15:27:46 -08: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-03-10 09:33:34 +01:00