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.

Dependency Surface

Detected Declarations

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

Implementation Notes