STRUCT COMEDI_DRIVER(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– struct comedi_driver(9) πŸ’–

okay bestie, welcome to the Kernel API Manual ✨ β€” this is the page where we learn how a low-level COMEDI driver gets its whole registration vibe on. it's giving "backstage pass to the kernel," no cap πŸŽ€


🌸 NAME 🌸

struct comedi_driver β€” COMEDI driver registration, aka the official paperwork your driver fills out so the kernel knows it exists πŸ’…


✨ SYNOPSIS ✨

struct comedi_driver {
    const char *driver_name;
    struct module *module;
    int (*attach)(struct comedi_device *dev, struct comedi_devconfig
*it);
    void (*detach)(struct comedi_device *dev);
    int (*auto_attach)(struct comedi_device *dev, unsigned long
context);
    unsigned int num_names;
    const char *const *board_name;
    int offset;
 };

like, that's the whole struct. every field, exactly as written, do not come for me πŸ”₯


πŸ¦‹ Members πŸ¦‹

so these are the fields you actually fill in, and here's what each one is for πŸ’œ

  • driver_name β€” the name of the driver. literally its whole identity, its main character energy πŸ‘‘
  • module β€” the owning module. who's your driver's parent, basically 🫢
  • attach β€” the optional "attach" handler for manually configured COMEDI devices. optional! say it with me πŸ™ˆ
  • detach β€” the "detach" handler, the one that deconfigures COMEDI devices. the clean-up queen 🧹
  • auto_attach β€” the optional "auto_attach" handler, for automatically configured COMEDI devices. the hands-free version ✨
  • num_names β€” optional number of "board names" supported 🌈
  • board_name β€” optional pointer to a pointer to a board name. lowkey important detail: the pointer to a board name is embedded in an element of a driver-defined array of static, read-only board type information πŸ’€ (read that twice, it's a pointer-to-a-pointer-inside-an-array situation)
  • offset β€” optional size of each element of that same driver-defined array of static, read-only board type information β€” i.e. the offset between each pointer to a board name 🎯

πŸŽ€ Description πŸŽ€

so here's the tea β˜•οΈ β€” this struct is what you hand to comedi_driver_register and comedi_driver_unregister to register and unregister a low-level COMEDI driver with the COMEDI core. that's the whole point. that's the assignment. periodt πŸ’…

now, the matching rules β€” and bestie, this part is load-bearing:

  • if num_names is non-zero, then board_name should be non-NULL, and offset should be at least sizeof(*board_name). the handler for the COMEDI_DEVCONFIG ioctl uses these to match a hardware device and its driver by board name πŸ‘‘
  • if num_names is zero, the COMEDI_DEVCONFIG ioctl matches a hardware device and its driver by driver name. this is only useful if the attach handler is set ⭐
  • if num_names is non-zero, the driver's attach handler will be called with the COMEDI device structure's board_ptr member pointing to the matched pointer to a board name within the driver's private array of static, read-only board type information πŸ¦‹

πŸ’€ the detach handler has TWO roles πŸ’€

ngl this is the part people get wrong, so listen up:

  1. if a COMEDI device was successfully configured by the attach or auto_attach handler, the detach handler is called when the device is being deconfigured β€” that's via the COMEDI_DEVCONFIG ioctl, or because the driver is being unloaded, or because the device was removed πŸ”₯
  2. it is also called when the attach or auto_attach handler returns an error 😭
and because of role #2, the attach or auto_attach handlers can defer clean-up on error until the detach handler is called. that's the perk 🫢

but β€” and this is the catch β€” if the attach or auto_attach handlers free any resources themselves, they must prevent the detach handler from freeing those same resources. double-free is not the vibe, fr fr πŸ™ˆ

⚠️ also huge: the detach handler must not assume that all resources requested by the attach or auto_attach handler were successfully allocated. like, some of them might just not be there. be chill about it 🧚

🌈 SEE ALSO 🌈

all the siblings, cousins and besties of this page β€” every single one, i'm not skipping a single name πŸ’–


okay that's the whole page, you ate that πŸ’… go register a driver, you got this 🫢

source: ./include/linux/comedi Β· dated October 2026 Β· mwah, catch you in the next manpage bestie πŸŽ€πŸ’–

πŸ“¦ where this page comes from