drivers/usb/core/offload.c
Source file repositories/reference/linux-study-clean/drivers/usb/core/offload.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/core/offload.c- Extension
.c- Size
- 3726 bytes
- Lines
- 153
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/usb.husb.h
Detected Declarations
function usb_offload_getfunction usb_offload_putfunction usb_offload_checkfunction usb_hub_for_each_childfunction usb_offload_set_pm_lockedexport usb_offload_getexport usb_offload_putexport usb_offload_checkexport usb_offload_set_pm_locked
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* offload.c - USB offload related functions
*
* Copyright (c) 2025, Google LLC.
*
* Author: Guan-Yu Lin
*/
#include <linux/usb.h>
#include "usb.h"
/**
* usb_offload_get - increment the offload_usage of a USB device
* @udev: the USB device to increment its offload_usage
*
* Incrementing the offload_usage of a usb_device indicates that offload is
* enabled on this usb_device; that is, another entity is actively handling USB
* transfers. This information allows the USB driver to adjust its power
* management policy based on offload activity.
*
* Return: 0 on success. A negative error code otherwise.
*/
int usb_offload_get(struct usb_device *udev)
{
int ret = 0;
if (!usb_get_dev(udev))
return -ENODEV;
if (pm_runtime_get_if_active(&udev->dev) != 1) {
ret = -EBUSY;
goto err_rpm;
}
spin_lock(&udev->offload_lock);
if (udev->offload_pm_locked) {
ret = -EAGAIN;
goto err;
}
udev->offload_usage++;
err:
spin_unlock(&udev->offload_lock);
pm_runtime_put_autosuspend(&udev->dev);
err_rpm:
usb_put_dev(udev);
return ret;
}
EXPORT_SYMBOL_GPL(usb_offload_get);
/**
* usb_offload_put - drop the offload_usage of a USB device
* @udev: the USB device to drop its offload_usage
*
* The inverse operation of usb_offload_get, which drops the offload_usage of
* a USB device. This information allows the USB driver to adjust its power
* management policy based on offload activity.
*
* Return: 0 on success. A negative error code otherwise.
*/
int usb_offload_put(struct usb_device *udev)
{
int ret = 0;
if (!usb_get_dev(udev))
return -ENODEV;
if (pm_runtime_get_if_active(&udev->dev) != 1) {
ret = -EBUSY;
goto err_rpm;
}
spin_lock(&udev->offload_lock);
if (udev->offload_pm_locked) {
ret = -EAGAIN;
goto err;
}
/* Drop the count when it wasn't 0, ignore the operation otherwise. */
if (udev->offload_usage)
udev->offload_usage--;
err:
Annotation
- Immediate include surface: `linux/usb.h`, `usb.h`.
- Detected declarations: `function usb_offload_get`, `function usb_offload_put`, `function usb_offload_check`, `function usb_hub_for_each_child`, `function usb_offload_set_pm_locked`, `export usb_offload_get`, `export usb_offload_put`, `export usb_offload_check`, `export usb_offload_set_pm_locked`.
- 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.