drivers/usb/mon/mon_bin.c
Source file repositories/reference/linux-study-clean/drivers/usb/mon/mon_bin.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/mon/mon_bin.c- Extension
.c- Size
- 34428 bytes
- Lines
- 1421
- Domain
- Driver Families
- Bucket
- drivers/usb
- 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/kernel.hlinux/sched/signal.hlinux/types.hlinux/fs.hlinux/cdev.hlinux/export.hlinux/usb.hlinux/poll.hlinux/compat.hlinux/mm.hlinux/scatterlist.hlinux/slab.hlinux/time64.hlinux/uaccess.husb_mon.h
Detected Declarations
struct mon_bin_hdrstruct iso_recstruct mon_bin_isodescstruct mon_bin_statsstruct mon_bin_getstruct mon_bin_mfetchstruct mon_bin_get32struct mon_bin_mfetch32struct mon_pgmapstruct mon_reader_binfunction mon_copy_to_bufffunction copy_from_buffunction anfunction mon_buff_area_alloc_contiguousfunction fewfunction mon_buff_area_freefunction mon_buff_area_fillfunction mon_bin_get_setupfunction mon_bin_get_datafunction for_each_sgfunction mon_bin_collate_isodescfunction mon_bin_get_isodescfunction mon_bin_eventfunction mon_bin_submitfunction mon_bin_completefunction mon_bin_errorfunction mon_bin_openfunction mon_bin_get_eventfunction mon_bin_releasefunction mon_bin_readfunction mon_bin_flushfunction mon_bin_fetchfunction mon_bin_queuedfunction mon_bin_ioctlfunction mon_bin_compat_ioctlfunction mon_bin_pollfunction mon_bin_vma_openfunction mon_bin_vma_closefunction mon_bin_vma_faultfunction mon_bin_mmapfunction mon_bin_wait_eventfunction mon_alloc_bufffunction mon_free_bufffunction mon_bin_addfunction mon_bin_delfunction mon_bin_initfunction mon_bin_exit
Annotated Snippet
static const struct file_operations mon_fops_binary = {
.owner = THIS_MODULE,
.open = mon_bin_open,
.read = mon_bin_read,
/* .write = mon_text_write, */
.poll = mon_bin_poll,
.unlocked_ioctl = mon_bin_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = mon_bin_compat_ioctl,
#endif
.release = mon_bin_release,
.mmap = mon_bin_mmap,
};
static int mon_bin_wait_event(struct file *file, struct mon_reader_bin *rp)
{
DECLARE_WAITQUEUE(waita, current);
unsigned long flags;
add_wait_queue(&rp->b_wait, &waita);
set_current_state(TASK_INTERRUPTIBLE);
spin_lock_irqsave(&rp->b_lock, flags);
while (MON_RING_EMPTY(rp)) {
spin_unlock_irqrestore(&rp->b_lock, flags);
if (file->f_flags & O_NONBLOCK) {
set_current_state(TASK_RUNNING);
remove_wait_queue(&rp->b_wait, &waita);
return -EWOULDBLOCK; /* Same as EAGAIN in Linux */
}
schedule();
if (signal_pending(current)) {
remove_wait_queue(&rp->b_wait, &waita);
return -EINTR;
}
set_current_state(TASK_INTERRUPTIBLE);
spin_lock_irqsave(&rp->b_lock, flags);
}
spin_unlock_irqrestore(&rp->b_lock, flags);
set_current_state(TASK_RUNNING);
remove_wait_queue(&rp->b_wait, &waita);
return 0;
}
static int mon_alloc_buff(struct mon_pgmap *map, int npages)
{
int n;
unsigned long vaddr;
for (n = 0; n < npages; n++) {
vaddr = get_zeroed_page(GFP_KERNEL);
if (vaddr == 0) {
while (n-- != 0)
free_page((unsigned long) map[n].ptr);
return -ENOMEM;
}
map[n].ptr = (unsigned char *) vaddr;
map[n].pg = virt_to_page((void *) vaddr);
}
return 0;
}
static void mon_free_buff(struct mon_pgmap *map, int npages)
{
int n;
for (n = 0; n < npages; n++)
free_page((unsigned long) map[n].ptr);
}
int mon_bin_add(struct mon_bus *mbus, const struct usb_bus *ubus)
{
struct device *dev;
unsigned minor = ubus? ubus->busnum: 0;
if (minor >= MON_BIN_MAX_MINOR)
return 0;
dev = device_create(&mon_bin_class, ubus ? ubus->controller : NULL,
MKDEV(MAJOR(mon_bin_dev0), minor), NULL,
"usbmon%d", minor);
if (IS_ERR(dev))
return 0;
mbus->classdev = dev;
return 1;
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/sched/signal.h`, `linux/types.h`, `linux/fs.h`, `linux/cdev.h`, `linux/export.h`, `linux/usb.h`, `linux/poll.h`.
- Detected declarations: `struct mon_bin_hdr`, `struct iso_rec`, `struct mon_bin_isodesc`, `struct mon_bin_stats`, `struct mon_bin_get`, `struct mon_bin_mfetch`, `struct mon_bin_get32`, `struct mon_bin_mfetch32`, `struct mon_pgmap`, `struct mon_reader_bin`.
- Atlas domain: Driver Families / drivers/usb.
- 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.