drivers/hid/bpf/hid_bpf_dispatch.c
Source file repositories/reference/linux-study-clean/drivers/hid/bpf/hid_bpf_dispatch.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hid/bpf/hid_bpf_dispatch.c- Extension
.c- Size
- 16734 bytes
- Lines
- 683
- 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.
- 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/bitops.hlinux/btf.hlinux/btf_ids.hlinux/filter.hlinux/hid.hlinux/hid_bpf.hlinux/init.hlinux/kfifo.hlinux/minmax.hlinux/module.hhid_bpf_dispatch.h
Detected Declarations
function dispatch_hid_bpf_device_eventfunction dispatch_hid_bpf_raw_requestsfunction srcu_read_lock_heldfunction dispatch_hid_bpf_output_reportfunction srcu_read_lock_heldfunction device_match_idfunction hid_put_devicefunction __hid_bpf_allocate_datafunction hid_bpf_allocate_event_datafunction hid_bpf_reconnectfunction hid_bpf_get_datafunction hid_bpf_allocate_contextfunction hid_bpf_release_contextfunction __hid_bpf_hw_check_paramsfunction hid_bpf_hw_requestfunction hid_bpf_hw_output_reportfunction __hid_bpf_input_reportfunction hid_bpf_try_input_reportfunction hid_bpf_input_reportfunction hid_bpf_connect_devicefunction hid_bpf_disconnect_devicefunction hid_bpf_destroy_devicefunction hid_bpf_device_initfunction hid_bpf_initexport hid_opsexport dispatch_hid_bpf_device_eventexport dispatch_hid_bpf_raw_requestsexport dispatch_hid_bpf_output_reportexport call_hid_bpf_rdesc_fixupexport hid_bpf_connect_deviceexport hid_bpf_disconnect_deviceexport hid_bpf_destroy_deviceexport hid_bpf_device_init
Annotated Snippet
if (e->hid_device_event) {
ret = e->hid_device_event(&ctx_kern.ctx, type, source);
if (ret < 0) {
rcu_read_unlock();
return ERR_PTR(ret);
}
if (ret)
ctx_kern.ctx.size = ret;
}
}
rcu_read_unlock();
ret = ctx_kern.ctx.size;
if (ret) {
if (ret > ctx_kern.ctx.allocated_size)
return ERR_PTR(-EINVAL);
*size = ret;
}
*buf_size = ctx_kern.ctx.allocated_size;
return ctx_kern.data;
}
EXPORT_SYMBOL_GPL(dispatch_hid_bpf_device_event);
int dispatch_hid_bpf_raw_requests(struct hid_device *hdev,
unsigned char reportnum, u8 *buf,
u32 size, enum hid_report_type rtype,
enum hid_class_request reqtype,
u64 source, bool from_bpf)
{
struct hid_bpf_ctx_kern ctx_kern = {
.ctx = {
.hid = hdev,
.allocated_size = size,
.size = size,
},
.data = buf,
.from_bpf = from_bpf,
};
struct hid_bpf_ops *e;
int ret, idx;
if (unlikely(hdev->bpf.destroyed))
return -ENODEV;
if (rtype >= HID_REPORT_TYPES)
return -EINVAL;
idx = srcu_read_lock(&hdev->bpf.srcu);
list_for_each_entry_srcu(e, &hdev->bpf.prog_list, list,
srcu_read_lock_held(&hdev->bpf.srcu)) {
if (!e->hid_hw_request)
continue;
ret = e->hid_hw_request(&ctx_kern.ctx, reportnum, rtype, reqtype, source);
if (ret)
goto out;
}
ret = 0;
out:
srcu_read_unlock(&hdev->bpf.srcu, idx);
return ret;
}
EXPORT_SYMBOL_GPL(dispatch_hid_bpf_raw_requests);
int dispatch_hid_bpf_output_report(struct hid_device *hdev,
__u8 *buf, u32 size, u64 source,
bool from_bpf)
{
struct hid_bpf_ctx_kern ctx_kern = {
.ctx = {
.hid = hdev,
.allocated_size = size,
.size = size,
},
.data = buf,
.from_bpf = from_bpf,
};
struct hid_bpf_ops *e;
int ret, idx;
if (unlikely(hdev->bpf.destroyed))
return -ENODEV;
idx = srcu_read_lock(&hdev->bpf.srcu);
list_for_each_entry_srcu(e, &hdev->bpf.prog_list, list,
srcu_read_lock_held(&hdev->bpf.srcu)) {
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/btf.h`, `linux/btf_ids.h`, `linux/filter.h`, `linux/hid.h`, `linux/hid_bpf.h`, `linux/init.h`, `linux/kfifo.h`.
- Detected declarations: `function dispatch_hid_bpf_device_event`, `function dispatch_hid_bpf_raw_requests`, `function srcu_read_lock_held`, `function dispatch_hid_bpf_output_report`, `function srcu_read_lock_held`, `function device_match_id`, `function hid_put_device`, `function __hid_bpf_allocate_data`, `function hid_bpf_allocate_event_data`, `function hid_bpf_reconnect`.
- 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.
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.