drivers/usb/core/endpoint.c
Source file repositories/reference/linux-study-clean/drivers/usb/core/endpoint.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/core/endpoint.c- Extension
.c- Size
- 4212 bytes
- Lines
- 185
- Domain
- Driver Families
- Bucket
- drivers/usb
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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/spinlock.hlinux/slab.hlinux/sysfs.hlinux/usb.husb.h
Detected Declarations
struct ep_devicefunction wMaxPacketSize_showfunction type_showfunction interval_showfunction direction_showfunction ep_device_releasefunction usb_create_ep_devsfunction usb_remove_ep_devs
Annotated Snippet
struct ep_device {
struct usb_endpoint_descriptor *desc;
struct usb_device *udev;
struct device dev;
};
#define to_ep_device(_dev) \
container_of(_dev, struct ep_device, dev)
#define usb_ep_attr(field, format_string) \
static ssize_t field##_show(struct device *dev, \
struct device_attribute *attr, \
char *buf) \
{ \
struct ep_device *ep = to_ep_device(dev); \
return sysfs_emit(buf, format_string, ep->desc->field); \
} \
static DEVICE_ATTR_RO(field)
usb_ep_attr(bLength, "%02x\n");
usb_ep_attr(bEndpointAddress, "%02x\n");
usb_ep_attr(bmAttributes, "%02x\n");
usb_ep_attr(bInterval, "%02x\n");
static ssize_t wMaxPacketSize_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct ep_device *ep = to_ep_device(dev);
return sysfs_emit(buf, "%04x\n", usb_endpoint_maxp(ep->desc));
}
static DEVICE_ATTR_RO(wMaxPacketSize);
static ssize_t type_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct ep_device *ep = to_ep_device(dev);
char *type = "unknown";
switch (usb_endpoint_type(ep->desc)) {
case USB_ENDPOINT_XFER_CONTROL:
type = "Control";
break;
case USB_ENDPOINT_XFER_ISOC:
type = "Isoc";
break;
case USB_ENDPOINT_XFER_BULK:
type = "Bulk";
break;
case USB_ENDPOINT_XFER_INT:
type = "Interrupt";
break;
}
return sysfs_emit(buf, "%s\n", type);
}
static DEVICE_ATTR_RO(type);
static ssize_t interval_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct ep_device *ep = to_ep_device(dev);
unsigned int interval;
char unit;
interval = usb_decode_interval(ep->desc, ep->udev->speed);
if (interval % 1000) {
unit = 'u';
} else {
unit = 'm';
interval /= 1000;
}
return sysfs_emit(buf, "%d%cs\n", interval, unit);
}
static DEVICE_ATTR_RO(interval);
static ssize_t direction_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct ep_device *ep = to_ep_device(dev);
char *direction;
if (usb_endpoint_xfer_control(ep->desc))
direction = "both";
else if (usb_endpoint_dir_in(ep->desc))
direction = "in";
else
direction = "out";
return sysfs_emit(buf, "%s\n", direction);
}
static DEVICE_ATTR_RO(direction);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/spinlock.h`, `linux/slab.h`, `linux/sysfs.h`, `linux/usb.h`, `usb.h`.
- Detected declarations: `struct ep_device`, `function wMaxPacketSize_show`, `function type_show`, `function interval_show`, `function direction_show`, `function ep_device_release`, `function usb_create_ep_devs`, `function usb_remove_ep_devs`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: source implementation candidate.
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.