drivers/usb/usbip/vudc_sysfs.c
Source file repositories/reference/linux-study-clean/drivers/usb/usbip/vudc_sysfs.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/usbip/vudc_sysfs.c- Extension
.c- Size
- 6111 bytes
- Lines
- 269
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/list.hlinux/usb/gadget.hlinux/usb/ch9.hlinux/sysfs.hlinux/kthread.hlinux/byteorder/generic.husbip_common.hvudc.hnet/sock.h
Detected Declarations
function Copyrightfunction dev_desc_readfunction usbip_sockfd_storefunction usbip_status_show
Annotated Snippet
if (udc->connected) {
dev_err(dev, "Device already connected");
ret = -EBUSY;
goto unlock;
}
spin_lock(&udc->ud.lock);
if (udc->ud.status != SDEV_ST_AVAILABLE) {
ret = -EINVAL;
goto unlock_ud;
}
socket = sockfd_lookup(sockfd, &err);
if (!socket) {
dev_err(dev, "failed to lookup sock");
ret = -EINVAL;
goto unlock_ud;
}
if (socket->type != SOCK_STREAM) {
dev_err(dev, "Expecting SOCK_STREAM - found %d",
socket->type);
ret = -EINVAL;
goto sock_err;
}
/* unlock and create threads and get tasks */
spin_unlock(&udc->ud.lock);
spin_unlock_irqrestore(&udc->lock, flags);
tcp_rx = kthread_create(&v_rx_loop, &udc->ud, "vudc_rx");
if (IS_ERR(tcp_rx)) {
sockfd_put(socket);
mutex_unlock(&udc->ud.sysfs_lock);
return -EINVAL;
}
tcp_tx = kthread_create(&v_tx_loop, &udc->ud, "vudc_tx");
if (IS_ERR(tcp_tx)) {
kthread_stop(tcp_rx);
sockfd_put(socket);
mutex_unlock(&udc->ud.sysfs_lock);
return -EINVAL;
}
/* get task structs now */
get_task_struct(tcp_rx);
get_task_struct(tcp_tx);
/* lock and update udc->ud state */
spin_lock_irqsave(&udc->lock, flags);
spin_lock(&udc->ud.lock);
udc->ud.tcp_socket = socket;
udc->ud.tcp_rx = tcp_rx;
udc->ud.tcp_tx = tcp_tx;
udc->ud.status = SDEV_ST_USED;
spin_unlock(&udc->ud.lock);
ktime_get_ts64(&udc->start_time);
v_start_timer(udc);
udc->connected = 1;
spin_unlock_irqrestore(&udc->lock, flags);
wake_up_process(udc->ud.tcp_rx);
wake_up_process(udc->ud.tcp_tx);
mutex_unlock(&udc->ud.sysfs_lock);
return count;
} else {
if (!udc->connected) {
dev_err(dev, "Device not connected");
ret = -EINVAL;
goto unlock;
}
spin_lock(&udc->ud.lock);
if (udc->ud.status != SDEV_ST_USED) {
ret = -EINVAL;
goto unlock_ud;
}
spin_unlock(&udc->ud.lock);
usbip_event_add(&udc->ud, VUDC_EVENT_DOWN);
}
spin_unlock_irqrestore(&udc->lock, flags);
Annotation
- Immediate include surface: `linux/device.h`, `linux/list.h`, `linux/usb/gadget.h`, `linux/usb/ch9.h`, `linux/sysfs.h`, `linux/kthread.h`, `linux/byteorder/generic.h`, `usbip_common.h`.
- Detected declarations: `function Copyright`, `function dev_desc_read`, `function usbip_sockfd_store`, `function usbip_status_show`.
- 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.