drivers/usb/core/driver.c
Source file repositories/reference/linux-study-clean/drivers/usb/core/driver.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/core/driver.c- Extension
.c- Size
- 60493 bytes
- Lines
- 2082
- 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.
- 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/device.hlinux/slab.hlinux/export.hlinux/usb.hlinux/usb/quirks.hlinux/usb/hcd.husb.h
Detected Declarations
function usb_store_new_idfunction usb_show_dynidsfunction new_id_showfunction new_id_storefunction remove_id_storefunction remove_id_showfunction usb_create_newid_filesfunction usb_remove_newid_filesfunction usb_free_dynidsfunction usb_probe_devicefunction usb_unbind_devicefunction usb_probe_interfacefunction usb_unbind_interfacefunction sleepfunction usb_shutdown_interfacefunction probingfunction disconnectfunction usb_match_devicefunction usb_match_one_id_intffunction usb_match_one_idfunction usb_driver_applicablefunction usb_device_matchfunction usb_ueventfunction __usb_bus_reprobe_driversfunction is_usb_device_driverfunction usb_register_device_driverfunction usb_deregister_device_driverfunction usb_register_devfunction usb_deregister_devfunction usb_forced_unbind_intffunction unbind_marked_interfacesfunction usb_rebind_intffunction rebind_marked_interfacesfunction usb_unbind_and_rebind_marked_interfacesfunction unbind_no_pm_drivers_interfacesfunction usb_suspend_devicefunction usb_resume_devicefunction usb_suspend_interfacefunction usb_resume_interfacefunction usb_suspend_bothfunction usb_resume_bothfunction choose_wakeupfunction usb_suspendfunction usb_resume_completefunction usb_resumefunction usb_enable_autosuspendfunction usb_disable_autosuspendfunction fail
Annotated Snippet
struct device_driver *driver,
const char *buf, size_t count)
{
struct usb_dynid *dynid;
u32 idVendor = 0;
u32 idProduct = 0;
unsigned int bInterfaceClass = 0;
u32 refVendor, refProduct;
int fields = 0;
int retval = 0;
fields = sscanf(buf, "%x %x %x %x %x", &idVendor, &idProduct,
&bInterfaceClass, &refVendor, &refProduct);
if (fields < 2)
return -EINVAL;
dynid = kzalloc_obj(*dynid);
if (!dynid)
return -ENOMEM;
INIT_LIST_HEAD(&dynid->node);
dynid->id.idVendor = idVendor;
dynid->id.idProduct = idProduct;
dynid->id.match_flags = USB_DEVICE_ID_MATCH_DEVICE;
if (fields > 2 && bInterfaceClass) {
if (bInterfaceClass > 255) {
retval = -EINVAL;
goto fail;
}
dynid->id.bInterfaceClass = (u8)bInterfaceClass;
dynid->id.match_flags |= USB_DEVICE_ID_MATCH_INT_CLASS;
}
if (fields > 4) {
const struct usb_device_id *id = id_table;
if (!id) {
retval = -ENODEV;
goto fail;
}
for (; id->match_flags; id++)
if (id->idVendor == refVendor && id->idProduct == refProduct)
break;
if (id->match_flags) {
dynid->id.driver_info = id->driver_info;
} else {
retval = -ENODEV;
goto fail;
}
}
mutex_lock(&usb_dynids_lock);
list_add_tail(&dynid->node, &dynids->list);
mutex_unlock(&usb_dynids_lock);
retval = driver_attach(driver);
if (retval)
return retval;
return count;
fail:
kfree(dynid);
return retval;
}
EXPORT_SYMBOL_GPL(usb_store_new_id);
ssize_t usb_show_dynids(struct usb_dynids *dynids, char *buf)
{
struct usb_dynid *dynid;
size_t count = 0;
guard(mutex)(&usb_dynids_lock);
list_for_each_entry(dynid, &dynids->list, node)
if (dynid->id.bInterfaceClass != 0)
count += sysfs_emit_at(buf, count, "%04x %04x %02x\n",
dynid->id.idVendor, dynid->id.idProduct,
dynid->id.bInterfaceClass);
else
count += sysfs_emit_at(buf, count, "%04x %04x\n",
dynid->id.idVendor, dynid->id.idProduct);
return count;
}
EXPORT_SYMBOL_GPL(usb_show_dynids);
static ssize_t new_id_show(struct device_driver *driver, char *buf)
{
Annotation
- Immediate include surface: `linux/device.h`, `linux/slab.h`, `linux/export.h`, `linux/usb.h`, `linux/usb/quirks.h`, `linux/usb/hcd.h`, `usb.h`.
- Detected declarations: `function usb_store_new_id`, `function usb_show_dynids`, `function new_id_show`, `function new_id_store`, `function remove_id_store`, `function remove_id_show`, `function usb_create_newid_files`, `function usb_remove_newid_files`, `function usb_free_dynids`, `function usb_probe_device`.
- 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.
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.