BUS_RELEASE_RESOURCE(9)

πŸ’– BUS_RELEASE_RESOURCE(9) πŸ’–

okay so bestie, welcome to the Kernel Developer's Manual entry for bus_release_resource β€” yes it's a real manpage, yes it's giving ✨responsible cleanup era✨, and yes you're gonna slay it.


🌸 NAME 🌸

bus_release_resource β€” release resources on a bus πŸšŒπŸ’…


✨ SYNOPSIS ✨

#include <sys/param.h>
#include <sys/bus.h>

#include <machine/bus.h>
#include <sys/rman.h>
#include <machine/resource.h>

int
bus_release_resource(device_t dev, int type, int rid,
    struct resource *r);

like. look at that signature. gorgeous. no notes. 🫢


πŸŽ€ DESCRIPTION πŸŽ€

So what this bad boy does is free a resource that was allocated by bus_alloc_resource(9). that's literally it. that's the whole vibe. it's the goodbye text after the situationship.

⚠️ BUT β€” and this is the important part, no cap β€” the resource must not be in use on release. like, call the appropriate function before you let it go (for example, bus_teardown_intr(9) if it's an IRQ). don't be out here releasing stuff mid-use, it's not the move, it's giving chaos. 😭

Now let's break down the args, bestie:

  • dev β€” the device that owns the resource. it's their resource. their name is on it. πŸ‘‘
  • type β€” the type of resource you're releasing. it must be the same type you allocated it as before, don't switch up on it. check bus_alloc_resource(9) for the valid types if you need a refresher. πŸ“
  • rid β€” the resource ID of the resource. and listen, the rid value must be the exact same one that bus_alloc_resource(9) handed you back. same. one. no substitutions. 🚫
  • r β€” the pointer to struct resource, aka the resource itself, the one and only, returned by bus_alloc_resource(9). hold onto it and give it back exactly as received. 🎁

πŸ’€ RETURN VALUES πŸ’€

  • EINVAL gets returned if the device dev has no parent. yep. no parent, no dice.
  • 0 otherwise. clean. iconic. a little win. ✨
🚨 and heads up: the kernel will PANIC if it cannot release the resource. not a vibe check you want to fail. panic = bad. be careful. πŸ˜­πŸ’€

🌈 EXAMPLES 🌈

here's the whole little routine, verbatim, because we do not gatekeep:

    /* deactivate IRQ */
    bus_teardown_intr(dev, foosoftc->irqres, foosoftc->irqid);

    /* release IRQ resource */
    bus_release_resource(dev, SYS_RES_IRQ, foosoftc->irqid,
        foosoftc->irqres);

    /* release I/O port resource */
    bus_release_resource(dev, SYS_RES_IOPORT, foosoftc->portid,
        foosoftc->portres);

see how it tears down the intr first? that's the whole point bestie. deactivate, then release. order matters. periodt. πŸ’…


πŸ‘€ SEE ALSO πŸ‘€

(the group chat, basically. read the whole thread. iykyk. πŸ¦‹)


🫢 AUTHORS 🫢

This manual page was written by Alexander Langer <alex@big.endian.de>. absolute legend behavior. we thank them. 🌸


and that's the page, bestie β€” go release your resources responsibly, keep your rids matching, and never panic the kernel πŸ’–βœ¨πŸŽ€πŸ¦‹

Debian Β· May 18, 2000 Β· BUS_RELEASE_RESOURCE(9) β€” mwah, signing off πŸ’…β­

πŸ“¦ where this page comes from