devm_gpiod_...dex_optional(9)
π NAME π
devm_gpiod_get_index_optional β it's literally the resource-managed glow-up of gpiod_get_index_optional(), bestie β¨
So this is from the Kernel API Manual, and honestly? She's giving "I handle the cleanup so you don't have to" main character energy π
πΈ SYNOPSIS πΈ
struct gpio_desc * devm_gpiod_get_index_optional (struct device *dev ,
const char *con_id , unsigned int index , enum gpiod_flags flags );
okay so that's the whole signature, no cap β we'll walk through every single piece π«Ά
π ARGUMENTS π
devβ the GPIO consumer π like, the device that's gonna be using this GPIOcon_idβ the function within the GPIO consumer π¦ (the name of the role it's playing)indexβ the index of the GPIO to obtain in the consumer β¨ so if there's more than one, this picks which oneflagsβ optional GPIO initialization flags π optional optional, iykyk
π DESCRIPTION π
So this is the managed version of gpiod_get_index_optional. The way that this works: any GPIO descriptors you get back from this function are automatically disposed on driver detach ππ which is genuinely the best part β no manual cleanup arc, no leaking, just vibes.
For the detailed tea on behavior and return values, go read gpiod_get_index_optional β that's where the full lore lives π
β RETURN β
Here's what you can get back, and yes there are three whole possibilities:
- the GPIO descriptor corresponding to the function
con_idof devicedevπ (the slay outcome) NULLif no GPIO has been assigned to the requested function π (not an error, just... nothing was assigned)- or another
IS_ERRcode if an error occurred while trying to acquire the GPIO π (check for errors properly, fr fr)
bestie please actually check the return value βNULLandIS_ERRare two completely different situations and mixing them up is not the move π¨
π SEE ALSO π
Kernel file ./drivers/gpio/gpiolib-devres.c, plus the whole friend group:
devm_gpiod_get(9)devm_gpiod_get_optional(9)devm_gpiod_get_index(9)devm_fwnode_gpiod_get_index(9)devm_gpiod_get_array(9)devm_gpiod_get_array_optional(9)devm_gpiod_put(9)devm_gpiod_unhinge(9)devm_gpiod_put_array(9)devm_gpiochip_add_data_with_key(9)
okay that's the whole page, periodt π
she lives in ./drivers/gpio, dated October 2026, in the Kernel API Manual β go forth and acquire your GPIOs responsibly, ily π§π
π¦ 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