Skip to content

Commit 1689cac

Browse files
vivekgautam1rafaeljw
authored andcommitted
driver core: Add flag to autoremove device link on supplier unbind
Add a flag to autoremove the device links on supplier driver unbind. This obviates the need to explicitly delete the link in the remove path. We remove these links only when the supplier's link to its consumers has gone to DL_STATE_SUPPLIER_UNBIND state. Signed-off-by: Vivek Gautam <vivek.gautam@codeaurora.org> Suggested-by: Lukas Wunner <lukas@wunner.de> Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent e88728f commit 1689cac

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

‎Documentation/driver-api/device_link.rst‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ automatically purged when the consumer fails to probe or later unbinds.
8686
This obviates the need to explicitly delete the link in the ``->remove``
8787
callback or in the error path of the ``->probe`` callback.
8888

89+
Similarly, when the device link is added from supplier's ``->probe`` callback,
90+
``DL_FLAG_AUTOREMOVE_SUPPLIER`` causes the device link to be automatically
91+
purged when the supplier fails to probe or later unbinds.
92+
8993
Limitations
9094
===========
9195

‎drivers/base/core.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,16 @@ void device_links_driver_cleanup(struct device *dev)
518518

519519
WARN_ON(link->flags & DL_FLAG_AUTOREMOVE_CONSUMER);
520520
WARN_ON(link->status != DL_STATE_SUPPLIER_UNBIND);
521+
522+
/*
523+
* autoremove the links between this @dev and its consumer
524+
* devices that are not active, i.e. where the link state
525+
* has moved to DL_STATE_SUPPLIER_UNBIND.
526+
*/
527+
if (link->status == DL_STATE_SUPPLIER_UNBIND &&
528+
link->flags & DL_FLAG_AUTOREMOVE_SUPPLIER)
529+
kref_put(&link->kref, __device_link_del);
530+
521531
WRITE_ONCE(link->status, DL_STATE_DORMANT);
522532
}
523533

‎include/linux/device.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,11 +787,13 @@ enum device_link_state {
787787
* AUTOREMOVE_CONSUMER: Remove the link automatically on consumer driver unbind.
788788
* PM_RUNTIME: If set, the runtime PM framework will use this link.
789789
* RPM_ACTIVE: Run pm_runtime_get_sync() on the supplier during link creation.
790+
* AUTOREMOVE_SUPPLIER: Remove the link automatically on supplier driver unbind.
790791
*/
791792
#define DL_FLAG_STATELESS BIT(0)
792793
#define DL_FLAG_AUTOREMOVE_CONSUMER BIT(1)
793794
#define DL_FLAG_PM_RUNTIME BIT(2)
794795
#define DL_FLAG_RPM_ACTIVE BIT(3)
796+
#define DL_FLAG_AUTOREMOVE_SUPPLIER BIT(4)
795797

796798
/**
797799
* struct device_link - Device link representation.

0 commit comments

Comments
 (0)