drivers/usb/core/message.c
Source file repositories/reference/linux-study-clean/drivers/usb/core/message.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/core/message.c- Extension
.c- Size
- 77074 bytes
- Lines
- 2522
- 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/acpi.hlinux/pci.hlinux/usb.hlinux/module.hlinux/of.hlinux/slab.hlinux/mm.hlinux/timer.hlinux/ctype.hlinux/nls.hlinux/device.hlinux/scatterlist.hlinux/usb/cdc.hlinux/usb/quirks.hlinux/usb/hcd.hlinux/usb/of.hasm/byteorder.husb.h
Detected Declarations
struct api_contextstruct set_config_requestfunction usb_api_blocking_completionfunction usb_start_wait_urbfunction usb_internal_control_msgfunction disconnectfunction responsefunction responsefunction disconnectfunction disconnectfunction outfunction sg_cleanfunction sg_completefunction usb_sg_waitfunction for_each_sgfunction usb_sg_cancelfunction usb_sg_waitfunction usb_get_stringfunction usb_stringfunction usb_try_string_workaroundsfunction usb_string_subfunction usb_get_langidfunction usb_get_string_descriptorfunction structurefunction usb_set_isoch_delayfunction haltedfunction usb_control_msgfunction create_intf_ep_devsfunction remove_intf_ep_devsfunction usb_disable_endpointfunction usb_reset_endpointfunction usb_disable_interfacefunction usb_disable_device_endpointsfunction usb_set_configurationfunction themfunction usb_enable_endpointfunction usb_enable_interfacefunction disconnectfunction statefunction usb_release_interfacefunction usb_deauthorize_interfacefunction usb_authorize_interfacefunction usb_if_ueventfunction usb_queue_reset_devicefunction usb_set_wireless_statusfunction usb_set_wireless_statusfunction usb_set_configurationfunction driver_set_config_work
Annotated Snippet
ret = device_add(&intf->dev);
if (ret != 0) {
dev_err(&dev->dev, "device_add(%s) --> %d\n",
dev_name(&intf->dev), ret);
continue;
}
create_intf_ep_devs(intf);
}
usb_autosuspend_device(dev);
return 0;
}
EXPORT_SYMBOL_GPL(usb_set_configuration);
static LIST_HEAD(set_config_list);
static DEFINE_SPINLOCK(set_config_lock);
struct set_config_request {
struct usb_device *udev;
int config;
struct work_struct work;
struct list_head node;
};
/* Worker routine for usb_driver_set_configuration() */
static void driver_set_config_work(struct work_struct *work)
{
struct set_config_request *req =
container_of(work, struct set_config_request, work);
struct usb_device *udev = req->udev;
usb_lock_device(udev);
spin_lock(&set_config_lock);
list_del(&req->node);
spin_unlock(&set_config_lock);
if (req->config >= -1) /* Is req still valid? */
usb_set_configuration(udev, req->config);
usb_unlock_device(udev);
usb_put_dev(udev);
kfree(req);
}
/* Cancel pending Set-Config requests for a device whose configuration
* was just changed
*/
static void cancel_async_set_config(struct usb_device *udev)
{
struct set_config_request *req;
spin_lock(&set_config_lock);
list_for_each_entry(req, &set_config_list, node) {
if (req->udev == udev)
req->config = -999; /* Mark as cancelled */
}
spin_unlock(&set_config_lock);
}
/**
* usb_driver_set_configuration - Provide a way for drivers to change device configurations
* @udev: the device whose configuration is being updated
* @config: the configuration being chosen.
* Context: In process context, must be able to sleep
*
* Device interface drivers are not allowed to change device configurations.
* This is because changing configurations will destroy the interface the
* driver is bound to and create new ones; it would be like a floppy-disk
* driver telling the computer to replace the floppy-disk drive with a
* tape drive!
*
* Still, in certain specialized circumstances the need may arise. This
* routine gets around the normal restrictions by using a work thread to
* submit the change-config request.
*
* Return: 0 if the request was successfully queued, error code otherwise.
* The caller has no way to know whether the queued request will eventually
* succeed.
*/
int usb_driver_set_configuration(struct usb_device *udev, int config)
{
struct set_config_request *req;
req = kmalloc_obj(*req);
if (!req)
return -ENOMEM;
req->udev = udev;
req->config = config;
INIT_WORK(&req->work, driver_set_config_work);
spin_lock(&set_config_lock);
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/pci.h`, `linux/usb.h`, `linux/module.h`, `linux/of.h`, `linux/slab.h`, `linux/mm.h`, `linux/timer.h`.
- Detected declarations: `struct api_context`, `struct set_config_request`, `function usb_api_blocking_completion`, `function usb_start_wait_urb`, `function usb_internal_control_msg`, `function disconnect`, `function response`, `function response`, `function disconnect`, `function disconnect`.
- 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.