devm_clk_get(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸŽ€ 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:

like I said. friend group. πŸ’–


ok real talk though β€” the RETURN value can be an IS_ERR thing containing errno, 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