devm_fwnode_gpiod_get_index(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ‘‘ devm_fwnode_gpiod_get_index(9) β€” the Kernel API Manual, bestie edition πŸ’…

okay so we're in the Kernel API Manual today and this little icon is genuinely so useful β€” it's the one that grabs a GPIO descriptor off a specific firmware node and then, and this is the ✨iconic✨ part, cleans up after itself. devm = "i gotchu, i'll handle the cleanup." obsessed. 🫢


✨ NAME ✨

devm_fwnode_gpiod_get_index β€” get a GPIO descriptor from a given node πŸŽ€


🌸 SYNOPSIS 🌸

struct gpio_desc * devm_fwnode_gpiod_get_index (struct device *dev ,
struct fwnode_handle *fwnode , const char *con_id , int index , enum
gpiod_flags flags , const char *label );

like, six whole arguments, she's high maintenance but worth it πŸ’–


πŸ¦‹ ARGUMENTS πŸ¦‹

  • dev β€” the GPIO consumer. the device that's gonna be using the GPIO, basically the main character here πŸ‘‘
  • fwnode β€” the firmware node that contains the GPIO reference. this is where we're looking it up, iykyk 🌈
  • con_id β€” the function within the GPIO consumer. like, which job is this pin doing for you?
  • index β€” the index of the GPIO to obtain in the consumer. when one function has multiple pins, this is your lil "which one" number πŸ”’
  • flags β€” the GPIO initialization flags. all the vibes/settings for setup ✨
  • label β€” the label to attach to the requested GPIO. a little name tag so everyone knows who she belongs to πŸŽ€

πŸ’œ DESCRIPTION πŸ’œ

okay here's the whole point, the reason we're all here: GPIO descriptors returned from this function are automatically disposed on driver detach. no cap. you don't have to remember to free them, no manual cleanup era, the devm machinery handles it. it's giving responsible adult energy and honestly? we stan 😭🫢


πŸ”₯ RETURN πŸ”₯

so what do you get back, bestie? it's one of these three situations:

  • The GPIO descriptor corresponding to the function con_id of device dev β€” slay, you got your pin πŸ’…
  • -ENOENT if no GPIO has been assigned to the requested function β€” basically "girl, there's nothing there" πŸ™ˆ
  • or another IS_ERR code if an error occurred while trying to acquire the GPIO β€” something went sideways, check that code πŸ’€
fr fr: always check it, don't just rawdog the return value. IS_ERR is right there, use her.

🧚 SEE ALSO 🧚

Kernel file ./drivers/gpio/gpiolib-devres.c β€” the source, go read her, she's gorgeous πŸ’–

then the whole friend group:


and that's the page!! 🌟 this one lives in ./drivers/gpio, dated October 2026, and she's filed under devm_fwnode_gpiod_get_index(9) β€” mwah, go get those pins bestie πŸ“πŸ’œ

πŸ“¦ where this page comes from