drivers/most/most_cdev.c
Source file repositories/reference/linux-study-clean/drivers/most/most_cdev.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/most/most_cdev.c- Extension
.c- Size
- 12720 bytes
- Lines
- 547
- Domain
- Driver Families
- Bucket
- drivers/most
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/module.hlinux/sched.hlinux/fs.hlinux/slab.hlinux/device.hlinux/cdev.hlinux/poll.hlinux/kfifo.hlinux/uaccess.hlinux/idr.hlinux/most.h
Detected Declarations
struct comp_channelfunction ch_has_mbofunction stop_channelfunction destroy_cdevfunction destroy_channelfunction comp_openfunction comp_closefunction comp_writefunction comp_readfunction comp_pollfunction comp_disconnect_channelfunction comp_rx_completionfunction comp_tx_completionfunction comp_probefunction most_cdev_initfunction most_cdev_exitfunction list_for_each_entry_safemodule init most_cdev_init
Annotated Snippet
* Initialization of struct file_operations
*/
static const struct file_operations channel_fops = {
.owner = THIS_MODULE,
.read = comp_read,
.write = comp_write,
.open = comp_open,
.release = comp_close,
.poll = comp_poll,
};
/**
* comp_disconnect_channel - disconnect a channel
* @iface: pointer to interface instance
* @channel_id: channel index
*
* This frees allocated memory and removes the cdev that represents this
* channel in user space.
*/
static int comp_disconnect_channel(struct most_interface *iface, int channel_id)
{
struct comp_channel *c;
c = get_channel(iface, channel_id);
if (!c)
return -EINVAL;
mutex_lock(&c->io_mutex);
spin_lock(&c->unlink);
c->dev = NULL;
spin_unlock(&c->unlink);
destroy_cdev(c);
if (c->access_ref) {
stop_channel(c);
wake_up_interruptible(&c->wq);
mutex_unlock(&c->io_mutex);
} else {
mutex_unlock(&c->io_mutex);
destroy_channel(c);
}
return 0;
}
/**
* comp_rx_completion - completion handler for rx channels
* @mbo: pointer to buffer object that has completed
*
* This searches for the channel linked to this MBO and stores it in the local
* fifo buffer.
*/
static int comp_rx_completion(struct mbo *mbo)
{
struct comp_channel *c;
if (!mbo)
return -EINVAL;
c = get_channel(mbo->ifp, mbo->hdm_channel_id);
if (!c)
return -EINVAL;
spin_lock(&c->unlink);
if (!c->access_ref || !c->dev) {
spin_unlock(&c->unlink);
return -ENODEV;
}
kfifo_in(&c->fifo, &mbo, 1);
spin_unlock(&c->unlink);
#ifdef DEBUG_MESG
if (kfifo_is_full(&c->fifo))
dev_warn(c->dev, "Fifo is full\n");
#endif
wake_up_interruptible(&c->wq);
return 0;
}
/**
* comp_tx_completion - completion handler for tx channels
* @iface: pointer to interface instance
* @channel_id: channel index/ID
*
* This wakes sleeping processes in the wait-queue.
*/
static int comp_tx_completion(struct most_interface *iface, int channel_id)
{
struct comp_channel *c;
c = get_channel(iface, channel_id);
if (!c)
return -EINVAL;
Annotation
- Immediate include surface: `linux/module.h`, `linux/sched.h`, `linux/fs.h`, `linux/slab.h`, `linux/device.h`, `linux/cdev.h`, `linux/poll.h`, `linux/kfifo.h`.
- Detected declarations: `struct comp_channel`, `function ch_has_mbo`, `function stop_channel`, `function destroy_cdev`, `function destroy_channel`, `function comp_open`, `function comp_close`, `function comp_write`, `function comp_read`, `function comp_poll`.
- Atlas domain: Driver Families / drivers/most.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.