devm_gpiod_...dex_optional(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– 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 GPIO
  • con_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 one
  • flags β€” 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_id of device dev πŸ’– (the slay outcome)
  • NULL if no GPIO has been assigned to the requested function πŸ™ˆ (not an error, just... nothing was assigned)
  • or another IS_ERR code if an error occurred while trying to acquire the GPIO πŸ’€ (check for errors properly, fr fr)
bestie please actually check the return value β€” NULL and IS_ERR are 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:


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