drivers/usb/core/quirks.c
Source file repositories/reference/linux-study-clean/drivers/usb/core/quirks.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/core/quirks.c- Extension
.c- Size
- 24194 bytes
- Lines
- 805
- 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.
- 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/moduleparam.hlinux/usb.hlinux/usb/quirks.hlinux/usb/hcd.husb.h
Detected Declarations
struct quirk_entryfunction quirks_param_setfunction usb_endpoint_is_ignoredfunction usb_match_any_interfacefunction usb_amd_resume_quirkfunction usb_detect_static_quirksfunction usb_detect_dynamic_quirksfunction usb_detect_quirksfunction usb_detect_interface_quirksfunction usb_release_quirk_list
Annotated Snippet
struct quirk_entry {
u16 vid;
u16 pid;
u32 flags;
};
static DEFINE_MUTEX(quirk_mutex);
static struct quirk_entry *quirk_list;
static unsigned int quirk_count;
static char quirks_param[128];
static int quirks_param_set(const char *value, const struct kernel_param *kp)
{
char *val, *p, *field;
u16 vid, pid;
u32 flags;
size_t i;
int err;
val = kstrdup(value, GFP_KERNEL);
if (!val)
return -ENOMEM;
err = param_set_copystring(val, kp);
if (err) {
kfree(val);
return err;
}
mutex_lock(&quirk_mutex);
if (!*val) {
quirk_count = 0;
kfree(quirk_list);
quirk_list = NULL;
goto unlock;
}
for (quirk_count = 1, i = 0; val[i]; i++)
if (val[i] == ',')
quirk_count++;
if (quirk_list) {
kfree(quirk_list);
quirk_list = NULL;
}
quirk_list = kzalloc_objs(struct quirk_entry, quirk_count);
if (!quirk_list) {
quirk_count = 0;
mutex_unlock(&quirk_mutex);
kfree(val);
return -ENOMEM;
}
for (i = 0, p = val; p && *p;) {
/* Each entry consists of VID:PID:flags */
field = strsep(&p, ":");
if (!field)
break;
if (kstrtou16(field, 16, &vid))
break;
field = strsep(&p, ":");
if (!field)
break;
if (kstrtou16(field, 16, &pid))
break;
field = strsep(&p, ",");
if (!field || !*field)
break;
/* Collect the flags */
for (flags = 0; *field; field++) {
switch (*field) {
case 'a':
flags |= USB_QUIRK_STRING_FETCH_255;
break;
case 'b':
flags |= USB_QUIRK_RESET_RESUME;
break;
case 'c':
flags |= USB_QUIRK_NO_SET_INTF;
break;
case 'd':
Annotation
- Immediate include surface: `linux/moduleparam.h`, `linux/usb.h`, `linux/usb/quirks.h`, `linux/usb/hcd.h`, `usb.h`.
- Detected declarations: `struct quirk_entry`, `function quirks_param_set`, `function usb_endpoint_is_ignored`, `function usb_match_any_interface`, `function usb_amd_resume_quirk`, `function usb_detect_static_quirks`, `function usb_detect_dynamic_quirks`, `function usb_detect_quirks`, `function usb_detect_interface_quirks`, `function usb_release_quirk_list`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: source 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.