Skip to content

Commit c2fa1e1

Browse files
joelagnelPaul E. McKenney
authored andcommitted
driver/core: Convert to use built-in RCU list checking
This commit applies the consolidated hlist_for_each_entry_rcu() support for lockdep conditions. Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org> Signed-off-by: Paul E. McKenney <paulmck@linux.ibm.com>
1 parent 7fd69b0 commit c2fa1e1

3 files changed

Lines changed: 23 additions & 5 deletions

File tree

‎drivers/base/base.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ static inline int devtmpfs_init(void) { return 0; }
165165
/* Device links support */
166166
extern int device_links_read_lock(void);
167167
extern void device_links_read_unlock(int idx);
168+
extern int device_links_read_lock_held(void);
168169
extern int device_links_check_suppliers(struct device *dev);
169170
extern void device_links_driver_bound(struct device *dev);
170171
extern void device_links_driver_cleanup(struct device *dev);

‎drivers/base/core.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ void device_links_read_unlock(int idx)
6868
{
6969
srcu_read_unlock(&device_links_srcu, idx);
7070
}
71+
72+
int device_links_read_lock_held(void)
73+
{
74+
return srcu_read_lock_held(&device_links_srcu);
75+
}
7176
#else /* !CONFIG_SRCU */
7277
static DECLARE_RWSEM(device_links_lock);
7378

@@ -91,6 +96,13 @@ void device_links_read_unlock(int not_used)
9196
{
9297
up_read(&device_links_lock);
9398
}
99+
100+
#ifdef CONFIG_DEBUG_LOCK_ALLOC
101+
int device_links_read_lock_held(void)
102+
{
103+
return lockdep_is_held(&device_links_lock);
104+
}
105+
#endif
94106
#endif /* !CONFIG_SRCU */
95107

96108
/**

‎drivers/base/power/runtime.c‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ static int rpm_get_suppliers(struct device *dev)
287287
{
288288
struct device_link *link;
289289

290-
list_for_each_entry_rcu(link, &dev->links.suppliers, c_node) {
290+
list_for_each_entry_rcu(link, &dev->links.suppliers, c_node,
291+
device_links_read_lock_held()) {
291292
int retval;
292293

293294
if (!(link->flags & DL_FLAG_PM_RUNTIME) ||
@@ -309,7 +310,8 @@ static void rpm_put_suppliers(struct device *dev)
309310
{
310311
struct device_link *link;
311312

312-
list_for_each_entry_rcu(link, &dev->links.suppliers, c_node) {
313+
list_for_each_entry_rcu(link, &dev->links.suppliers, c_node,
314+
device_links_read_lock_held()) {
313315
if (READ_ONCE(link->status) == DL_STATE_SUPPLIER_UNBIND)
314316
continue;
315317

@@ -1640,7 +1642,8 @@ void pm_runtime_clean_up_links(struct device *dev)
16401642

16411643
idx = device_links_read_lock();
16421644

1643-
list_for_each_entry_rcu(link, &dev->links.consumers, s_node) {
1645+
list_for_each_entry_rcu(link, &dev->links.consumers, s_node,
1646+
device_links_read_lock_held()) {
16441647
if (link->flags & DL_FLAG_STATELESS)
16451648
continue;
16461649

@@ -1662,7 +1665,8 @@ void pm_runtime_get_suppliers(struct device *dev)
16621665

16631666
idx = device_links_read_lock();
16641667

1665-
list_for_each_entry_rcu(link, &dev->links.suppliers, c_node)
1668+
list_for_each_entry_rcu(link, &dev->links.suppliers, c_node,
1669+
device_links_read_lock_held())
16661670
if (link->flags & DL_FLAG_PM_RUNTIME) {
16671671
link->supplier_preactivated = true;
16681672
refcount_inc(&link->rpm_active);
@@ -1683,7 +1687,8 @@ void pm_runtime_put_suppliers(struct device *dev)
16831687

16841688
idx = device_links_read_lock();
16851689

1686-
list_for_each_entry_rcu(link, &dev->links.suppliers, c_node)
1690+
list_for_each_entry_rcu(link, &dev->links.suppliers, c_node,
1691+
device_links_read_lock_held())
16871692
if (link->supplier_preactivated) {
16881693
link->supplier_preactivated = false;
16891694
if (refcount_dec_not_one(&link->rpm_active))

0 commit comments

Comments
 (0)