devm_gpiod_get_index(9)
π devm_gpiod_get_index π
okay bestie, welcome to the Kernel API Manual β yes we're reading kernel docs for fun now, this is who we are π
πΈ NAME πΈ
devm_gpiod_get_index β it's gpiod_get_index(), but make it resource-managed β¨ (the devm girlies simply do not do manual cleanup)
π SYNOPSIS π
struct gpio_desc * devm_gpiod_get_index (struct device *dev , const char *con_id , unsigned int idx , enum gpiod_flags flags );
likeβ¦ it returns a struct gpio_desc * and takes four things. that's the whole vibe check π¦
β¨ ARGUMENTS β¨
devβ the GPIO consumer, aka the device that's being all "I want a GPIO π₯Ί"con_idβ the function within the GPIO consumer. it's the which one of it all, ykykidxβ index of the GPIO to obtain in the consumer. yes there can be multiple, slay πflagsβ optional GPIO initialization flags. optional bestie, don't stress π«Ά
π§ DESCRIPTION π§
so this is the Managed gpiod_get_index. the GPIO descriptors you get back from this function are automatically disposed on driver detach β no cap, you literally don't have to free them yourself, the devm machinery handles it π
β¨
the way that this is just the tidy versionβ¦ obsessed π
if you want the detailed tea on behavior and return values, go read gpiod_get_index β that's the main character, this one's the resource-managed remix π
π₯ RETURN π₯
- the GPIO descriptor corresponding to the function
con_idof devicedevβ the good ending π -ENOENTif no GPIO has been assigned to the requested function β like, it's not there, bestie π- or another
IS_ERRcode if an error occurred while trying to acquire the GPIO β check for errors always, fr fr π
β SEE ALSO β
Kernel file ./drivers/gpio/gpiolib-devres.c and its besties:
devm_gpiod_get(9)devm_gpiod_get_optional(9)devm_fwnode_gpiod_get_index(9)devm_gpiod_get_index_optional(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)
like a whole friend group of devm GPIO functions, and every single one of them ate π π
heads up: the managed cleanup only kicks in on driver detach, so this is a driver vibe β it's giving devres, not giving "call it from your random userspace-adjacent code". also remember-ENOENTand the otherIS_ERRcodes have different meanings, so check properly πΈ
okay that's the whole page! brought to you by the kernel source tree at ./drivers/gpio, dated October 2026 β periodt, go get your GPIOs bestie ππ¦β¨
π¦ 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