drivers/usb/serial/bus.c
Source file repositories/reference/linux-study-clean/drivers/usb/serial/bus.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/serial/bus.c- Extension
.c- Size
- 4131 bytes
- Lines
- 172
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/errno.hlinux/tty.hlinux/slab.hlinux/module.hlinux/usb.hlinux/usb/serial.h
Detected Declarations
function Copyrightfunction usb_serial_device_probefunction usb_serial_device_removefunction new_id_storefunction new_id_showfunction free_dynidsfunction usb_serial_bus_registerfunction usb_serial_bus_deregister
Annotated Snippet
const struct device_driver *drv)
{
const struct usb_serial_port *port = to_usb_serial_port(dev);
const struct usb_serial_driver *driver = to_usb_serial_driver(drv);
/*
* drivers are already assigned to ports in serial_probe so it's
* a simple check here.
*/
if (driver == port->serial->type)
return 1;
return 0;
}
static int usb_serial_device_probe(struct device *dev)
{
struct usb_serial_port *port = to_usb_serial_port(dev);
struct usb_serial_driver *driver;
struct device *tty_dev;
int retval = 0;
int minor;
/* make sure suspend/resume doesn't race against port_probe */
retval = usb_autopm_get_interface(port->serial->interface);
if (retval)
return retval;
driver = port->serial->type;
if (driver->port_probe) {
retval = driver->port_probe(port);
if (retval)
goto err_autopm_put;
}
minor = port->minor;
tty_dev = tty_port_register_device(&port->port, usb_serial_tty_driver,
minor, dev);
if (IS_ERR(tty_dev)) {
retval = PTR_ERR(tty_dev);
goto err_port_remove;
}
usb_autopm_put_interface(port->serial->interface);
dev_info(&port->serial->dev->dev,
"%s converter now attached to ttyUSB%d\n",
driver->description, minor);
return 0;
err_port_remove:
if (driver->port_remove)
driver->port_remove(port);
err_autopm_put:
usb_autopm_put_interface(port->serial->interface);
return retval;
}
static void usb_serial_device_remove(struct device *dev)
{
struct usb_serial_port *port = to_usb_serial_port(dev);
struct usb_serial_driver *driver;
int minor;
int autopm_err;
/*
* Make sure suspend/resume doesn't race against port_remove.
*
* Note that no further runtime PM callbacks will be made if
* autopm_get fails.
*/
autopm_err = usb_autopm_get_interface(port->serial->interface);
minor = port->minor;
tty_unregister_device(usb_serial_tty_driver, minor);
driver = port->serial->type;
if (driver->port_remove)
driver->port_remove(port);
dev_info(dev, "%s converter now disconnected from ttyUSB%d\n",
driver->description, minor);
if (!autopm_err)
usb_autopm_put_interface(port->serial->interface);
}
static ssize_t new_id_store(struct device_driver *driver,
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/errno.h`, `linux/tty.h`, `linux/slab.h`, `linux/module.h`, `linux/usb.h`, `linux/usb/serial.h`.
- Detected declarations: `function Copyright`, `function usb_serial_device_probe`, `function usb_serial_device_remove`, `function new_id_store`, `function new_id_show`, `function free_dynids`, `function usb_serial_bus_register`, `function usb_serial_bus_deregister`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: pattern implementation candidate.
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.