devm_clk_get(9)
π devm_clk_get(9) π
okay SO bestie, welcome to the Kernel API Manual, where we learn how to get a clock and have the kernel clean up after us like the absolute icon it is π this one's short and sweet and honestly kind of a bop.
β¨ NAME β¨
devm_clk_get β lookup and obtain a managed reference to a clock producer πβ¨
πΈ SYNOPSIS πΈ
struct clk * devm_clk_get (struct device *dev , const char *id );
look at her. two args. no notes. π«Ά
π¦ ARGUMENTS π¦
devβ the device that's acting as the clock "consumer" π (yes, consumer, in quotes, that's literally how they wrote it)idβ the clock consumer ID π·οΈ
π CONTEXT π
May sleep. π΄ fr fr, so no calling this from atomic context, bestie β she naps.
β RETURN β
You get back a struct clk that corresponds to the clock producer π β or a valid IS_ERR condition containing errno π (so like, pls check it, don't just rawdog the pointer into your driver).
The implementation uses dev and id together to figure out who the clock consumer is, and thereby the clock producer π. IOW β and this is the spicy part π₯ β id may be identical strings, but clk_get may still return different clock producers depending on dev. so yeah, the string alone isn't the whole story, iykyk.
π DESCRIPTION π
Drivers must assume that the clock source is neither prepared nor enabled π β like it's not warmed up, don't assume anything, do the prep work yourself.
The clock will automatically be freed when the device is unbound from the bus π§ β that's the "managed" part of managed reference, and it's the whole reason this function exists and slays. no manual cleanup arc, no clk_put trauma, the devres machinery handles it periodt π
π₯ SEE ALSO π₯
Kernel file ./include/linux/clk.h π plus this whole friend group:
clk notifier callback types(9)β yes, that one's a phrase not a symbol, iconic π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_optional(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_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)
like I said. friend group. π
ok real talk though β the RETURN value can be anIS_ERRthing containingerrno, so check it before you dereference it or you WILL have a bad time ππ
and that's the page!! sourced from ./include/linux, dated October 2026 ποΈβ¨ go get your clocks bestie, they're managed, they're freed on unbind, they're literally the moment π«Άπ
π¦ 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