Skip to content

Commit 7d2f353

Browse files
committed
Merge tag 'clk-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/clk/linux
Pull clk fixes from Stephen Boyd: "One clk driver fix and two clk framework fixes: - Fix an OOB access when devm_get_clk_from_child() is used and devm_clk_release() casts the void pointer to the wrong type - Move clk_rate_exclusive_{get,put}() within the correct ifdefs in clk.h so that the stubs are used when CONFIG_COMMON_CLK=n - Register the proper clk provider function depending on the value of #clock-cells in the TI keystone driver" * tag 'clk-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/clk/linux: clk: Fix slab-out-of-bounds error in devm_clk_release() clk: Fix undefined reference to `clk_rate_exclusive_{get,put}' clk: keystone: syscon-clk: Fix audio refclk
2 parents 382d4cd + 66fbfb3 commit 7d2f353

File tree

3 files changed

+51
-48
lines changed

3 files changed

+51
-48
lines changed

drivers/clk/clk-devres.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,18 +205,19 @@ EXPORT_SYMBOL(devm_clk_put);
205205
struct clk *devm_get_clk_from_child(struct device *dev,
206206
struct device_node *np, const char *con_id)
207207
{
208-
struct clk **ptr, *clk;
208+
struct devm_clk_state *state;
209+
struct clk *clk;
209210

210-
ptr = devres_alloc(devm_clk_release, sizeof(*ptr), GFP_KERNEL);
211-
if (!ptr)
211+
state = devres_alloc(devm_clk_release, sizeof(*state), GFP_KERNEL);
212+
if (!state)
212213
return ERR_PTR(-ENOMEM);
213214

214215
clk = of_clk_get_by_name(np, con_id);
215216
if (!IS_ERR(clk)) {
216-
*ptr = clk;
217-
devres_add(dev, ptr);
217+
state->clk = clk;
218+
devres_add(dev, state);
218219
} else {
219-
devres_free(ptr);
220+
devres_free(state);
220221
}
221222

222223
return clk;

drivers/clk/keystone/syscon-clk.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,10 @@ static int ti_syscon_gate_clk_probe(struct platform_device *pdev)
151151
data[i].name);
152152
}
153153

154-
return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
155-
hw_data);
154+
if (num_clks == 1)
155+
return devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get,
156+
hw_data->hws[0]);
157+
return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, hw_data);
156158
}
157159

158160
#define TI_SYSCON_CLK_GATE(_name, _offset, _bit_idx) \

include/linux/clk.h

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,39 @@ int clk_get_scaled_duty_cycle(struct clk *clk, unsigned int scale);
183183
*/
184184
bool clk_is_match(const struct clk *p, const struct clk *q);
185185

186+
/**
187+
* clk_rate_exclusive_get - get exclusivity over the rate control of a
188+
* producer
189+
* @clk: clock source
190+
*
191+
* This function allows drivers to get exclusive control over the rate of a
192+
* provider. It prevents any other consumer to execute, even indirectly,
193+
* opereation which could alter the rate of the provider or cause glitches
194+
*
195+
* If exlusivity is claimed more than once on clock, even by the same driver,
196+
* the rate effectively gets locked as exclusivity can't be preempted.
197+
*
198+
* Must not be called from within atomic context.
199+
*
200+
* Returns success (0) or negative errno.
201+
*/
202+
int clk_rate_exclusive_get(struct clk *clk);
203+
204+
/**
205+
* clk_rate_exclusive_put - release exclusivity over the rate control of a
206+
* producer
207+
* @clk: clock source
208+
*
209+
* This function allows drivers to release the exclusivity it previously got
210+
* from clk_rate_exclusive_get()
211+
*
212+
* The caller must balance the number of clk_rate_exclusive_get() and
213+
* clk_rate_exclusive_put() calls.
214+
*
215+
* Must not be called from within atomic context.
216+
*/
217+
void clk_rate_exclusive_put(struct clk *clk);
218+
186219
#else
187220

188221
static inline int clk_notifier_register(struct clk *clk,
@@ -236,6 +269,13 @@ static inline bool clk_is_match(const struct clk *p, const struct clk *q)
236269
return p == q;
237270
}
238271

272+
static inline int clk_rate_exclusive_get(struct clk *clk)
273+
{
274+
return 0;
275+
}
276+
277+
static inline void clk_rate_exclusive_put(struct clk *clk) {}
278+
239279
#endif
240280

241281
#ifdef CONFIG_HAVE_CLK_PREPARE
@@ -583,38 +623,6 @@ struct clk *devm_clk_get_optional_enabled(struct device *dev, const char *id);
583623
*/
584624
struct clk *devm_get_clk_from_child(struct device *dev,
585625
struct device_node *np, const char *con_id);
586-
/**
587-
* clk_rate_exclusive_get - get exclusivity over the rate control of a
588-
* producer
589-
* @clk: clock source
590-
*
591-
* This function allows drivers to get exclusive control over the rate of a
592-
* provider. It prevents any other consumer to execute, even indirectly,
593-
* opereation which could alter the rate of the provider or cause glitches
594-
*
595-
* If exlusivity is claimed more than once on clock, even by the same driver,
596-
* the rate effectively gets locked as exclusivity can't be preempted.
597-
*
598-
* Must not be called from within atomic context.
599-
*
600-
* Returns success (0) or negative errno.
601-
*/
602-
int clk_rate_exclusive_get(struct clk *clk);
603-
604-
/**
605-
* clk_rate_exclusive_put - release exclusivity over the rate control of a
606-
* producer
607-
* @clk: clock source
608-
*
609-
* This function allows drivers to release the exclusivity it previously got
610-
* from clk_rate_exclusive_get()
611-
*
612-
* The caller must balance the number of clk_rate_exclusive_get() and
613-
* clk_rate_exclusive_put() calls.
614-
*
615-
* Must not be called from within atomic context.
616-
*/
617-
void clk_rate_exclusive_put(struct clk *clk);
618626

619627
/**
620628
* clk_enable - inform the system when the clock source should be running.
@@ -974,14 +982,6 @@ static inline void clk_bulk_put_all(int num_clks, struct clk_bulk_data *clks) {}
974982

975983
static inline void devm_clk_put(struct device *dev, struct clk *clk) {}
976984

977-
978-
static inline int clk_rate_exclusive_get(struct clk *clk)
979-
{
980-
return 0;
981-
}
982-
983-
static inline void clk_rate_exclusive_put(struct clk *clk) {}
984-
985985
static inline int clk_enable(struct clk *clk)
986986
{
987987
return 0;

0 commit comments

Comments
 (0)