drivers/usb/core/urb.c
Source file repositories/reference/linux-study-clean/drivers/usb/core/urb.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/core/urb.c- Extension
.c- Size
- 34130 bytes
- Lines
- 1022
- 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/module.hlinux/string.hlinux/bitops.hlinux/slab.hlinux/log2.hlinux/kmsan.hlinux/usb.hlinux/wait.hlinux/usb/hcd.hlinux/scatterlist.h
Detected Declarations
function urb_destroyfunction usb_alloc_urbfunction usb_free_urbfunction usb_free_urbfunction usb_anchor_urbfunction usb_anchor_check_wakeupfunction __usb_unanchor_urbfunction usb_unanchor_urbfunction usb_pipe_type_checkfunction usb_urb_ep_type_checkfunction usb_submit_urbfunction twofunction usb_unlink_urbfunction contextfunction contextfunction usb_unpoison_urbfunction usb_block_urbfunction usb_kill_anchored_urbsfunction usb_poison_anchored_urbsfunction usb_unpoison_anchored_urbsfunction usb_anchor_suspend_wakeupsfunction usb_anchor_resume_wakeupsfunction usb_wait_anchor_empty_timeoutfunction usb_scuttle_anchored_urbsfunction usb_anchor_emptyexport usb_init_urbexport usb_alloc_urbexport usb_free_urbexport usb_get_urbexport usb_anchor_urbexport usb_unanchor_urbexport usb_pipe_type_checkexport usb_urb_ep_type_checkexport usb_submit_urbexport usb_unlink_urbexport usb_kill_urbexport usb_poison_urbexport usb_unpoison_urbexport usb_block_urbexport usb_kill_anchored_urbsexport usb_poison_anchored_urbsexport usb_unpoison_anchored_urbsexport usb_anchor_suspend_wakeupsexport usb_anchor_resume_wakeupsexport usb_wait_anchor_empty_timeoutexport usb_get_from_anchorexport usb_scuttle_anchored_urbsexport usb_anchor_empty
Annotated Snippet
if (le16_to_cpu(setup->wLength) != urb->transfer_buffer_length) {
dev_dbg(&dev->dev, "BOGUS control len %d doesn't match transfer length %d\n",
le16_to_cpu(setup->wLength),
urb->transfer_buffer_length);
return -EBADR;
}
} else {
is_out = usb_endpoint_dir_out(&ep->desc);
}
/* Clear the internal flags and cache the direction for later use */
urb->transfer_flags &= ~(URB_DIR_MASK | URB_DMA_MAP_SINGLE |
URB_DMA_MAP_PAGE | URB_DMA_MAP_SG | URB_MAP_LOCAL |
URB_SETUP_MAP_SINGLE | URB_SETUP_MAP_LOCAL |
URB_DMA_SG_COMBINED);
urb->transfer_flags |= (is_out ? URB_DIR_OUT : URB_DIR_IN);
kmsan_handle_urb(urb, is_out);
if (xfertype != USB_ENDPOINT_XFER_CONTROL &&
dev->state < USB_STATE_CONFIGURED)
return -ENODEV;
max = usb_endpoint_maxp(&ep->desc);
is_eusb2_isoch_double = usb_endpoint_is_hs_isoc_double(dev, ep);
if (!max && !is_eusb2_isoch_double) {
dev_dbg(&dev->dev,
"bogus endpoint ep%d%s in %s (bad maxpacket %d)\n",
usb_endpoint_num(&ep->desc), is_out ? "out" : "in",
__func__, max);
return -EMSGSIZE;
}
/* periodic transfers limit size per frame/uframe,
* but drivers only control those sizes for ISO.
* while we're checking, initialize return status.
*/
if (xfertype == USB_ENDPOINT_XFER_ISOC) {
int n, len;
/* SuperSpeed isoc endpoints have up to 16 bursts of up to
* 3 packets each
*/
if (dev->speed >= USB_SPEED_SUPER) {
int burst = 1 + ep->ss_ep_comp.bMaxBurst;
int mult = USB_SS_MULT(ep->ss_ep_comp.bmAttributes);
max *= burst;
max *= mult;
}
if (dev->speed == USB_SPEED_SUPER_PLUS &&
USB_SS_SSP_ISOC_COMP(ep->ss_ep_comp.bmAttributes)) {
struct usb_ssp_isoc_ep_comp_descriptor *isoc_ep_comp;
isoc_ep_comp = &ep->ssp_isoc_ep_comp;
max = le32_to_cpu(isoc_ep_comp->dwBytesPerInterval);
}
/* High speed, 1-3 packets/uframe, max 6 for eUSB2 double bw */
if (dev->speed == USB_SPEED_HIGH) {
if (is_eusb2_isoch_double)
max = le32_to_cpu(ep->eusb2_isoc_ep_comp.dwBytesPerInterval);
else
max *= usb_endpoint_maxp_mult(&ep->desc);
}
if (urb->number_of_packets <= 0)
return -EINVAL;
for (n = 0; n < urb->number_of_packets; n++) {
len = urb->iso_frame_desc[n].length;
if (len < 0 || len > max)
return -EMSGSIZE;
urb->iso_frame_desc[n].status = -EXDEV;
urb->iso_frame_desc[n].actual_length = 0;
}
} else if (urb->num_sgs && !urb->dev->bus->no_sg_constraint) {
struct scatterlist *sg;
int i;
for_each_sg(urb->sg, sg, urb->num_sgs - 1, i)
if (sg->length % max)
return -EINVAL;
}
/* the I/O buffer must be mapped/unmapped, except when length=0 */
if (urb->transfer_buffer_length > INT_MAX)
return -EMSGSIZE;
/*
* stuff that drivers shouldn't do, but which shouldn't
* cause problems in HCDs if they get it wrong.
Annotation
- Immediate include surface: `linux/module.h`, `linux/string.h`, `linux/bitops.h`, `linux/slab.h`, `linux/log2.h`, `linux/kmsan.h`, `linux/usb.h`, `linux/wait.h`.
- Detected declarations: `function urb_destroy`, `function usb_alloc_urb`, `function usb_free_urb`, `function usb_free_urb`, `function usb_anchor_urb`, `function usb_anchor_check_wakeup`, `function __usb_unanchor_urb`, `function usb_unanchor_urb`, `function usb_pipe_type_check`, `function usb_urb_ep_type_check`.
- 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.