drivers/usb/usbip/stub_main.c
Source file repositories/reference/linux-study-clean/drivers/usb/usbip/stub_main.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/usbip/stub_main.c- Extension
.c- Size
- 9018 bytes
- Lines
- 429
- Domain
- Driver Families
- Bucket
- drivers/usb
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/string.hlinux/module.hlinux/device.hlinux/scatterlist.husbip_common.hstub.h
Detected Declarations
function init_busid_tablefunction get_busid_idxfunction put_busid_privfunction add_match_busidfunction del_match_busidfunction match_busid_showfunction match_busid_storefunction do_rebindfunction stub_device_rebindfunction rebind_storefunction list_for_each_entry_safefunction stub_free_priv_and_urbfunction stub_device_cleanup_urbsfunction usbip_host_initfunction usbip_host_exitmodule init usbip_host_init
Annotated Snippet
static ssize_t match_busid_show(struct device_driver *drv, char *buf)
{
int i;
char *out = buf;
spin_lock(&busid_table_lock);
for (i = 0; i < MAX_BUSID; i++) {
spin_lock(&busid_table[i].busid_lock);
if (busid_table[i].name[0])
out += sprintf(out, "%s ", busid_table[i].name);
spin_unlock(&busid_table[i].busid_lock);
}
spin_unlock(&busid_table_lock);
out += sprintf(out, "\n");
return out - buf;
}
static ssize_t match_busid_store(struct device_driver *dev, const char *buf,
size_t count)
{
char busid[BUSID_SIZE];
if (count < 5)
return -EINVAL;
/* busid needs to include \0 termination */
if (strscpy(busid, buf + 4, BUSID_SIZE) < 0)
return -EINVAL;
if (!strncmp(buf, "add ", 4)) {
if (add_match_busid(busid) < 0)
return -ENOMEM;
pr_debug("add busid %s\n", busid);
return count;
}
if (!strncmp(buf, "del ", 4)) {
if (del_match_busid(busid) < 0)
return -ENODEV;
pr_debug("del busid %s\n", busid);
return count;
}
return -EINVAL;
}
static DRIVER_ATTR_RW(match_busid);
static int do_rebind(char *busid, struct bus_id_priv *busid_priv)
{
int ret = 0;
/* device_attach() callers should hold parent lock for USB */
if (busid_priv->udev->dev.parent)
device_lock(busid_priv->udev->dev.parent);
ret = device_attach(&busid_priv->udev->dev);
if (busid_priv->udev->dev.parent)
device_unlock(busid_priv->udev->dev.parent);
if (ret < 0)
dev_err(&busid_priv->udev->dev, "rebind failed\n");
return ret;
}
static void stub_device_rebind(void)
{
#if IS_MODULE(CONFIG_USBIP_HOST)
struct bus_id_priv *busid_priv;
int i;
/* update status to STUB_BUSID_OTHER so probe ignores the device */
spin_lock(&busid_table_lock);
for (i = 0; i < MAX_BUSID; i++) {
if (busid_table[i].name[0] &&
busid_table[i].shutdown_busid) {
busid_priv = &(busid_table[i]);
busid_priv->status = STUB_BUSID_OTHER;
}
}
spin_unlock(&busid_table_lock);
/* now run rebind - no need to hold locks. driver files are removed */
for (i = 0; i < MAX_BUSID; i++) {
if (busid_table[i].name[0] &&
busid_table[i].shutdown_busid) {
busid_priv = &(busid_table[i]);
do_rebind(busid_table[i].name, busid_priv);
}
}
Annotation
- Immediate include surface: `linux/string.h`, `linux/module.h`, `linux/device.h`, `linux/scatterlist.h`, `usbip_common.h`, `stub.h`.
- Detected declarations: `function init_busid_table`, `function get_busid_idx`, `function put_busid_priv`, `function add_match_busid`, `function del_match_busid`, `function match_busid_show`, `function match_busid_store`, `function do_rebind`, `function stub_device_rebind`, `function rebind_store`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: pattern 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.