drivers/usb/gadget/composite.c
Source file repositories/reference/linux-study-clean/drivers/usb/gadget/composite.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/gadget/composite.c- Extension
.c- Size
- 77315 bytes
- Lines
- 2806
- Domain
- Driver Families
- Bucket
- drivers/usb
- 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/kallsyms.hlinux/kernel.hlinux/slab.hlinux/module.hlinux/device.hlinux/utsname.hlinux/bitfield.hlinux/uuid.hlinux/usb/composite.hlinux/usb/otg.hlinux/usb/webusb.hlinux/unaligned.hu_os_desc.h
Detected Declarations
struct usb_os_stringfunction function_descriptorsfunction next_descfunction config_ep_by_speed_and_altfunction config_ep_by_speedfunction usb_add_functionfunction usb_remove_functionfunction daemonfunction usb_function_deactivatefunction usb_interface_idfunction usb_func_wakeupfunction encode_bMaxPowerfunction check_remote_wakeup_configfunction config_buffunction config_descfunction count_configsfunction bos_descfunction device_qualfunction reset_configfunction list_for_each_entryfunction set_configfunction usb_add_config_onlyfunction usb_add_configfunction remove_configfunction languagefunction lookup_stringfunction get_stringfunction list_for_each_entryfunction list_for_each_entryfunction list_for_each_entryfunction list_for_each_entryfunction list_for_each_entryfunction usb_string_idfunction usb_string_ids_tabfunction usb_gstrings_attachfunction usb_string_ids_nfunction composite_setup_completefunction composite_ep0_queuefunction count_ext_compatfunction fill_ext_compatfunction count_ext_propfunction len_ext_propfunction fill_ext_propfunction setupfunction SetFeaturefunction recipientsfunction list_for_each_entryfunction __composite_disconnect
Annotated Snippet
struct usb_os_string {
__u8 bLength;
__u8 bDescriptorType;
__u8 qwSignature[OS_STRING_QW_SIGN_LEN];
__u8 bMS_VendorCode;
__u8 bPad;
} __packed;
/*
* The code in this file is utility code, used to build a gadget driver
* from one or more "function" drivers, one or more "configuration"
* objects, and a "usb_composite_driver" by gluing them together along
* with the relevant device-wide data.
*/
static struct usb_gadget_strings **get_containers_gs(
struct usb_gadget_string_container *uc)
{
return (struct usb_gadget_strings **)uc->stash;
}
/**
* function_descriptors() - get function descriptors for speed
* @f: the function
* @speed: the speed
*
* Returns the descriptors or NULL if not set.
*/
static struct usb_descriptor_header **
function_descriptors(struct usb_function *f,
enum usb_device_speed speed)
{
struct usb_descriptor_header **descriptors;
/*
* NOTE: we try to help gadget drivers which might not be setting
* max_speed appropriately.
*/
switch (speed) {
case USB_SPEED_SUPER_PLUS:
descriptors = f->ssp_descriptors;
if (descriptors)
break;
fallthrough;
case USB_SPEED_SUPER:
descriptors = f->ss_descriptors;
if (descriptors)
break;
fallthrough;
case USB_SPEED_HIGH:
descriptors = f->hs_descriptors;
if (descriptors)
break;
fallthrough;
default:
descriptors = f->fs_descriptors;
}
/*
* if we can't find any descriptors at all, then this gadget deserves to
* Oops with a NULL pointer dereference
*/
return descriptors;
}
/**
* next_desc() - advance to the next desc_type descriptor
* @t: currect pointer within descriptor array
* @desc_type: descriptor type
*
* Return: next desc_type descriptor or NULL
*
* Iterate over @t until either desc_type descriptor found or
* NULL (that indicates end of list) encountered
*/
static struct usb_descriptor_header**
next_desc(struct usb_descriptor_header **t, u8 desc_type)
{
for (; *t; t++) {
if ((*t)->bDescriptorType == desc_type)
return t;
}
return NULL;
}
/*
* for_each_desc() - iterate over desc_type descriptors in the
* descriptors list
Annotation
- Immediate include surface: `linux/kallsyms.h`, `linux/kernel.h`, `linux/slab.h`, `linux/module.h`, `linux/device.h`, `linux/utsname.h`, `linux/bitfield.h`, `linux/uuid.h`.
- Detected declarations: `struct usb_os_string`, `function function_descriptors`, `function next_desc`, `function config_ep_by_speed_and_alt`, `function config_ep_by_speed`, `function usb_add_function`, `function usb_remove_function`, `function daemon`, `function usb_function_deactivate`, `function usb_interface_id`.
- Atlas domain: Driver Families / drivers/usb.
- 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.