devm_gpiod_...ray_optional(9)
π devm_gpiod_...ray_optional β straight from the Kernel API Manual, bestie
okay so before we even get into it: yes the title is literally devm_gpiod_...ray_optional(9) with the dots and everything, that's not me being lazy, that's the actual page name, the middle got squished like a text message from someone typing too fast π anyway. intent is giving "kernel dev who wants ALL the GPIOs, but responsibly." let's get into it β¨
β¨ NAME β¨
devm_gpiod_get_array_optional β it's the resource-managed glow-up of gpiod_get_array_optional(). same energy, but the cleanup is handled for you π«Ά
π SYNOPSIS π
struct gpio_descs * devm_gpiod_get_array_optional (struct device *dev ,
const char *con_id , enum gpiod_flags flags );
bestie look at that signature. struct gpio_descs * coming back at you, three args going in. iconic behavior fr fr π
πΈ ARGUMENTS πΈ
devβ the GPIO consumer. like, the device that's about to be obsessed with some GPIOs πcon_idβ the function within the GPIO consumer. the name-tag that says which function we're talking about β¨flagsβ optional GPIO initialization flags. optional optional, they're right there in the name π
π¦ DESCRIPTION π¦
so this is the managed version of gpiod_get_array_optional, no cap. the GPIO descriptors you get back from this function? they get automatically disposed on driver detach. you don't have to clean up after yourself, the kernel does it for you. main character energy honestly π«Ά
if you want the full tea on how it actually behaves and what it returns, go read gpiod_get_array_optional β this one is literally pointing you there π
π₯ RETURN π₯
here's the vibe check on what you get back:
- the GPIO descriptors corresponding to the function
con_idof devicedevβ slay, you got your array π NULLif no GPIO has been assigned to the requested function β no GPIOs, no problem, no drama π- or another
IS_ERRcode if an error happened while trying to acquire the GPIOs β read it, don't ignore it, that's the whole point π
β SEE ALSO β
go down the rabbit hole, i promise it's worth it π§
- Kernel file
./drivers/gpio/gpiolib-devres.c devm_gpiod_get(9)devm_gpiod_get_optional(9)devm_gpiod_get_index(9)devm_fwnode_gpiod_get_index(9)devm_gpiod_get_index_optional(9)devm_gpiod_get_array(9)devm_gpiod_put(9)devm_gpiod_unhinge(9)devm_gpiod_put_array(9)devm_gpiochip_add_data_with_key(9)
π friendly reminder from your favorite kernel bestie: this whole page lives at./drivers/gpio, and it's dated October 2026 β so when you cite it, cite it cute. oh and the page name is stilldevm_gpiod_...ray_optional(9), dots and all, i don't make the rules, i just vibe with them π
that's the whole page, you ate that, periodt π β¨πΈ
π¦ 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