STRUCT COMEDI_DRIVER(9)
π 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_namesis non-zero, thenboard_nameshould be non-NULL, andoffsetshould be at leastsizeof(*board_name). the handler for theCOMEDI_DEVCONFIGioctl uses these to match a hardware device and its driver by board name π - if
num_namesis zero, theCOMEDI_DEVCONFIGioctl matches a hardware device and its driver by driver name. this is only useful if theattachhandler is set β - if
num_namesis non-zero, the driver'sattachhandler will be called with the COMEDI device structure'sboard_ptrmember 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:
- if a COMEDI device was successfully configured by the
attachorauto_attachhandler, thedetachhandler is called when the device is being deconfigured β that's via theCOMEDI_DEVCONFIGioctl, or because the driver is being unloaded, or because the device was removed π₯ - it is also called when the
attachorauto_attachhandler returns an error π
and because of role #2, theattachorauto_attachhandlers can defer clean-up on error until thedetachhandler 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: thedetachhandler must not assume that all resources requested by theattachorauto_attachhandler 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 π
- Kernel file
./include/linux/comedi/comedidev.hstruct comedi_subdevice(9)struct comedi_buf_page(9)struct comedi_buf_map(9)struct comedi_async(9)enum comedi_cb(9)struct comedi_device(9)struct comedi_lrange(9)comedi_range_is_bipolar(9)comedi_range_is_unipolar(9)comedi_range_is_external(9)comedi_chan_range_is_bipolar(9)comedi_chan_range_is_unipolar(9)comedi_chan_range_is_external(9)comedi_offset_munge(9)comedi_bytes_per_sample(9)comedi_sample_shift(9)comedi_bytes_to_samples(9)comedi_samples_to_bytes(9)comedi_check_trigger_src(9)comedi_check_trigger_is_unique(9)comedi_check_trigger_arg_is(9)comedi_check_trigger_arg_min(9)comedi_check_trigger_arg_max(9)comedi_buf_n_bytes_ready(9)__comedi_request_region(9)comedi_request_region(9)module_comedi_driver(9)
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
- 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