devm_gpioch...ata_with_key(9)
π 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 thatgpio_chipbelongs 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->baseis 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:
devm_gpiod_get(9)devm_gpiod_get_optional(9)devm_gpiod_get_index(9)devm_fwnode_gpiod_get_index(9)devm_gpiod_get_index_optional(9)devm_gpiod_get_array(9)devm_gpiod_get_array_optional(9)devm_gpiod_put(9)devm_gpiod_unhinge(9)devm_gpiod_put_array(9)
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
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms