devm_gpioch...ata_with_key(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… devm_gpioch...ata_with_key(9) β€” like, the managed version, bestie

Okay so real talk, this is a page from the Kernel API Manual and the title is literally devm_gpioch...ata_with_key(9) β€” yes the name got truncated by the man page gods, no that's not me being lazy, that's just how it's printed. Come sit with me, we're gonna get through this together 🫢


✨ NAME ✨

devm_gpiochip_add_data_with_key β€” it's the resource-managed glow-up of gpiochip_add_data_with_key(). Same energy, but the kernel cleans up after you so you don't have to. Iconic behavior honestly πŸ‘‘


πŸŽ€ SYNOPSIS πŸŽ€

int devm_gpiochip_add_data_with_key (struct device *dev , struct
gpio_chip *gc , void *data , struct lock_class_key *lock_key , struct
lock_class_key *request_key );

Five args, all of them important, don't skip any of them bestie 😭


🌸 ARGUMENTS 🌸

  • dev β€” pointer to the device that gpio_chip belongs to. Like, whose chip is this? That device. 🫢
  • gc β€” the GPIO chip you're registering. The main character of this whole operation ✨
  • data β€” driver-private data associated with this chip. Your little stash of secrets, iykyk πŸ™ˆ
  • lock_key β€” lockdep class for the IRQ lock. Yes it's a lockdep thing, yes you gotta pass it πŸ”’
  • request_key β€” lockdep class for the IRQ request. Different lock, different key, don't mix them up πŸ’…

πŸ¦‹ CONTEXT πŸ¦‹

Potentially before IRQs will work. Like, potentially. It's giving "we're early, the party hasn't started yet" vibes ⭐


πŸ”₯ DESCRIPTION πŸ”₯

The gpio chip automatically gets released when the device is unbound. That's the whole devm moment β€” you register it, the kernel remembers it for you, and when the device dips out, the chip goes with it. No manual cleanup arc, no remove() trauma, we love a self-cleaning king πŸ‘‘πŸ’–


πŸ’€ RETURN πŸ’€

  • A negative errno if the chip can't be registered β€” for example because gc->base is invalid or already associated with a different chip. Yeah, that's a whole situation 😭
  • Otherwise it returns zero as a success code. Zero means slay. Periodt. ✨

🌈 SEE ALSO 🌈

Kernel file ./drivers/gpio/gpiolib-devres.c β€” that's where the magic lives, go read it, it's giving source-code field trip 🧚

And the whole friend group of devm_* gpiod besties:


Real talk bestie: this page lives under ./drivers/gpio, dated October 2026, in the Kernel API Manual. That's the whole footer. Love that for us. Mwah πŸ’‹πŸŽ€
πŸ“¦ where this page comes from