drivers/usb/usbip/usbip_event.c
Source file repositories/reference/linux-study-clean/drivers/usb/usbip/usbip_event.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/usbip/usbip_event.c- Extension
.c- Size
- 3998 bytes
- Lines
- 197
- Domain
- Driver Families
- Bucket
- drivers/usb
- 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/kthread.hlinux/export.hlinux/slab.hlinux/workqueue.husbip_common.h
Detected Declarations
struct usbip_eventfunction set_eventfunction unset_eventfunction event_handlerfunction usbip_start_ehfunction usbip_stop_ehfunction usbip_init_ehfunction usbip_finish_ehfunction usbip_event_addfunction list_for_each_entry_reversefunction usbip_event_happenedfunction usbip_in_ehexport usbip_start_ehexport usbip_stop_ehexport usbip_event_addexport usbip_event_happenedexport usbip_in_eh
Annotated Snippet
struct usbip_event {
struct list_head node;
struct usbip_device *ud;
};
static DEFINE_SPINLOCK(event_lock);
static LIST_HEAD(event_list);
static void set_event(struct usbip_device *ud, unsigned long event)
{
unsigned long flags;
spin_lock_irqsave(&ud->lock, flags);
ud->event |= event;
spin_unlock_irqrestore(&ud->lock, flags);
}
static void unset_event(struct usbip_device *ud, unsigned long event)
{
unsigned long flags;
spin_lock_irqsave(&ud->lock, flags);
ud->event &= ~event;
spin_unlock_irqrestore(&ud->lock, flags);
}
static struct usbip_device *get_event(void)
{
struct usbip_event *ue = NULL;
struct usbip_device *ud = NULL;
unsigned long flags;
spin_lock_irqsave(&event_lock, flags);
if (!list_empty(&event_list)) {
ue = list_first_entry(&event_list, struct usbip_event, node);
list_del(&ue->node);
}
spin_unlock_irqrestore(&event_lock, flags);
if (ue) {
ud = ue->ud;
kfree(ue);
}
return ud;
}
static struct task_struct *worker_context;
static void event_handler(struct work_struct *work)
{
struct usbip_device *ud;
if (worker_context == NULL) {
worker_context = current;
}
while ((ud = get_event()) != NULL) {
usbip_dbg_eh("pending event %lx\n", ud->event);
mutex_lock(&ud->sysfs_lock);
/*
* NOTE: shutdown must come first.
* Shutdown the device.
*/
if (ud->event & USBIP_EH_SHUTDOWN) {
ud->eh_ops.shutdown(ud);
unset_event(ud, USBIP_EH_SHUTDOWN);
}
/* Reset the device. */
if (ud->event & USBIP_EH_RESET) {
ud->eh_ops.reset(ud);
unset_event(ud, USBIP_EH_RESET);
}
/* Mark the device as unusable. */
if (ud->event & USBIP_EH_UNUSABLE) {
ud->eh_ops.unusable(ud);
unset_event(ud, USBIP_EH_UNUSABLE);
}
mutex_unlock(&ud->sysfs_lock);
wake_up(&ud->eh_waitq);
}
}
int usbip_start_eh(struct usbip_device *ud)
{
init_waitqueue_head(&ud->eh_waitq);
ud->event = 0;
Annotation
- Immediate include surface: `linux/kthread.h`, `linux/export.h`, `linux/slab.h`, `linux/workqueue.h`, `usbip_common.h`.
- Detected declarations: `struct usbip_event`, `function set_event`, `function unset_event`, `function event_handler`, `function usbip_start_eh`, `function usbip_stop_eh`, `function usbip_init_eh`, `function usbip_finish_eh`, `function usbip_event_add`, `function list_for_each_entry_reverse`.
- Atlas domain: Driver Families / drivers/usb.
- 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.