devm_clk_bulk_get_optional(9)
π devm_clk_bulk_get_optional β from the Kernel API Manual, bestie β¨
okay so picture this: you're in the kernel, you've got a whole squad of clocks to grab, and some of them might literally not exist yet. that's the vibe this function was made for π«Ά
πΈ NAME πΈ
devm_clk_bulk_get_optional β the managed way to get multiple optional consumer clocks. that's it, that's the whole name, periodt π
β¨ SYNOPSIS β¨
int devm_clk_bulk_get_optional (struct device *dev , int num_clks ,
struct clk_bulk_data *clks );
like, that's the whole signature. no cap. π
π― ARGUMENTS π―
devβ the device that's acting as the clock "consumer". it's the one doing the consuming, main character energy πnum_clksβ the number ofclk_bulk_data. yes, it's a count. yes, it matters. don't skip it πclksβ pointer to theclk_bulk_datatable that belongs to the consumer. this is the whole squad of clocks, right here π¦
π DESCRIPTION π
so it behaves exactly the same as devm_clk_bulk_get... except for the one iconic little twist: when there's no clock producer at all π₯ in that exact case, instead of hitting you with -ENOENT, the function just returns NULL for the given clk. that's it, no drama, no error code, just NULL. the assumption baked in here is that all the clocks in clk_bulk_data are optional β every single one, so don't come at it with a required clock, that's not the assignment π
It returns 0 if all the clocks specified in the clk_bulk_data table are obtained successfully, or if for any clk there was no clk provider available at all. otherwise it returns a valid IS_ERR condition containing errno. so like, 0 = we're so back, IS_ERR = it's over π
the implementation uses dev and clk_bulk_data.id to determine the clock consumer, and thereby the clock producer. iykyk. and the clock that comes back is stored in each clk_bulk_data.clk field β
π¨ Drivers must assume that the clock source is not enabled. like, do not assume it's already up and running. it is NOT. assume nothing, bestie.
π¨ Also: clk_bulk_get should not be called from within interrupt context. hard no. don't do it. π
ββοΈ
π SEE ALSO π
Kernel file ./include/linux/clk.h β and honestly the whole clock extended family showed up for this one, so let's give them their moment:
clk notifier callback types(9)struct clk_notifier(9)struct clk_notifier_data(9)struct clk_bulk_data(9)clk_notifier_register(9)clk_notifier_unregister(9)devm_clk_notifier_register(9)clk_get_accuracy(9)clk_set_phase(9)clk_get_phase(9)clk_set_duty_cycle(9)clk_get_scaled_duty_cycle(9)clk_is_match(9)clk_rate_exclusive_get(9)devm_clk_rate_exclusive_get(9)clk_rate_exclusive_put(9)clk_save_context(9)clk_restore_context(9)clk_prepare(9)clk_unprepare(9)clk_is_enabled_when_prepared(9)clk_get(9)clk_bulk_get(9)clk_bulk_get_all(9)clk_bulk_get_optional(9)devm_clk_bulk_get(9)devm_clk_bulk_get_enable(9)devm_clk_bulk_get_optional_enable(9)devm_clk_bulk_get_all(9)devm_clk_bulk_get_all_enabled(9)devm_clk_get(9)devm_clk_get_prepared(9)devm_clk_get_enabled(9)devm_clk_get_optional(9)devm_clk_get_optional_prepared(9)devm_clk_get_optional_enabled(9)devm_clk_get_optional_enabled_with_rate(9)devm_get_clk_from_child(9)clk_enable(9)clk_bulk_enable(9)clk_disable(9)clk_bulk_disable(9)clk_get_rate(9)clk_put(9)clk_bulk_put(9)clk_bulk_put_all(9)devm_clk_put(9)clk_round_rate(9)clk_set_rate(9)clk_set_rate_exclusive(9)clk_has_parent(9)clk_set_rate_range(9)clk_set_min_rate(9)clk_set_max_rate(9)clk_set_parent(9)clk_get_parent(9)clk_get_sys(9)clk_drop_range(9)clk_get_optional(9)
and that's the page!! π this little beauty lives in ./include/linux, and it's stamped October 2026 β so like, future-dated and thriving β¨ mwah, go get those optional clocks bestie π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms