drivers/usb/core/sysfs.c
Source file repositories/reference/linux-study-clean/drivers/usb/core/sysfs.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/core/sysfs.c- Extension
.c- Size
- 34750 bytes
- Lines
- 1368
- Domain
- Driver Families
- Bucket
- drivers/usb
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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/kernel.hlinux/kstrtox.hlinux/string.hlinux/usb.hlinux/usb/hcd.hlinux/usb/quirks.hlinux/of.husb.h
Detected Declarations
function bMaxPower_showfunction configuration_showfunction bConfigurationValue_storefunction devspec_showfunction speed_showfunction rx_lanes_showfunction tx_lanes_showfunction busnum_showfunction devnum_showfunction devpath_showfunction version_showfunction maxchild_showfunction quirks_showfunction avoid_reset_quirk_showfunction avoid_reset_quirk_storefunction urbnum_showfunction ltm_capable_showfunction persist_showfunction persist_storefunction add_persist_attributesfunction remove_persist_attributesfunction connected_duration_showfunction active_duration_showfunction autosuspend_showfunction autosuspend_storefunction warn_levelfunction level_showfunction level_storefunction usb2_hardware_lpm_showfunction usb2_hardware_lpm_storefunction usb2_lpm_l1_timeout_showfunction usb2_lpm_l1_timeout_storefunction usb2_lpm_besl_showfunction usb2_lpm_besl_storefunction usb3_hardware_lpm_u1_showfunction usb3_hardware_lpm_u2_showfunction add_power_attributesfunction remove_power_attributesfunction authorized_showfunction authorized_storefunction remove_storefunction dev_string_attrs_are_visiblefunction descriptors_readfunction bos_descriptors_readfunction dev_bin_attrs_are_visiblefunction authorized_default_showfunction authorized_default_storefunction interface_authorized_default_show
Annotated Snippet
if (cfgno < 0) {
src = &udev->descriptor;
srclen = sizeof(struct usb_device_descriptor);
} else {
src = udev->rawdescriptors[cfgno];
srclen = le16_to_cpu(udev->config[cfgno].desc.
wTotalLength);
}
if (off < srclen) {
n = min(nleft, srclen - (size_t) off);
memcpy(buf, src + off, n);
nleft -= n;
buf += n;
off = 0;
} else {
off -= srclen;
}
}
return count - nleft;
}
static const BIN_ATTR_RO(descriptors, 18 + 65535); /* dev descr + max-size raw descriptor */
static ssize_t
bos_descriptors_read(struct file *filp, struct kobject *kobj,
const struct bin_attribute *attr,
char *buf, loff_t off, size_t count)
{
struct device *dev = kobj_to_dev(kobj);
struct usb_device *udev = to_usb_device(dev);
struct usb_host_bos *bos = udev->bos;
struct usb_bos_descriptor *desc;
size_t desclen, n = 0;
if (bos) {
desc = bos->desc;
desclen = le16_to_cpu(desc->wTotalLength);
if (off < desclen) {
n = min(count, desclen - (size_t) off);
memcpy(buf, (void *) desc + off, n);
}
}
return n;
}
static const BIN_ATTR_RO(bos_descriptors, 65535); /* max-size BOS */
/* When modifying this list, be sure to modify dev_bin_attrs_are_visible()
* accordingly.
*/
static const struct bin_attribute *const dev_bin_attrs[] = {
&bin_attr_descriptors,
&bin_attr_bos_descriptors,
NULL
};
static umode_t dev_bin_attrs_are_visible(struct kobject *kobj,
const struct bin_attribute *a, int n)
{
struct device *dev = kobj_to_dev(kobj);
struct usb_device *udev = to_usb_device(dev);
/*
* There's no need to check if the descriptors attribute should
* be visible because all devices have a device descriptor. The
* bos_descriptors attribute should be visible if and only if
* the device has a BOS, so check if it exists here.
*/
if (a == &bin_attr_bos_descriptors) {
if (udev->bos == NULL)
return 0;
}
return a->attr.mode;
}
static const struct attribute_group dev_bin_attr_grp = {
.bin_attrs = dev_bin_attrs,
.is_bin_visible = dev_bin_attrs_are_visible,
};
const struct attribute_group *usb_device_groups[] = {
&dev_attr_grp,
&dev_string_attr_grp,
&dev_bin_attr_grp,
NULL
};
/*
* Show & store the current value of authorized_default
*/
static ssize_t authorized_default_show(struct device *dev,
struct device_attribute *attr, char *buf)
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/kstrtox.h`, `linux/string.h`, `linux/usb.h`, `linux/usb/hcd.h`, `linux/usb/quirks.h`, `linux/of.h`, `usb.h`.
- Detected declarations: `function bMaxPower_show`, `function configuration_show`, `function bConfigurationValue_store`, `function devspec_show`, `function speed_show`, `function rx_lanes_show`, `function tx_lanes_show`, `function busnum_show`, `function devnum_show`, `function devpath_show`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: source 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.