devm_gpiod_get_optional(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… devm_gpiod_get_optional β€” the kernel API manual, but make it make sense

okay so bestie, welcome to the devm_gpiod_get_optional(9) page, from the Kernel API Manual ✨ this one is literally about grabbing a GPIO descriptor in a resource-managed way β€” and the _optional part is doing SO much work, iykyk πŸŽ€


✨ NAME ✨

devm_gpiod_get_optional β€” it's the resource-managed glow-up of gpiod_get_optional(). that's it, that's the whole name, slay 🫢


🌸 SYNOPSIS 🌸

struct gpio_desc * devm_gpiod_get_optional (struct device *dev , const
char *con_id , enum gpiod_flags flags );

like, look at that signature. it's giving "i return a pointer to a struct gpio_desc" and honestly? iconic πŸ‘‘


πŸ¦‹ ARGUMENTS πŸ¦‹

  • dev β€” the GPIO consumer. it's the device that's gonna be consuming the GPIO, bestie, don't overthink it πŸ’œ
  • con_id β€” the function within the GPIO consumer. that's the name of the thing you're asking for, basically 🌸
  • flags β€” optional GPIO initialization flags. this one is literally optional-optional, it's just flags for init ✨

πŸ’– DESCRIPTION πŸ’–

so this is the managed gpiod_get_optional. and when we say managed, we mean: GPIO descriptors returned from this function are automatically disposed on driver detach β€” no cap, the kernel cleans up after you so you don't have to 😭🫢 that's the main character energy of devm_.

for the detailed tea on behavior and return values, go read gpiod_get_optional β€” this one is basically the same vibe, just resource-managed. periodt πŸ’…


⭐ RETURN ⭐

here's what you get back (vibe check them all, they matter):

  • the GPIO descriptor corresponding to the function con_id of device dev β€” the happy path, we love her πŸŽ€
  • NULL if no GPIO has been assigned to the requested function β€” not an error btw, that's the _optional bit doing its thing πŸ¦‹
  • or another IS_ERR code if an error occurred while trying to acquire the GPIO β€” that's your "something actually went wrong" signal πŸ™ˆ
ngl bestie, always check for IS_ERR before you start using the pointer. just because it's managed doesn't mean it's guaranteed πŸ’€

🌈 SEE ALSO 🌈

the whole friend group, all of them, in order, no one left out πŸ’œ


and that's the page! 🧚 it lives over at ./drivers/gpio, dated October 2026, and it's devm_gpiod_get_optional(9) β€” go forth and acquire those GPIOs responsibly, bestie πŸ’–βœ¨

πŸ“¦ where this page comes from