comedi_set_hw_dev(9)
π comedi_set_hw_dev β the kernel API manual, bestie edition π
okay so this is a page from the Kernel API Manual (yes, that's the manual name, we're not hiding it π«Ά) and it's all about one tiny function that does one very specific little job: introducing a COMEDI device to its hardware device. matchmaking, basically. π
β¨ NAME β¨
comedi_set_hw_dev β set the hardware device associated with a COMEDI device
like... that's the whole gig. it links dev and hw_dev together. no cap. π
πΈ SYNOPSIS πΈ
int comedi_set_hw_dev (struct comedi_device *dev , struct device *hw_dev
);
that's it. that's the whole signature. two pointers and an int coming back at you. iconic honestly. β¨
π¦ ARGUMENTS π¦
devβ the COMEDI device. the one getting a hardware buddy.hw_devβ the hardware device. the buddy in question. π
π₯ DESCRIPTION π₯
okay so picture this: for automatically configured COMEDI devices β the ones that come from a call to comedi_auto_config or one of its wrappers over in the low-level COMEDI driver β comedi_set_hw_dev gets called automatically by the COMEDI core to associate the COMEDI device with the hardware device. the core does it for you. main character behaviour. π
it can also be called directly by "legacy" low-level COMEDI drivers, the ones that rely on the COMEDI_DEVCONFIG ioctl to configure the hardware β and that's fine, as long as the hardware has a struct device. key caveat bestie, don't forget it. π«Ά
now here's the actual vibe check of the logic:
- if
dev->hw_devisNULL, it grabs a reference tohw_devand setsdev->hw_dev. slay. β - otherwise? it does absolutely nothing. nothing at all. π
- calling it multiple times with the same hardware device is not considered an error. we stan an idempotent queen. π
- and if it does grab a reference to the hardware device, that reference gets automatically 'put' when the device is detached from COMEDI. automatic cleanup, we love to see it. π
Return value: it returns 0 if dev->hw_dev was NULL or the same as hw_dev. otherwise it returns -EEXIST. that's the whole report card. β
ngl the whole function is basically "if already taken, return -EEXIST" and honestly? relatable.
π SEE ALSO π
the kernel file ./drivers/comedi/drivers.c π β and then the whole friend group, fr fr:
comedi_alloc_devpriv(9)comedi_alloc_subdevices(9)comedi_alloc_subdev_readback(9)comedi_readback_insn_read(9)comedi_timeout(9)comedi_dio_insn_config(9)comedi_dio_update_state(9)comedi_bytes_per_scan_cmd(9)comedi_bytes_per_scan(9)comedi_nscans_left(9)comedi_nsamples_left(9)comedi_inc_scan_progress(9)comedi_handle_events(9)comedi_load_firmware(9)__comedi_check_request_region(9)comedi_check_request_region(9)comedi_legacy_detach(9)comedi_auto_config(9)comedi_auto_unconfig(9)comedi_driver_register(9)comedi_driver_unregister(9)
and that's the page bestie π§π this little icon of a function lives in ./drivers/comedi, the manual is dated October 2026, and it's the comedi_set_hw_dev(9) page from the Kernel API Manual. go forth and matchmake responsibly. π
β¨πΈ
π¦ 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