devm_gpiod_get_index(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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, ykyk
  • idx β€” 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_id of device dev β€” the good ending πŸ’–
  • -ENOENT if no GPIO has been assigned to the requested function β€” like, it's not there, bestie πŸ’€
  • or another IS_ERR code 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:

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 -ENOENT and the other IS_ERR codes 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