linux-stable/drivers/base
Herve Codina 7f62d985e9 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-13 12:59:34 +02:00
..
firmware_loader firmware_loader: use kernel credentials when reading firmware 2022-05-18 10:23:46 +02:00
power PM: sleep: wakeirq: fix wake irq warning in system suspend 2024-04-13 12:58:18 +02:00
regmap regmap: Add missing map->bus check 2024-03-26 18:22:04 -04:00
test driver core: test_async: fix an error code 2023-09-19 12:20:18 +02:00
Kconfig
Makefile device property: Move fwnode_connection_find_match() under drivers/base/property.c 2020-09-08 13:32:06 +02:00
arch_topology.c arm64: topology: move store_cpu_topology() to shared code 2022-10-30 09:41:19 +01:00
attribute_container.c
base.h
bus.c driver: base: fix UAF when driver_attach failed 2022-06-14 18:32:34 +02:00
cacheinfo.c drivers core: Use sysfs_emit for shared_cpu_map_show and shared_cpu_list_show 2020-10-02 13:24:40 +02:00
class.c class: fix possible memory leak in __class_register() 2023-01-14 10:15:54 +01:00
component.c
container.c
core.c driver core: Introduce device_link_wait_removal() 2024-04-13 12:59:34 +02:00
cpu.c x86/rfds: Mitigate Register File Data Sampling (RFDS) 2024-04-13 12:58:59 +02:00
dd.c driver core: Release all resources during unbind before updating device links 2023-12-08 08:46:16 +01:00
devcoredump.c devcoredump: Send uevent once devcd is ready 2023-12-13 18:27:07 +01:00
devres.c devres: provide devm_krealloc() 2020-09-08 13:32:06 +02:00
devtmpfs.c devtmpfs regression fix: reconfigure on each mount 2022-01-20 09:17:49 +01:00
driver.c driver: platform: Add helper for safer setting of driver_override 2023-11-08 17:30:47 +01:00
firmware.c
hypervisor.c
init.c
isa.c
map.c
memory.c drivers/base/memory: fix an unlikely reference counting issue in __add_memory_block() 2022-06-09 10:21:16 +02:00
module.c
node.c drivers/base/node.c: fix compaction sysfs file leak 2022-06-09 10:21:16 +02:00
pinctrl.c
platform-msi.c
platform.c driver: platform: Add helper for safer setting of driver_override 2023-11-08 17:30:47 +01:00
property.c device property: Fix fwnode_graph_devcon_match() fwnode leak 2022-01-27 10:54:25 +01:00
soc.c drivers core: Miscellaneous changes for sysfs_emit 2020-10-02 13:12:07 +02:00
swnode.c software node: Let args be NULL in software_node_get_reference_args 2024-01-25 14:37:54 -08:00
syscore.c syscore: Use pm_pr_dbg() for syscore_{suspend,resume}() 2020-09-08 13:32:06 +02:00
topology.c drivers core: Miscellaneous changes for sysfs_emit 2020-10-02 13:12:07 +02:00
transport_class.c