drivers/usb/core/ledtrig-usbport.c
Source file repositories/reference/linux-study-clean/drivers/usb/core/ledtrig-usbport.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/core/ledtrig-usbport.c- Extension
.c- Size
- 8814 bytes
- Lines
- 359
- 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.
- 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/device.hlinux/leds.hlinux/module.hlinux/of.hlinux/slab.hlinux/sysfs.hlinux/usb.hlinux/usb/of.h
Detected Declarations
struct usbport_trig_datastruct usbport_trig_portfunction usbport_trig_usb_dev_observedfunction list_for_each_entryfunction usbport_trig_usb_dev_checkfunction usbport_trig_update_countfunction usbport_trig_port_showfunction usbport_trig_port_storefunction usbport_trig_port_observedfunction usbport_trig_add_portfunction usbport_trig_add_usb_dev_portsfunction usbport_trig_remove_portfunction usbport_trig_remove_usb_dev_portsfunction list_for_each_entry_safefunction usbport_trig_notifyfunction usbport_trig_activatefunction usbport_trig_deactivatefunction list_for_each_entry_safe
Annotated Snippet
struct usbport_trig_data {
struct led_classdev *led_cdev;
struct list_head ports;
struct notifier_block nb;
int count; /* Amount of connected matching devices */
};
struct usbport_trig_port {
struct usbport_trig_data *data;
struct usb_device *hub;
int portnum;
char *port_name;
bool observed;
struct device_attribute attr;
struct list_head list;
};
/***************************************
* Helpers
***************************************/
/*
* usbport_trig_usb_dev_observed - Check if dev is connected to observed port
*/
static bool usbport_trig_usb_dev_observed(struct usbport_trig_data *usbport_data,
struct usb_device *usb_dev)
{
struct usbport_trig_port *port;
if (!usb_dev->parent)
return false;
list_for_each_entry(port, &usbport_data->ports, list) {
if (usb_dev->parent == port->hub &&
usb_dev->portnum == port->portnum)
return port->observed;
}
return false;
}
static int usbport_trig_usb_dev_check(struct usb_device *usb_dev, void *data)
{
struct usbport_trig_data *usbport_data = data;
if (usbport_trig_usb_dev_observed(usbport_data, usb_dev))
usbport_data->count++;
return 0;
}
/*
* usbport_trig_update_count - Recalculate amount of connected matching devices
*/
static void usbport_trig_update_count(struct usbport_trig_data *usbport_data)
{
struct led_classdev *led_cdev = usbport_data->led_cdev;
usbport_data->count = 0;
usb_for_each_dev(usbport_data, usbport_trig_usb_dev_check);
led_set_brightness(led_cdev, usbport_data->count ? LED_FULL : LED_OFF);
}
/***************************************
* Device attr
***************************************/
static ssize_t usbport_trig_port_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct usbport_trig_port *port = container_of(attr,
struct usbport_trig_port,
attr);
return sysfs_emit(buf, "%d\n", port->observed) + 1;
}
static ssize_t usbport_trig_port_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t size)
{
struct usbport_trig_port *port = container_of(attr,
struct usbport_trig_port,
attr);
if (!strcmp(buf, "0") || !strcmp(buf, "0\n"))
port->observed = 0;
else if (!strcmp(buf, "1") || !strcmp(buf, "1\n"))
port->observed = 1;
else
Annotation
- Immediate include surface: `linux/device.h`, `linux/leds.h`, `linux/module.h`, `linux/of.h`, `linux/slab.h`, `linux/sysfs.h`, `linux/usb.h`, `linux/usb/of.h`.
- Detected declarations: `struct usbport_trig_data`, `struct usbport_trig_port`, `function usbport_trig_usb_dev_observed`, `function list_for_each_entry`, `function usbport_trig_usb_dev_check`, `function usbport_trig_update_count`, `function usbport_trig_port_show`, `function usbport_trig_port_store`, `function usbport_trig_port_observed`, `function usbport_trig_add_port`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: source implementation candidate.
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.