@@ -194,6 +194,17 @@ int device_links_read_lock_held(void)
194
194
{
195
195
return srcu_read_lock_held (& device_links_srcu );
196
196
}
197
+
198
+ static void device_link_synchronize_removal (void )
199
+ {
200
+ synchronize_srcu (& device_links_srcu );
201
+ }
202
+
203
+ static void device_link_remove_from_lists (struct device_link * link )
204
+ {
205
+ list_del_rcu (& link -> s_node );
206
+ list_del_rcu (& link -> c_node );
207
+ }
197
208
#else /* !CONFIG_SRCU */
198
209
static DECLARE_RWSEM (device_links_lock );
199
210
@@ -224,6 +235,16 @@ int device_links_read_lock_held(void)
224
235
return lockdep_is_held (& device_links_lock );
225
236
}
226
237
#endif
238
+
239
+ static inline void device_link_synchronize_removal (void )
240
+ {
241
+ }
242
+
243
+ static void device_link_remove_from_lists (struct device_link * link )
244
+ {
245
+ list_del (& link -> s_node );
246
+ list_del (& link -> c_node );
247
+ }
227
248
#endif /* !CONFIG_SRCU */
228
249
229
250
static bool device_is_ancestor (struct device * dev , struct device * target )
@@ -445,8 +466,13 @@ static struct attribute *devlink_attrs[] = {
445
466
};
446
467
ATTRIBUTE_GROUPS (devlink );
447
468
448
- static void device_link_free (struct device_link * link )
469
+ static void device_link_release_fn (struct work_struct * work )
449
470
{
471
+ struct device_link * link = container_of (work , struct device_link , rm_work );
472
+
473
+ /* Ensure that all references to the link object have been dropped. */
474
+ device_link_synchronize_removal ();
475
+
450
476
while (refcount_dec_not_one (& link -> rpm_active ))
451
477
pm_runtime_put (link -> supplier );
452
478
@@ -455,24 +481,19 @@ static void device_link_free(struct device_link *link)
455
481
kfree (link );
456
482
}
457
483
458
- #ifdef CONFIG_SRCU
459
- static void __device_link_free_srcu (struct rcu_head * rhead )
460
- {
461
- device_link_free (container_of (rhead , struct device_link , rcu_head ));
462
- }
463
-
464
484
static void devlink_dev_release (struct device * dev )
465
485
{
466
486
struct device_link * link = to_devlink (dev );
467
487
468
- call_srcu (& device_links_srcu , & link -> rcu_head , __device_link_free_srcu );
469
- }
470
- #else
471
- static void devlink_dev_release (struct device * dev )
472
- {
473
- device_link_free (to_devlink (dev ));
488
+ INIT_WORK (& link -> rm_work , device_link_release_fn );
489
+ /*
490
+ * It may take a while to complete this work because of the SRCU
491
+ * synchronization in device_link_release_fn() and if the consumer or
492
+ * supplier devices get deleted when it runs, so put it into the "long"
493
+ * workqueue.
494
+ */
495
+ queue_work (system_long_wq , & link -> rm_work );
474
496
}
475
- #endif
476
497
477
498
static struct class devlink_class = {
478
499
.name = "devlink" ,
@@ -846,7 +867,6 @@ struct device_link *device_link_add(struct device *consumer,
846
867
}
847
868
EXPORT_SYMBOL_GPL (device_link_add );
848
869
849
- #ifdef CONFIG_SRCU
850
870
static void __device_link_del (struct kref * kref )
851
871
{
852
872
struct device_link * link = container_of (kref , struct device_link , kref );
@@ -856,25 +876,9 @@ static void __device_link_del(struct kref *kref)
856
876
857
877
pm_runtime_drop_link (link );
858
878
859
- list_del_rcu (& link -> s_node );
860
- list_del_rcu (& link -> c_node );
861
- device_unregister (& link -> link_dev );
862
- }
863
- #else /* !CONFIG_SRCU */
864
- static void __device_link_del (struct kref * kref )
865
- {
866
- struct device_link * link = container_of (kref , struct device_link , kref );
867
-
868
- dev_info (link -> consumer , "Dropping the link to %s\n" ,
869
- dev_name (link -> supplier ));
870
-
871
- pm_runtime_drop_link (link );
872
-
873
- list_del (& link -> s_node );
874
- list_del (& link -> c_node );
879
+ device_link_remove_from_lists (link );
875
880
device_unregister (& link -> link_dev );
876
881
}
877
- #endif /* !CONFIG_SRCU */
878
882
879
883
static void device_link_put_kref (struct device_link * link )
880
884
{
0 commit comments