drivers/thermal/thermal_hwmon.c
Source file repositories/reference/linux-study-clean/drivers/thermal/thermal_hwmon.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/thermal/thermal_hwmon.c- Extension
.c- Size
- 4959 bytes
- Lines
- 202
- Domain
- Driver Families
- Bucket
- drivers/thermal
- 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/err.hlinux/export.hlinux/hwmon.hlinux/slab.hlinux/thermal.hthermal_hwmon.hthermal_core.h
Detected Declarations
struct thermal_hwmon_devicefunction temp1_input_showfunction temp1_crit_showfunction thermal_hwmon_attr_is_visiblefunction thermal_add_hwmon_sysfsfunction thermal_hwmon_lookupfunction list_for_each_entryfunction thermal_remove_hwmon_sysfsfunction scoped_guardfunction devm_thermal_hwmon_releasefunction devm_thermal_add_hwmon_sysfsexport thermal_add_hwmon_sysfsexport thermal_remove_hwmon_sysfsexport devm_thermal_add_hwmon_sysfs
Annotated Snippet
struct thermal_hwmon_device {
char name[THERMAL_HWMON_NAME_LENGTH];
struct device *device;
struct list_head node;
struct thermal_zone_device *tz;
};
static LIST_HEAD(thermal_hwmon_list);
static DEFINE_MUTEX(thermal_hwmon_list_lock);
static ssize_t
temp1_input_show(struct device *dev, struct device_attribute *attr, char *buf)
{
struct thermal_hwmon_device *hwmon = dev_get_drvdata(dev);
struct thermal_zone_device *tz = hwmon->tz;
int temperature;
int ret;
ret = thermal_zone_get_temp(tz, &temperature);
if (ret)
return ret;
return sysfs_emit(buf, "%d\n", temperature);
}
static ssize_t
temp1_crit_show(struct device *dev, struct device_attribute *attr, char *buf)
{
struct thermal_hwmon_device *hwmon = dev_get_drvdata(dev);
struct thermal_zone_device *tz = hwmon->tz;
int temperature;
int ret;
guard(thermal_zone)(tz);
ret = tz->ops.get_crit_temp(tz, &temperature);
if (ret)
return ret;
return sysfs_emit(buf, "%d\n", temperature);
}
static DEVICE_ATTR_RO(temp1_input);
static DEVICE_ATTR_RO(temp1_crit);
static struct attribute *thermal_hwmon_attrs[] = {
&dev_attr_temp1_input.attr,
&dev_attr_temp1_crit.attr,
NULL,
};
static umode_t thermal_hwmon_attr_is_visible(struct kobject *kobj,
struct attribute *a, int n)
{
if (a == &dev_attr_temp1_input.attr)
return a->mode;
if (a == &dev_attr_temp1_crit.attr) {
struct thermal_hwmon_device *hwmon = dev_get_drvdata(kobj_to_dev(kobj));
struct thermal_zone_device *tz = hwmon->tz;
int dummy;
if (tz->ops.get_crit_temp && !tz->ops.get_crit_temp(tz, &dummy))
return a->mode;
}
return 0;
}
static const struct attribute_group thermal_hwmon_group = {
.attrs = thermal_hwmon_attrs,
.is_visible = thermal_hwmon_attr_is_visible,
};
__ATTRIBUTE_GROUPS(thermal_hwmon);
int thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
{
struct thermal_hwmon_device *hwmon;
hwmon = kzalloc_obj(*hwmon);
if (!hwmon)
return -ENOMEM;
hwmon->tz = tz;
/*
* Append the thermal zone ID preceded by an underline character to the
* type to disambiguate the sensors command output.
*/
Annotation
- Immediate include surface: `linux/err.h`, `linux/export.h`, `linux/hwmon.h`, `linux/slab.h`, `linux/thermal.h`, `thermal_hwmon.h`, `thermal_core.h`.
- Detected declarations: `struct thermal_hwmon_device`, `function temp1_input_show`, `function temp1_crit_show`, `function thermal_hwmon_attr_is_visible`, `function thermal_add_hwmon_sysfs`, `function thermal_hwmon_lookup`, `function list_for_each_entry`, `function thermal_remove_hwmon_sysfs`, `function scoped_guard`, `function devm_thermal_hwmon_release`.
- Atlas domain: Driver Families / drivers/thermal.
- 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.