drivers/usb/usbip/stub_dev.c
Source file repositories/reference/linux-study-clean/drivers/usb/usbip/stub_dev.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/usbip/stub_dev.c- Extension
.c- Size
- 12428 bytes
- Lines
- 535
- 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/device.hlinux/file.hlinux/kthread.hlinux/module.husbip_common.hstub.h
Detected Declarations
function Copyrightfunction usbip_sockfd_storefunction stub_shutdown_connectionfunction list_for_each_entry_safefunction list_for_each_entry_safefunction stub_device_resetfunction stub_device_unusablefunction stub_device_freefunction stub_probefunction shutdown_busidfunction usb_disconnectfunction stub_suspendfunction stub_resume
Annotated Snippet
if (sdev->ud.status != SDEV_ST_AVAILABLE) {
dev_err(dev, "not ready\n");
goto err;
}
socket = sockfd_lookup(sockfd, &err);
if (!socket) {
dev_err(dev, "failed to lookup sock");
goto err;
}
if (socket->type != SOCK_STREAM) {
dev_err(dev, "Expecting SOCK_STREAM - found %d",
socket->type);
goto sock_err;
}
/* unlock and create threads and get tasks */
spin_unlock_irq(&sdev->ud.lock);
tcp_rx = kthread_create(stub_rx_loop, &sdev->ud, "stub_rx");
if (IS_ERR(tcp_rx)) {
sockfd_put(socket);
goto unlock_mutex;
}
tcp_tx = kthread_create(stub_tx_loop, &sdev->ud, "stub_tx");
if (IS_ERR(tcp_tx)) {
kthread_stop(tcp_rx);
sockfd_put(socket);
goto unlock_mutex;
}
/* get task structs now */
get_task_struct(tcp_rx);
get_task_struct(tcp_tx);
/* lock and update sdev->ud state */
spin_lock_irq(&sdev->ud.lock);
sdev->ud.tcp_socket = socket;
sdev->ud.sockfd = sockfd;
sdev->ud.tcp_rx = tcp_rx;
sdev->ud.tcp_tx = tcp_tx;
sdev->ud.status = SDEV_ST_USED;
spin_unlock_irq(&sdev->ud.lock);
wake_up_process(sdev->ud.tcp_rx);
wake_up_process(sdev->ud.tcp_tx);
mutex_unlock(&sdev->ud.sysfs_lock);
} else {
dev_info(dev, "stub down\n");
mutex_lock(&sdev->ud.sysfs_lock);
spin_lock_irq(&sdev->ud.lock);
if (sdev->ud.status != SDEV_ST_USED)
goto err;
spin_unlock_irq(&sdev->ud.lock);
usbip_event_add(&sdev->ud, SDEV_EVENT_DOWN);
mutex_unlock(&sdev->ud.sysfs_lock);
}
return count;
sock_err:
sockfd_put(socket);
err:
spin_unlock_irq(&sdev->ud.lock);
unlock_mutex:
mutex_unlock(&sdev->ud.sysfs_lock);
return -EINVAL;
}
static DEVICE_ATTR_WO(usbip_sockfd);
static struct attribute *usbip_attrs[] = {
&dev_attr_usbip_status.attr,
&dev_attr_usbip_sockfd.attr,
&dev_attr_usbip_debug.attr,
NULL,
};
ATTRIBUTE_GROUPS(usbip);
static void stub_shutdown_connection(struct usbip_device *ud)
{
struct stub_device *sdev = container_of(ud, struct stub_device, ud);
/*
* When removing an exported device, kernel panic sometimes occurred
Annotation
- Immediate include surface: `linux/device.h`, `linux/file.h`, `linux/kthread.h`, `linux/module.h`, `usbip_common.h`, `stub.h`.
- Detected declarations: `function Copyright`, `function usbip_sockfd_store`, `function stub_shutdown_connection`, `function list_for_each_entry_safe`, `function list_for_each_entry_safe`, `function stub_device_reset`, `function stub_device_unusable`, `function stub_device_free`, `function stub_probe`, `function shutdown_busid`.
- 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.