put_disk(9)
π put_disk(9) β the kernel API manual, bestie edition π
Okay so we're in the put_disk(9) page of the Kernel API Manual, and honestly? This one is short but she matters. Let's get into it β¨
πΈ NAME πΈ
put_disk β decrements the gendisk refcount
Like, that's it. That's the whole job. One lil decrement. But miss it and your kernel is not gonna be okay π
π¦ SYNOPSIS π¦
void put_disk (struct gendisk *disk );
Yep. Void return, one pointer in. No drama, no return value to check, just vibes and refcounting π«Ά
π ARGUMENTS π
diskβ thestruct gendiskto decrement the refcount for. That's the one. Hand her over and let her go π
β¨ DESCRIPTION β¨
So here's the tea β: this decrements the refcount for the struct gendisk. When that refcount reaches 0, we'll have disk_release called. That's the whole lifecycle arc, main character energy from start to finish π
Think of it as the polite way of saying "okay bestie, you can go now" β and once the last one is said, disk_release shows up to do the actual cleanup π§
π₯ NOTE π₯
Listen up, this one's important, no cap π¨
For blk-mq disk, put_disk must be called before freeing the tag_set when handling probe errors β that is, before add_disk is called.
Do it in the wrong order and it's giving chaos. Not the cute kind π
π CONTEXT π
Any context, bestie β go wild π¦
BUT β and this is a big but β the last reference must not be dropped from atomic context. That's the one line you cannot skip, fr fr π€
β SEE ALSO β
Kernel file ./block/genhd.c, plus the whole friend group:
bdev_count_inflight(9)__register_blkdev(9)add_disk_fwnode(9)device_add_disk(9)blk_mark_disk_dead(9)del_gendisk(9)invalidate_disk(9)disk_release(9)set_disk_ro(9)
iykyk π
Okay go forth and decrement responsibly, bestie ππ This page lives in ./block and it's stamped October 2026 β mwah, slay, periodt π
β¨
π¦ 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