drivers/usb/core/devio.c
Source file repositories/reference/linux-study-clean/drivers/usb/core/devio.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/core/devio.c- Extension
.c- Size
- 73077 bytes
- Lines
- 2931
- 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/fs.hlinux/mm.hlinux/sched/signal.hlinux/slab.hlinux/signal.hlinux/poll.hlinux/module.hlinux/string.hlinux/usb.hlinux/usbdevice_fs.hlinux/usb/hcd.hlinux/usb/quirks.hlinux/cdev.hlinux/notifier.hlinux/security.hlinux/user_namespace.hlinux/scatterlist.hlinux/uaccess.hlinux/dma-mapping.hasm/byteorder.hlinux/moduleparam.husb.h
Detected Declarations
struct usb_dev_statestruct usb_memorystruct asyncenum snoop_whenfunction usbfs_increase_memory_usagefunction usbfs_decrease_memory_usagefunction connectedfunction dec_usb_memory_use_countfunction usbdev_vm_openfunction usbdev_vm_closefunction usbdev_mmapfunction usbdev_readfunction free_asyncfunction async_newpendingfunction async_removependingfunction list_for_each_entryfunction snoop_urbfunction snoop_urb_datafunction copy_urb_data_to_userfunction cancel_bulk_urbsfunction async_completedfunction destroy_asyncfunction destroy_async_on_interfacefunction destroy_all_asyncfunction themfunction driver_disconnectfunction driver_suspendfunction driver_resumefunction usbfs_notify_suspendfunction claimintffunction releaseintffunction checkintffunction findintfepfunction check_ctrlrecipfunction parse_usbdevfs_streamsfunction usbdev_openfunction usbdev_releasefunction usbfs_blocking_completionfunction usbfs_start_wait_urbfunction do_proc_controlfunction proc_controlfunction do_proc_bulkfunction proc_bulkfunction check_reset_of_active_epfunction proc_resetepfunction proc_clearhaltfunction proc_getdriverfunction proc_connectinfo
Annotated Snippet
const struct file_operations usbdev_file_operations = {
.owner = THIS_MODULE,
.llseek = no_seek_end_llseek,
.read = usbdev_read,
.poll = usbdev_poll,
.unlocked_ioctl = usbdev_ioctl,
.compat_ioctl = compat_ptr_ioctl,
.mmap = usbdev_mmap,
.open = usbdev_open,
.release = usbdev_release,
};
static void usbdev_remove(struct usb_device *udev)
{
struct usb_dev_state *ps;
/* Protect against simultaneous resume */
mutex_lock(&usbfs_mutex);
while (!list_empty(&udev->filelist)) {
ps = list_entry(udev->filelist.next, struct usb_dev_state, list);
destroy_all_async(ps);
wake_up_all(&ps->wait);
WRITE_ONCE(ps->not_yet_resumed, 0);
wake_up_all(&ps->wait_for_resume);
list_del_init(&ps->list);
if (ps->discsignr)
kill_pid_usb_asyncio(ps->discsignr, EPIPE, ps->disccontext,
ps->disc_pid, ps->cred);
}
mutex_unlock(&usbfs_mutex);
}
static int usbdev_notify(struct notifier_block *self,
unsigned long action, void *dev)
{
switch (action) {
case USB_DEVICE_ADD:
break;
case USB_DEVICE_REMOVE:
usbdev_remove(dev);
break;
}
return NOTIFY_OK;
}
static struct notifier_block usbdev_nb = {
.notifier_call = usbdev_notify,
};
static struct cdev usb_device_cdev;
int __init usb_devio_init(void)
{
int retval;
retval = register_chrdev_region(USB_DEVICE_DEV, USB_DEVICE_MAX,
"usb_device");
if (retval) {
printk(KERN_ERR "Unable to register minors for usb_device\n");
goto out;
}
cdev_init(&usb_device_cdev, &usbdev_file_operations);
retval = cdev_add(&usb_device_cdev, USB_DEVICE_DEV, USB_DEVICE_MAX);
if (retval) {
printk(KERN_ERR "Unable to get usb_device major %d\n",
USB_DEVICE_MAJOR);
goto error_cdev;
}
usb_register_notify(&usbdev_nb);
out:
return retval;
error_cdev:
unregister_chrdev_region(USB_DEVICE_DEV, USB_DEVICE_MAX);
goto out;
}
void usb_devio_cleanup(void)
{
usb_unregister_notify(&usbdev_nb);
cdev_del(&usb_device_cdev);
unregister_chrdev_region(USB_DEVICE_DEV, USB_DEVICE_MAX);
}
Annotation
- Immediate include surface: `linux/fs.h`, `linux/mm.h`, `linux/sched/signal.h`, `linux/slab.h`, `linux/signal.h`, `linux/poll.h`, `linux/module.h`, `linux/string.h`.
- Detected declarations: `struct usb_dev_state`, `struct usb_memory`, `struct async`, `enum snoop_when`, `function usbfs_increase_memory_usage`, `function usbfs_decrease_memory_usage`, `function connected`, `function dec_usb_memory_use_count`, `function usbdev_vm_open`, `function usbdev_vm_close`.
- 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.