put_disk(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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 β€” the struct gendisk to 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:

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