devm_clk_bulk_get_optional(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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 of clk_bulk_data. yes, it's a count. yes, it matters. don't skip it πŸ™ˆ
  • clks β€” pointer to the clk_bulk_data table 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:


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