Skip to content

Commit 0469a43

Browse files
author
Mike Turquette
committed
Merge branch 'clk-next-debugfs-lock' into clk-next
2 parents 2fed71e + 6314b67 commit 0469a43

2 files changed

Lines changed: 28 additions & 46 deletions

File tree

‎drivers/clk/clk.c‎

Lines changed: 27 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ static void clk_enable_unlock(unsigned long flags)
100100

101101
static struct dentry *rootdir;
102102
static int inited = 0;
103+
static DEFINE_MUTEX(clk_debug_lock);
104+
static HLIST_HEAD(clk_debug_list);
103105

104106
static struct hlist_head *all_lists[] = {
105107
&clk_root_list,
@@ -300,49 +302,28 @@ static int clk_debug_create_one(struct clk *clk, struct dentry *pdentry)
300302
return ret;
301303
}
302304

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-
325305
/**
326306
* clk_debug_register - add a clk node to the debugfs clk tree
327307
* @clk: the clk being added to the debugfs clk tree
328308
*
329309
* Dynamically adds a clk to the debugfs clk tree if debugfs has been
330310
* initialized. Otherwise it bails out early since the debugfs clk tree
331311
* 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.
335312
*/
336313
static int clk_debug_register(struct clk *clk)
337314
{
338315
int ret = 0;
339316

317+
mutex_lock(&clk_debug_lock);
318+
hlist_add_head(&clk->debug_node, &clk_debug_list);
319+
340320
if (!inited)
341-
goto out;
321+
goto unlock;
342322

343-
ret = clk_debug_create_subtree(clk, rootdir);
323+
ret = clk_debug_create_one(clk, rootdir);
324+
unlock:
325+
mutex_unlock(&clk_debug_lock);
344326

345-
out:
346327
return ret;
347328
}
348329

@@ -353,12 +334,18 @@ static int clk_debug_register(struct clk *clk)
353334
* Dynamically removes a clk and all it's children clk nodes from the
354335
* debugfs clk tree if clk->dentry points to debugfs created by
355336
* clk_debug_register in __clk_init.
356-
*
357-
* Caller must hold prepare_lock.
358337
*/
359338
static void clk_debug_unregister(struct clk *clk)
360339
{
340+
mutex_lock(&clk_debug_lock);
341+
if (!clk->dentry)
342+
goto out;
343+
344+
hlist_del_init(&clk->debug_node);
361345
debugfs_remove_recursive(clk->dentry);
346+
clk->dentry = NULL;
347+
out:
348+
mutex_unlock(&clk_debug_lock);
362349
}
363350

364351
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)
415402
if (!d)
416403
return -ENOMEM;
417404

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);
425408

426409
inited = 1;
427-
428-
clk_prepare_unlock();
410+
mutex_unlock(&clk_debug_lock);
429411

430412
return 0;
431413
}
@@ -2087,14 +2069,16 @@ void clk_unregister(struct clk *clk)
20872069
{
20882070
unsigned long flags;
20892071

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);
20922076

20932077
clk_prepare_lock();
20942078

20952079
if (clk->ops == &clk_nodrv_ops) {
20962080
pr_err("%s: unregistered clock: %s\n", __func__, clk->name);
2097-
goto out;
2081+
return;
20982082
}
20992083
/*
21002084
* Assign empty clock ops for consumers that might still hold
@@ -2113,16 +2097,13 @@ void clk_unregister(struct clk *clk)
21132097
clk_set_parent(child, NULL);
21142098
}
21152099

2116-
clk_debug_unregister(clk);
2117-
21182100
hlist_del_init(&clk->child_node);
21192101

21202102
if (clk->prepare_count)
21212103
pr_warn("%s: unregistering prepared clock: %s\n",
21222104
__func__, clk->name);
2123-
21242105
kref_put(&clk->ref, __clk_release);
2125-
out:
2106+
21262107
clk_prepare_unlock();
21272108
}
21282109
EXPORT_SYMBOL_GPL(clk_unregister);

‎include/linux/clk-private.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ struct clk {
4848
unsigned long accuracy;
4949
struct hlist_head children;
5050
struct hlist_node child_node;
51+
struct hlist_node debug_node;
5152
unsigned int notifier_count;
5253
#ifdef CONFIG_DEBUG_FS
5354
struct dentry *dentry;

0 commit comments

Comments
 (0)