drivers/usb/core/hub.c
Source file repositories/reference/linux-study-clean/drivers/usb/core/hub.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/core/hub.c- Extension
.c- Size
- 191730 bytes
- Lines
- 6568
- 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/kernel.hlinux/errno.hlinux/module.hlinux/moduleparam.hlinux/completion.hlinux/sched/mm.hlinux/list.hlinux/slab.hlinux/string_choices.hlinux/kcov.hlinux/ioctl.hlinux/usb.hlinux/usbdevice_fs.hlinux/usb/hcd.hlinux/usb/onboard_dev.hlinux/usb/otg.hlinux/usb/quirks.hlinux/workqueue.hlinux/minmax.hlinux/mutex.hlinux/random.hlinux/pm_qos.hlinux/kobject.hlinux/bitfield.hlinux/uaccess.hasm/byteorder.hhub.hphy.hotg_productlist.htrace.h
Detected Declarations
enum hub_activation_typeenum hub_quiescing_typefunction usb_device_supports_lpmfunction Latencyfunction Latencyfunction Latencyfunction usb_set_lpm_parametersfunction get_hub_descriptorfunction clear_hub_featurefunction usb_clear_port_featurefunction set_port_featurefunction set_port_ledfunction led_workfunction get_hub_statusfunction get_port_statusfunction hub_ext_port_statusfunction usb_hub_port_statusfunction hub_resubmit_irq_urbfunction hub_retry_irq_urbfunction kick_hub_wqfunction usb_kick_hub_wqfunction usb_wakeup_notificationfunction hub_irqfunction hub_clear_tt_bufferfunction transfersfunction usb_hub_set_port_powerfunction fullfunction hub_power_onfunction hub_hub_statusfunction hub_set_port_link_statefunction disconnectfunction usb_remove_devicefunction hub_activatefunction hubfunction HUB_RESUMEfunction hub_init_func2function hub_init_func3function hub_post_resumefunction hub_quiescefunction hub_pm_barrier_for_all_portsfunction hub_pre_resetfunction hub_post_resetfunction hub_configurefunction SetIsochDelayfunction hub_releasefunction hub_getfunction hub_putfunction hub_disconnect
Annotated Snippet
err = device_add(&udev->dev);
if (err) {
dev_err(&udev->dev, "can't device_add, error %d\n", err);
goto fail;
}
/* Create link files between child device and usb port device. */
if (udev->parent) {
struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent);
int port1 = udev->portnum;
struct usb_port *port_dev = hub->ports[port1 - 1];
err = sysfs_create_link(&udev->dev.kobj,
&port_dev->dev.kobj, "port");
if (err)
goto out_del_dev;
err = sysfs_create_link(&port_dev->dev.kobj,
&udev->dev.kobj, "device");
if (err) {
sysfs_remove_link(&udev->dev.kobj, "port");
goto out_del_dev;
}
if (!test_and_set_bit(port1, hub->child_usage_bits))
pm_runtime_get_sync(&port_dev->dev);
typec_attach(port_dev->connector, &udev->dev);
}
(void) usb_create_ep_devs(&udev->dev, &udev->ep0, udev);
usb_mark_last_busy(udev);
pm_runtime_put_sync_autosuspend(&udev->dev);
return err;
out_del_dev:
device_del(&udev->dev);
fail:
usb_set_device_state(udev, USB_STATE_NOTATTACHED);
pm_runtime_disable(&udev->dev);
pm_runtime_set_suspended(&udev->dev);
return err;
}
/**
* usb_deauthorize_device - deauthorize a device (usbcore-internal)
* @usb_dev: USB device
*
* Move the USB device to a very basic state where interfaces are disabled
* and the device is in fact unconfigured and unusable.
*
* We share a lock (that we have) with device_del(), so we need to
* defer its call.
*
* Return: 0.
*/
int usb_deauthorize_device(struct usb_device *usb_dev)
{
usb_lock_device(usb_dev);
if (usb_dev->authorized == 0)
goto out_unauthorized;
usb_dev->authorized = 0;
usb_set_configuration(usb_dev, -1);
out_unauthorized:
usb_unlock_device(usb_dev);
return 0;
}
int usb_authorize_device(struct usb_device *usb_dev)
{
int result = 0, c;
usb_lock_device(usb_dev);
if (usb_dev->authorized == 1)
goto out_authorized;
result = usb_autoresume_device(usb_dev);
if (result < 0) {
dev_err(&usb_dev->dev,
"can't autoresume for authorization: %d\n", result);
goto error_autoresume;
}
usb_dev->authorized = 1;
/* Choose and set the configuration. This registers the interfaces
* with the driver core and lets interface drivers bind to them.
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/errno.h`, `linux/module.h`, `linux/moduleparam.h`, `linux/completion.h`, `linux/sched/mm.h`, `linux/list.h`, `linux/slab.h`.
- Detected declarations: `enum hub_activation_type`, `enum hub_quiescing_type`, `function usb_device_supports_lpm`, `function Latency`, `function Latency`, `function Latency`, `function usb_set_lpm_parameters`, `function get_hub_descriptor`, `function clear_hub_feature`, `function usb_clear_port_feature`.
- 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.