drivers/usb/core/usb.c
Source file repositories/reference/linux-study-clean/drivers/usb/core/usb.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/core/usb.c- Extension
.c- Size
- 37467 bytes
- Lines
- 1295
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/moduleparam.hlinux/of.hlinux/string.hlinux/bitops.hlinux/slab.hlinux/kmod.hlinux/init.hlinux/spinlock.hlinux/errno.hlinux/usb.hlinux/usb/hcd.hlinux/mutex.hlinux/workqueue.hlinux/debugfs.hlinux/usb/of.hasm/io.hlinux/scatterlist.hlinux/mm.hlinux/dma-mapping.hhub.htrace.h
Detected Declarations
struct find_interface_argstruct each_dev_argfunction usb_disabledfunction match_endpointfunction usb_find_common_endpointsfunction usb_find_common_endpoints_reversefunction usb_find_endpointfunction usb_check_bulk_endpointsfunction usb_check_int_endpointsfunction usb_find_alt_settingfunction __find_interfacefunction __each_devfunction usb_for_each_devfunction usb_release_devfunction usb_dev_ueventfunction usb_port_suspendfunction usb_dev_completefunction usb_dev_suspendfunction usb_dev_resumefunction usb_dev_freezefunction usb_dev_thawfunction usb_dev_powerofffunction usb_dev_restorefunction usb_dev_authorizedfunction driversfunction probefunction usb_put_devfunction probefunction usb_put_intffunction suspendfunction usb_get_current_frame_numberfunction __usb_get_extra_descriptorfunction addressfunction usb_alloc_coherentfunction addressfunction usb_alloc_noncoherentfunction usb_endpoint_max_periodic_payloadfunction usb_endpoint_is_hs_isoc_doublefunction usb_bus_notifyfunction usb_debugfs_initfunction usb_debugfs_cleanupfunction usb_initfunction usb_exitmodule init usb_initexport usb_disabledexport usb_find_common_endpointsexport usb_find_common_endpoints_reverseexport usb_check_bulk_endpoints
Annotated Snippet
struct device_driver *drv;
};
static int __find_interface(struct device *dev, const void *data)
{
const struct find_interface_arg *arg = data;
struct usb_interface *intf;
if (!is_usb_interface(dev))
return 0;
if (dev->driver != arg->drv)
return 0;
intf = to_usb_interface(dev);
return intf->minor == arg->minor;
}
/**
* usb_find_interface - find usb_interface pointer for driver and device
* @drv: the driver whose current configuration is considered
* @minor: the minor number of the desired device
*
* This walks the bus device list and returns a pointer to the interface
* with the matching minor and driver. Note, this only works for devices
* that share the USB major number.
*
* Return: A pointer to the interface with the matching major and @minor.
*/
struct usb_interface *usb_find_interface(struct usb_driver *drv, int minor)
{
struct find_interface_arg argb;
struct device *dev;
argb.minor = minor;
argb.drv = &drv->driver;
dev = bus_find_device(&usb_bus_type, NULL, &argb, __find_interface);
/* Drop reference count from bus_find_device */
put_device(dev);
return dev ? to_usb_interface(dev) : NULL;
}
EXPORT_SYMBOL_GPL(usb_find_interface);
struct each_dev_arg {
void *data;
int (*fn)(struct usb_device *, void *);
};
static int __each_dev(struct device *dev, void *data)
{
struct each_dev_arg *arg = (struct each_dev_arg *)data;
/* There are struct usb_interface on the same bus, filter them out */
if (!is_usb_device(dev))
return 0;
return arg->fn(to_usb_device(dev), arg->data);
}
/**
* usb_for_each_dev - iterate over all USB devices in the system
* @data: data pointer that will be handed to the callback function
* @fn: callback function to be called for each USB device
*
* Iterate over all USB devices and call @fn for each, passing it @data. If it
* returns anything other than 0, we break the iteration prematurely and return
* that value.
*/
int usb_for_each_dev(void *data, int (*fn)(struct usb_device *, void *))
{
struct each_dev_arg arg = {data, fn};
return bus_for_each_dev(&usb_bus_type, NULL, &arg, __each_dev);
}
EXPORT_SYMBOL_GPL(usb_for_each_dev);
/**
* usb_release_dev - free a usb device structure when all users of it are finished.
* @dev: device that's been disconnected
*
* Will be called only by the device core when all users of this usb device are
* done.
*/
static void usb_release_dev(struct device *dev)
{
struct usb_device *udev;
struct usb_hcd *hcd;
Annotation
- Immediate include surface: `linux/module.h`, `linux/moduleparam.h`, `linux/of.h`, `linux/string.h`, `linux/bitops.h`, `linux/slab.h`, `linux/kmod.h`, `linux/init.h`.
- Detected declarations: `struct find_interface_arg`, `struct each_dev_arg`, `function usb_disabled`, `function match_endpoint`, `function usb_find_common_endpoints`, `function usb_find_common_endpoints_reverse`, `function usb_find_endpoint`, `function usb_check_bulk_endpoints`, `function usb_check_int_endpoints`, `function usb_find_alt_setting`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: pattern implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.