Skip to content

Commit b0cde62

Browse files
Uwe Kleine-Königbebarino
authored andcommitted
clk: Add a devm variant of clk_rate_exclusive_get()
This allows to simplify drivers that use clk_rate_exclusive_get() in their probe routine as calling clk_rate_exclusive_put() is cared for automatically. Signed-off-by: Uwe Kleine-König <[email protected]> Link: https://lore.kernel.org/r/[email protected] Acked-by: Russell King (Oracle) <[email protected]> Signed-off-by: Stephen Boyd <[email protected]>
1 parent 6613476 commit b0cde62

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

drivers/clk/clk.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,25 @@ int clk_rate_exclusive_get(struct clk *clk)
939939
}
940940
EXPORT_SYMBOL_GPL(clk_rate_exclusive_get);
941941

942+
static void devm_clk_rate_exclusive_put(void *data)
943+
{
944+
struct clk *clk = data;
945+
946+
clk_rate_exclusive_put(clk);
947+
}
948+
949+
int devm_clk_rate_exclusive_get(struct device *dev, struct clk *clk)
950+
{
951+
int ret;
952+
953+
ret = clk_rate_exclusive_get(clk);
954+
if (ret)
955+
return ret;
956+
957+
return devm_add_action_or_reset(dev, devm_clk_rate_exclusive_put, clk);
958+
}
959+
EXPORT_SYMBOL_GPL(devm_clk_rate_exclusive_get);
960+
942961
static void clk_core_unprepare(struct clk_core *core)
943962
{
944963
lockdep_assert_held(&prepare_lock);

include/linux/clk.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,18 @@ bool clk_is_match(const struct clk *p, const struct clk *q);
201201
*/
202202
int clk_rate_exclusive_get(struct clk *clk);
203203

204+
/**
205+
* devm_clk_rate_exclusive_get - devm variant of clk_rate_exclusive_get
206+
* @dev: device the exclusivity is bound to
207+
* @clk: clock source
208+
*
209+
* Calls clk_rate_exclusive_get() on @clk and registers a devm cleanup handler
210+
* on @dev to call clk_rate_exclusive_put().
211+
*
212+
* Must not be called from within atomic context.
213+
*/
214+
int devm_clk_rate_exclusive_get(struct device *dev, struct clk *clk);
215+
204216
/**
205217
* clk_rate_exclusive_put - release exclusivity over the rate control of a
206218
* producer

0 commit comments

Comments
 (0)