drivers/hid/hid-quirks.c
Source file repositories/reference/linux-study-clean/drivers/hid/hid-quirks.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hid/hid-quirks.c- Extension
.c- Size
- 81785 bytes
- Lines
- 1398
- Domain
- Driver Families
- Bucket
- drivers/hid
- 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.
- 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/hid.hlinux/export.hlinux/slab.hlinux/mutex.hlinux/input/elan-i2c-ids.hhid-ids.h
Detected Declarations
struct quirks_list_structfunction devicesfunction hid_ignorefunction list_for_each_entryfunction hid_modify_dquirkfunction list_for_each_entryfunction hid_remove_all_dquirksfunction hid_quirks_initfunction hid_quirks_exitfunction hid_gets_squirkfunction hid_lookup_quirkexport hid_ignoreexport hid_quirks_initexport hid_quirks_exitexport hid_lookup_quirk
Annotated Snippet
struct quirks_list_struct {
struct hid_device_id hid_bl_item;
struct list_head node;
};
static LIST_HEAD(dquirks_list);
static DEFINE_MUTEX(dquirks_lock);
/* Runtime ("dynamic") quirks manipulation functions */
/**
* hid_exists_dquirk - find any dynamic quirks for a HID device
* @hdev: the HID device to match
*
* Description:
* Scans dquirks_list for a matching dynamic quirk and returns
* the pointer to the relevant struct hid_device_id if found.
* Must be called with a read lock held on dquirks_lock.
*
* Return: NULL if no quirk found, struct hid_device_id * if found.
*/
static struct hid_device_id *hid_exists_dquirk(const struct hid_device *hdev)
{
struct quirks_list_struct *q;
struct hid_device_id *bl_entry = NULL;
list_for_each_entry(q, &dquirks_list, node) {
if (hid_match_one_id(hdev, &q->hid_bl_item)) {
bl_entry = &q->hid_bl_item;
break;
}
}
if (bl_entry != NULL)
dbg_hid("Found dynamic quirk 0x%lx for HID device 0x%04x:0x%04x\n",
bl_entry->driver_data, bl_entry->vendor,
bl_entry->product);
return bl_entry;
}
/**
* hid_modify_dquirk - add/replace a HID quirk
* @id: the HID device to match
* @quirks: the unsigned long quirks value to add/replace
*
* Description:
* If an dynamic quirk exists in memory for this device, replace its
* quirks value with what was provided. Otherwise, add the quirk
* to the dynamic quirks list.
*
* Return: 0 OK, -error on failure.
*/
static int hid_modify_dquirk(const struct hid_device_id *id,
const unsigned long quirks)
{
struct hid_device *hdev;
struct quirks_list_struct *q_new, *q;
int list_edited = 0;
int ret = 0;
hdev = kzalloc_obj(*hdev);
if (!hdev)
return -ENOMEM;
q_new = kmalloc_obj(struct quirks_list_struct);
if (!q_new) {
ret = -ENOMEM;
goto out;
}
hdev->bus = q_new->hid_bl_item.bus = id->bus;
hdev->group = q_new->hid_bl_item.group = id->group;
hdev->vendor = q_new->hid_bl_item.vendor = id->vendor;
hdev->product = q_new->hid_bl_item.product = id->product;
q_new->hid_bl_item.driver_data = quirks;
mutex_lock(&dquirks_lock);
list_for_each_entry(q, &dquirks_list, node) {
if (hid_match_one_id(hdev, &q->hid_bl_item)) {
list_replace(&q->node, &q_new->node);
kfree(q);
list_edited = 1;
break;
}
Annotation
- Immediate include surface: `linux/hid.h`, `linux/export.h`, `linux/slab.h`, `linux/mutex.h`, `linux/input/elan-i2c-ids.h`, `hid-ids.h`.
- Detected declarations: `struct quirks_list_struct`, `function devices`, `function hid_ignore`, `function list_for_each_entry`, `function hid_modify_dquirk`, `function list_for_each_entry`, `function hid_remove_all_dquirks`, `function hid_quirks_init`, `function hid_quirks_exit`, `function hid_gets_squirk`.
- Atlas domain: Driver Families / drivers/hid.
- Implementation status: integration 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.