drivers/usb/gadget/legacy/inode.c
Source file repositories/reference/linux-study-clean/drivers/usb/gadget/legacy/inode.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/gadget/legacy/inode.c- Extension
.c- Size
- 53539 bytes
- Lines
- 2143
- 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/init.hlinux/module.hlinux/fs.hlinux/fs_context.hlinux/pagemap.hlinux/uts.hlinux/wait.hlinux/compiler.hlinux/uaccess.hlinux/sched.hlinux/slab.hlinux/string_choices.hlinux/poll.hlinux/kthread.hlinux/aio.hlinux/uio.hlinux/refcount.hlinux/delay.hlinux/device.hlinux/moduleparam.hlinux/usb/gadgetfs.hlinux/usb/gadget.hlinux/usb/composite.h
Detected Declarations
struct dev_datastruct ep_datastruct kiocb_privenum ep0_stateenum ep_statefunction get_devfunction put_devfunction get_epfunction put_epfunction epio_completefunction get_ready_epfunction ep_iofunction ep_releasefunction ep_ioctlfunction ep_aio_cancelfunction ep_user_copy_workerfunction ep_aio_completefunction ep_aiofunction ep_read_iterfunction ep_write_iterfunction ep_configfunction ep_openfunction ep0_readablefunction clean_reqfunction ep0_completefunction setup_reqfunction ep0_readfunction next_eventfunction ep0_writefunction ep0_fasyncfunction dev_releasefunction ep0_pollfunction gadget_dev_ioctlfunction configurationfunction config_buffunction gadgetfs_setupfunction destroy_ep_filesfunction activate_ep_filesfunction gadget_for_each_epfunction gadgetfs_unbindfunction gadgetfs_bindfunction gadgetfs_disconnectfunction gadgetfs_suspendfunction configurefunction dev_configfunction gadget_dev_openfunction gadgetfs_make_inodefunction gadgetfs_create_file
Annotated Snippet
static const struct file_operations ep_io_operations = {
.owner = THIS_MODULE,
.open = ep_open,
.release = ep_release,
.unlocked_ioctl = ep_ioctl,
.read_iter = ep_read_iter,
.write_iter = ep_write_iter,
};
/* ENDPOINT INITIALIZATION
*
* fd = open ("/dev/gadget/$ENDPOINT", O_RDWR)
* status = write (fd, descriptors, sizeof descriptors)
*
* That write establishes the endpoint configuration, configuring
* the controller to process bulk, interrupt, or isochronous transfers
* at the right maxpacket size, and so on.
*
* The descriptors are message type 1, identified by a host order u32
* at the beginning of what's written. Descriptor order is: full/low
* speed descriptor, then optional high speed descriptor.
*/
static ssize_t
ep_config (struct ep_data *data, const char *buf, size_t len)
{
struct usb_ep *ep;
u32 tag;
int value, length = len;
if (data->state != STATE_EP_READY) {
value = -EL2HLT;
goto fail;
}
value = len;
if (len < USB_DT_ENDPOINT_SIZE + 4)
goto fail0;
/* we might need to change message format someday */
memcpy(&tag, buf, 4);
if (tag != 1) {
DBG(data->dev, "config %s, bad tag %d\n", data->name, tag);
goto fail0;
}
buf += 4;
len -= 4;
/* NOTE: audio endpoint extensions not accepted here;
* just don't include the extra bytes.
*/
/* full/low speed descriptor, then high speed */
memcpy(&data->desc, buf, USB_DT_ENDPOINT_SIZE);
if (data->desc.bLength != USB_DT_ENDPOINT_SIZE
|| data->desc.bDescriptorType != USB_DT_ENDPOINT)
goto fail0;
if (len != USB_DT_ENDPOINT_SIZE) {
if (len != 2 * USB_DT_ENDPOINT_SIZE)
goto fail0;
memcpy(&data->hs_desc, buf + USB_DT_ENDPOINT_SIZE,
USB_DT_ENDPOINT_SIZE);
if (data->hs_desc.bLength != USB_DT_ENDPOINT_SIZE
|| data->hs_desc.bDescriptorType
!= USB_DT_ENDPOINT) {
DBG(data->dev, "config %s, bad hs length or type\n",
data->name);
goto fail0;
}
}
spin_lock_irq (&data->dev->lock);
if (data->dev->state == STATE_DEV_UNBOUND) {
value = -ENOENT;
goto gone;
} else {
ep = data->ep;
if (ep == NULL) {
value = -ENODEV;
goto gone;
}
}
switch (data->dev->gadget->speed) {
case USB_SPEED_LOW:
case USB_SPEED_FULL:
ep->desc = &data->desc;
break;
case USB_SPEED_HIGH:
/* fails if caller didn't provide that descriptor... */
ep->desc = &data->hs_desc;
Annotation
- Immediate include surface: `linux/init.h`, `linux/module.h`, `linux/fs.h`, `linux/fs_context.h`, `linux/pagemap.h`, `linux/uts.h`, `linux/wait.h`, `linux/compiler.h`.
- Detected declarations: `struct dev_data`, `struct ep_data`, `struct kiocb_priv`, `enum ep0_state`, `enum ep_state`, `function get_dev`, `function put_dev`, `function get_ep`, `function put_ep`, `function epio_complete`.
- 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.