Skip to content

Commit

Permalink
clk: add devm variant of clk_notifier_register
Browse files Browse the repository at this point in the history
Add a memory managed variant of clk_notifier_register() to make life easier
on clock consumers using notifiers

Signed-off-by: Jerome Brunet <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Stephen Boyd <[email protected]>
  • Loading branch information
jbrun3t authored and bebarino committed Nov 14, 2020
1 parent 8e677e7 commit 6d30d50
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
36 changes: 36 additions & 0 deletions drivers/clk/clk.c
Original file line number Diff line number Diff line change
Expand Up @@ -4395,6 +4395,42 @@ int clk_notifier_unregister(struct clk *clk, struct notifier_block *nb)
}
EXPORT_SYMBOL_GPL(clk_notifier_unregister);

struct clk_notifier_devres {
struct clk *clk;
struct notifier_block *nb;
};

static void devm_clk_notifier_release(struct device *dev, void *res)
{
struct clk_notifier_devres *devres = res;

clk_notifier_unregister(devres->clk, devres->nb);
}

int devm_clk_notifier_register(struct device *dev, struct clk *clk,
struct notifier_block *nb)
{
struct clk_notifier_devres *devres;
int ret;

devres = devres_alloc(devm_clk_notifier_release,
sizeof(*devres), GFP_KERNEL);

if (!devres)
return -ENOMEM;

ret = clk_notifier_register(clk, nb);
if (!ret) {
devres->clk = clk;
devres->nb = nb;
} else {
devres_free(devres);
}

return ret;
}
EXPORT_SYMBOL_GPL(devm_clk_notifier_register);

#ifdef CONFIG_OF
static void clk_core_reparent_orphans(void)
{
Expand Down
10 changes: 10 additions & 0 deletions include/linux/clk.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ int clk_notifier_register(struct clk *clk, struct notifier_block *nb);
*/
int clk_notifier_unregister(struct clk *clk, struct notifier_block *nb);

/**
* devm_clk_notifier_register - register a managed rate-change notifier callback
* @dev: device for clock "consumer"
* @clk: clock whose rate we are interested in
* @nb: notifier block with callback function pointer
*
* Returns 0 on success, -EERROR otherwise
*/
int devm_clk_notifier_register(struct device *dev, struct clk *clk, struct notifier_block *nb);

/**
* clk_get_accuracy - obtain the clock accuracy in ppb (parts per billion)
* for a clock source.
Expand Down

0 comments on commit 6d30d50

Please sign in to comment.