Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Vivek Gautam and committed by
Rafael J. Wysocki
1689cac5 e88728f4

+16
+4
Documentation/driver-api/device_link.rst
··· 86 86 This obviates the need to explicitly delete the link in the ``->remove`` 87 87 callback or in the error path of the ``->probe`` callback. 88 88 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 + 89 93 Limitations 90 94 =========== 91 95
+10
drivers/base/core.c
··· 518 518 519 519 WARN_ON(link->flags & DL_FLAG_AUTOREMOVE_CONSUMER); 520 520 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 + 521 531 WRITE_ONCE(link->status, DL_STATE_DORMANT); 522 532 } 523 533
+2
include/linux/device.h
··· 787 787 * AUTOREMOVE_CONSUMER: Remove the link automatically on consumer driver unbind. 788 788 * PM_RUNTIME: If set, the runtime PM framework will use this link. 789 789 * RPM_ACTIVE: Run pm_runtime_get_sync() on the supplier during link creation. 790 + * AUTOREMOVE_SUPPLIER: Remove the link automatically on supplier driver unbind. 790 791 */ 791 792 #define DL_FLAG_STATELESS BIT(0) 792 793 #define DL_FLAG_AUTOREMOVE_CONSUMER BIT(1) 793 794 #define DL_FLAG_PM_RUNTIME BIT(2) 794 795 #define DL_FLAG_RPM_ACTIVE BIT(3) 796 + #define DL_FLAG_AUTOREMOVE_SUPPLIER BIT(4) 795 797 796 798 /** 797 799 * struct device_link - Device link representation.