Skip to content

Commit 6b57b15

Browse files
Saravana Kannangregkh
authored andcommitted
driver core: Fix device_pm_lock() locking for device links
This commit fixes two issues: 1. The lockdep warning reported by Dong Aisheng <dongas86@gmail.com> [1]. It is a warning about a cycle (dpm_list_mtx --> kn->active#3 --> fw_lock) that was introduced when device-link devices were added to expose device link information in sysfs. The patch that "introduced" this cycle can't be reverted because it's fixes a real SRCU issue and also ensures that the device-link device is deleted as soon as the device-link is deleted. This is important to avoid sysfs name collisions if the device-link is create again immediately (this can happen a lot with deferred probing). 2. Inconsistency in grabbing device_pm_lock() during device link deletion Some device link deletion code paths grab device_pm_lock(), while others don't. The device_pm_lock() is grabbed during device_link_add() because it checks if the supplier is in the dpm_list and also reorders the dpm_list. However, when a device link is deleted, it does not do either of those and therefore device_pm_lock() is not necessary. Dropping the device_pm_lock() in all the device link deletion paths removes the inconsistency in locking. Thanks to Stephen Boyd for helping me understand the lockdep splat. Fixes: 843e600 ("driver core: Fix sleeping in invalid context during device link deletion") [1] - https://lore.kernel.org/lkml/CAA+hA=S4eAreb7vo69LAXSk2t5=DEKNxHaiY1wSpk4xTp9urLg@mail.gmail.com/ Reported-by: Dong Aisheng <dongas86@gmail.com> Signed-off-by: Saravana Kannan <saravanak@google.com> Tested-by: Peng Fan <peng.fan@nxp.com> Link: https://lore.kernel.org/r/20200901184445.1736658-1-saravanak@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 51de18b commit 6b57b15

File tree

1 file changed

+0
-4
lines changed

1 file changed

+0
-4
lines changed

drivers/base/core.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -807,9 +807,7 @@ static void device_link_put_kref(struct device_link *link)
807807
void device_link_del(struct device_link *link)
808808
{
809809
device_links_write_lock();
810-
device_pm_lock();
811810
device_link_put_kref(link);
812-
device_pm_unlock();
813811
device_links_write_unlock();
814812
}
815813
EXPORT_SYMBOL_GPL(device_link_del);
@@ -830,7 +828,6 @@ void device_link_remove(void *consumer, struct device *supplier)
830828
return;
831829

832830
device_links_write_lock();
833-
device_pm_lock();
834831

835832
list_for_each_entry(link, &supplier->links.consumers, s_node) {
836833
if (link->consumer == consumer) {
@@ -839,7 +836,6 @@ void device_link_remove(void *consumer, struct device *supplier)
839836
}
840837
}
841838

842-
device_pm_unlock();
843839
device_links_write_unlock();
844840
}
845841
EXPORT_SYMBOL_GPL(device_link_remove);

0 commit comments

Comments
 (0)