@@ -100,6 +100,8 @@ static void clk_enable_unlock(unsigned long flags)
100
100
101
101
static struct dentry * rootdir ;
102
102
static int inited = 0 ;
103
+ static DEFINE_MUTEX (clk_debug_lock );
104
+ static HLIST_HEAD (clk_debug_list );
103
105
104
106
static struct hlist_head * all_lists [] = {
105
107
& clk_root_list ,
@@ -300,49 +302,28 @@ static int clk_debug_create_one(struct clk *clk, struct dentry *pdentry)
300
302
return ret ;
301
303
}
302
304
303
- /* caller must hold prepare_lock */
304
- static int clk_debug_create_subtree (struct clk * clk , struct dentry * pdentry )
305
- {
306
- struct clk * child ;
307
- int ret = - EINVAL ;;
308
-
309
- if (!clk || !pdentry )
310
- goto out ;
311
-
312
- ret = clk_debug_create_one (clk , pdentry );
313
-
314
- if (ret )
315
- goto out ;
316
-
317
- hlist_for_each_entry (child , & clk -> children , child_node )
318
- clk_debug_create_subtree (child , pdentry );
319
-
320
- ret = 0 ;
321
- out :
322
- return ret ;
323
- }
324
-
325
305
/**
326
306
* clk_debug_register - add a clk node to the debugfs clk tree
327
307
* @clk: the clk being added to the debugfs clk tree
328
308
*
329
309
* Dynamically adds a clk to the debugfs clk tree if debugfs has been
330
310
* initialized. Otherwise it bails out early since the debugfs clk tree
331
311
* will be created lazily by clk_debug_init as part of a late_initcall.
332
- *
333
- * Caller must hold prepare_lock. Only clk_init calls this function (so
334
- * far) so this is taken care.
335
312
*/
336
313
static int clk_debug_register (struct clk * clk )
337
314
{
338
315
int ret = 0 ;
339
316
317
+ mutex_lock (& clk_debug_lock );
318
+ hlist_add_head (& clk -> debug_node , & clk_debug_list );
319
+
340
320
if (!inited )
341
- goto out ;
321
+ goto unlock ;
342
322
343
- ret = clk_debug_create_subtree (clk , rootdir );
323
+ ret = clk_debug_create_one (clk , rootdir );
324
+ unlock :
325
+ mutex_unlock (& clk_debug_lock );
344
326
345
- out :
346
327
return ret ;
347
328
}
348
329
@@ -353,12 +334,18 @@ static int clk_debug_register(struct clk *clk)
353
334
* Dynamically removes a clk and all it's children clk nodes from the
354
335
* debugfs clk tree if clk->dentry points to debugfs created by
355
336
* clk_debug_register in __clk_init.
356
- *
357
- * Caller must hold prepare_lock.
358
337
*/
359
338
static void clk_debug_unregister (struct clk * clk )
360
339
{
340
+ mutex_lock (& clk_debug_lock );
341
+ if (!clk -> dentry )
342
+ goto out ;
343
+
344
+ hlist_del_init (& clk -> debug_node );
361
345
debugfs_remove_recursive (clk -> dentry );
346
+ clk -> dentry = NULL ;
347
+ out :
348
+ mutex_unlock (& clk_debug_lock );
362
349
}
363
350
364
351
struct dentry * clk_debugfs_add_file (struct clk * clk , char * name , umode_t mode ,
@@ -415,17 +402,12 @@ static int __init clk_debug_init(void)
415
402
if (!d )
416
403
return - ENOMEM ;
417
404
418
- clk_prepare_lock ();
419
-
420
- hlist_for_each_entry (clk , & clk_root_list , child_node )
421
- clk_debug_create_subtree (clk , rootdir );
422
-
423
- hlist_for_each_entry (clk , & clk_orphan_list , child_node )
424
- clk_debug_create_subtree (clk , rootdir );
405
+ mutex_lock (& clk_debug_lock );
406
+ hlist_for_each_entry (clk , & clk_debug_list , debug_node )
407
+ clk_debug_create_one (clk , rootdir );
425
408
426
409
inited = 1 ;
427
-
428
- clk_prepare_unlock ();
410
+ mutex_unlock (& clk_debug_lock );
429
411
430
412
return 0 ;
431
413
}
@@ -2087,14 +2069,16 @@ void clk_unregister(struct clk *clk)
2087
2069
{
2088
2070
unsigned long flags ;
2089
2071
2090
- if (!clk || WARN_ON_ONCE (IS_ERR (clk )))
2091
- return ;
2072
+ if (!clk || WARN_ON_ONCE (IS_ERR (clk )))
2073
+ return ;
2074
+
2075
+ clk_debug_unregister (clk );
2092
2076
2093
2077
clk_prepare_lock ();
2094
2078
2095
2079
if (clk -> ops == & clk_nodrv_ops ) {
2096
2080
pr_err ("%s: unregistered clock: %s\n" , __func__ , clk -> name );
2097
- goto out ;
2081
+ return ;
2098
2082
}
2099
2083
/*
2100
2084
* Assign empty clock ops for consumers that might still hold
@@ -2113,16 +2097,13 @@ void clk_unregister(struct clk *clk)
2113
2097
clk_set_parent (child , NULL );
2114
2098
}
2115
2099
2116
- clk_debug_unregister (clk );
2117
-
2118
2100
hlist_del_init (& clk -> child_node );
2119
2101
2120
2102
if (clk -> prepare_count )
2121
2103
pr_warn ("%s: unregistering prepared clock: %s\n" ,
2122
2104
__func__ , clk -> name );
2123
-
2124
2105
kref_put (& clk -> ref , __clk_release );
2125
- out :
2106
+
2126
2107
clk_prepare_unlock ();
2127
2108
}
2128
2109
EXPORT_SYMBOL_GPL (clk_unregister );
0 commit comments