drivers/comedi/drivers.c
Source file repositories/reference/linux-study-clean/drivers/comedi/drivers.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/comedi/drivers.c- Extension
.c- Size
- 37779 bytes
- Lines
- 1290
- Domain
- Driver Families
- Bucket
- drivers/comedi
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/module.hlinux/errno.hlinux/kernel.hlinux/ioport.hlinux/slab.hlinux/dma-direction.hlinux/interrupt.hlinux/firmware.hlinux/comedi/comedidev.hcomedi_internal.h
Detected Declarations
function comedi_set_hw_devfunction comedi_clear_hw_devfunction comedi_alloc_devprivfunction comedi_alloc_subdevicesfunction comedi_alloc_subdev_readbackfunction comedi_device_detach_cleanupfunction comedi_device_detach_lockedfunction comedi_device_detachfunction poll_invalidfunction insn_device_invalfunction get_zero_valid_routesfunction insn_invalfunction comedi_readback_insn_readfunction comedi_timeoutfunction comedi_dio_insn_configfunction comedi_dio_update_statefunction comedi_bytes_per_scan_cmdfunction _comedi_bytes_per_scanfunction comedi_bytes_per_scanfunction __comedi_nscans_leftfunction _comedi_nscans_leftfunction comedi_nscans_leftfunction _comedi_nsamples_leftfunction comedi_nsamples_leftfunction _comedi_inc_scan_progressfunction comedi_inc_scan_progressfunction _comedi_handle_eventsfunction comedi_handle_eventsfunction insn_rw_emulate_bitsfunction __comedi_device_postconfig_asyncfunction __comedi_device_postconfigfunction comedi_device_postconfigfunction comedi_report_boardsfunction comedi_load_firmwarefunction __comedi_check_request_regionfunction comedi_check_request_regionfunction comedi_legacy_detachfunction comedi_device_attachfunction comedi_auto_configfunction comedi_auto_unconfigfunction comedi_driver_registerfunction comedi_driver_unregisterexport comedi_set_hw_devexport comedi_alloc_devprivexport comedi_alloc_subdevicesexport comedi_alloc_subdev_readbackexport comedi_readback_insn_readexport comedi_timeout
Annotated Snippet
if (s->async) {
comedi_buf_alloc(dev, s, 0);
kfree(s->async);
}
kfree(s->readback);
}
kfree(dev->subdevices);
dev->subdevices = NULL;
dev->n_subdevices = 0;
}
kfree(dev->private);
if (!IS_ERR(dev->pacer))
kfree(dev->pacer);
dev->private = NULL;
dev->pacer = NULL;
dev->driver = NULL;
dev->board_name = NULL;
dev->board_ptr = NULL;
dev->mmio = NULL;
dev->iobase = 0;
dev->iolen = 0;
dev->ioenabled = false;
dev->irq = 0;
dev->read_subdev = NULL;
dev->write_subdev = NULL;
dev->open = NULL;
dev->close = NULL;
comedi_clear_hw_dev(dev);
}
void comedi_device_detach_locked(struct comedi_device *dev)
{
lockdep_assert_held_write(&dev->attach_lock);
lockdep_assert_held(&dev->mutex);
comedi_device_cancel_all(dev);
dev->attached = false;
dev->detach_count++;
if (dev->driver)
dev->driver->detach(dev);
comedi_device_detach_cleanup(dev);
}
void comedi_device_detach(struct comedi_device *dev)
{
lockdep_assert_held(&dev->mutex);
down_write(&dev->attach_lock);
comedi_device_detach_locked(dev);
up_write(&dev->attach_lock);
}
static int poll_invalid(struct comedi_device *dev, struct comedi_subdevice *s)
{
return -EINVAL;
}
static int insn_device_inval(struct comedi_device *dev,
struct comedi_insn *insn, unsigned int *data)
{
return -EINVAL;
}
static unsigned int get_zero_valid_routes(struct comedi_device *dev,
unsigned int n_pairs,
unsigned int *pair_data)
{
return 0;
}
int insn_inval(struct comedi_device *dev, struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
{
return -EINVAL;
}
/**
* comedi_readback_insn_read() - A generic (*insn_read) for subdevice readback.
* @dev: COMEDI device.
* @s: COMEDI subdevice.
* @insn: COMEDI instruction.
* @data: Pointer to return the readback data.
*
* Handles the %INSN_READ instruction for subdevices that use the readback
* array allocated by comedi_alloc_subdev_readback(). It may be used
* directly as the subdevice's handler (@s->insn_read) or called via a
* wrapper.
*
* @insn->n is normally 1, which will read a single value. If higher, the
* same element of the readback array will be read multiple times.
*
* Returns @insn->n on success, or -EINVAL if @s->readback is NULL.
Annotation
- Immediate include surface: `linux/device.h`, `linux/module.h`, `linux/errno.h`, `linux/kernel.h`, `linux/ioport.h`, `linux/slab.h`, `linux/dma-direction.h`, `linux/interrupt.h`.
- Detected declarations: `function comedi_set_hw_dev`, `function comedi_clear_hw_dev`, `function comedi_alloc_devpriv`, `function comedi_alloc_subdevices`, `function comedi_alloc_subdev_readback`, `function comedi_device_detach_cleanup`, `function comedi_device_detach_locked`, `function comedi_device_detach`, `function poll_invalid`, `function insn_device_inval`.
- Atlas domain: Driver Families / drivers/comedi.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.