Skip to content

Commit 51e32e8

Browse files
cristiccbebarino
authored andcommitted
clk: Provide devm_clk_bulk_get_all_enabled() helper
Commit 265b07d ("clk: Provide managed helper to get and enable bulk clocks") added devm_clk_bulk_get_all_enable() function, but missed to return the number of clocks stored in the clk_bulk_data table referenced by the clks argument. Without knowing the number, it's not possible to iterate these clocks when needed, hence the argument is useless and could have been simply removed. Introduce devm_clk_bulk_get_all_enabled() variant, which is consistent with devm_clk_bulk_get_all() in terms of the returned value: > 0 if one or more clocks have been stored = 0 if there are no clocks < 0 if an error occurred Moreover, the naming is consistent with devm_clk_get_enabled(), i.e. use the past form of 'enable'. To reduce code duplication and improve patch readability, make devm_clk_bulk_get_all_enable() use the new helper, as suggested by Stephen Boyd. Reviewed-by: AngeloGioacchino Del Regno <[email protected]> Reviewed-by: Manivannan Sadhasivam <[email protected]> Signed-off-by: Cristian Ciocaltea <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Stephen Boyd <[email protected]>
1 parent 9852d85 commit 51e32e8

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

drivers/clk/clk-devres.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ static void devm_clk_bulk_release_all_enable(struct device *dev, void *res)
218218
clk_bulk_put_all(devres->num_clks, devres->clks);
219219
}
220220

221-
int __must_check devm_clk_bulk_get_all_enable(struct device *dev,
222-
struct clk_bulk_data **clks)
221+
int __must_check devm_clk_bulk_get_all_enabled(struct device *dev,
222+
struct clk_bulk_data **clks)
223223
{
224224
struct clk_bulk_devres *devres;
225225
int ret;
@@ -244,11 +244,12 @@ int __must_check devm_clk_bulk_get_all_enable(struct device *dev,
244244
} else {
245245
clk_bulk_put_all(devres->num_clks, devres->clks);
246246
devres_free(devres);
247+
return ret;
247248
}
248249

249-
return ret;
250+
return devres->num_clks;
250251
}
251-
EXPORT_SYMBOL_GPL(devm_clk_bulk_get_all_enable);
252+
EXPORT_SYMBOL_GPL(devm_clk_bulk_get_all_enabled);
252253

253254
static int devm_clk_match(struct device *dev, void *res, void *data)
254255
{

include/linux/clk.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -496,20 +496,22 @@ int __must_check devm_clk_bulk_get_all(struct device *dev,
496496
struct clk_bulk_data **clks);
497497

498498
/**
499-
* devm_clk_bulk_get_all_enable - Get and enable all clocks of the consumer (managed)
499+
* devm_clk_bulk_get_all_enabled - Get and enable all clocks of the consumer (managed)
500500
* @dev: device for clock "consumer"
501501
* @clks: pointer to the clk_bulk_data table of consumer
502502
*
503-
* Returns success (0) or negative errno.
503+
* Returns a positive value for the number of clocks obtained while the
504+
* clock references are stored in the clk_bulk_data table in @clks field.
505+
* Returns 0 if there're none and a negative value if something failed.
504506
*
505507
* This helper function allows drivers to get all clocks of the
506508
* consumer and enables them in one operation with management.
507509
* The clks will automatically be disabled and freed when the device
508510
* is unbound.
509511
*/
510512

511-
int __must_check devm_clk_bulk_get_all_enable(struct device *dev,
512-
struct clk_bulk_data **clks);
513+
int __must_check devm_clk_bulk_get_all_enabled(struct device *dev,
514+
struct clk_bulk_data **clks);
513515

514516
/**
515517
* devm_clk_get - lookup and obtain a managed reference to a clock producer.
@@ -1034,7 +1036,7 @@ static inline int __must_check devm_clk_bulk_get_all(struct device *dev,
10341036
return 0;
10351037
}
10361038

1037-
static inline int __must_check devm_clk_bulk_get_all_enable(struct device *dev,
1039+
static inline int __must_check devm_clk_bulk_get_all_enabled(struct device *dev,
10381040
struct clk_bulk_data **clks)
10391041
{
10401042
return 0;
@@ -1136,6 +1138,15 @@ static inline void clk_restore_context(void) {}
11361138

11371139
#endif
11381140

1141+
/* Deprecated. Use devm_clk_bulk_get_all_enabled() */
1142+
static inline int __must_check
1143+
devm_clk_bulk_get_all_enable(struct device *dev, struct clk_bulk_data **clks)
1144+
{
1145+
int ret = devm_clk_bulk_get_all_enabled(dev, clks);
1146+
1147+
return ret > 0 ? 0 : ret;
1148+
}
1149+
11391150
/* clk_prepare_enable helps cases using clk_enable in non-atomic context. */
11401151
static inline int clk_prepare_enable(struct clk *clk)
11411152
{

0 commit comments

Comments
 (0)