--- zzzz-none-000/linux-5.4.213/drivers/thermal/thermal_sysfs.c 2022-09-15 10:04:56.000000000 +0000 +++ miami-7690-761/linux-5.4.213/drivers/thermal/thermal_sysfs.c 2024-05-29 11:20:02.000000000 +0000 @@ -106,19 +106,57 @@ switch (type) { case THERMAL_TRIP_CRITICAL: - return sprintf(buf, "critical\n"); + return scnprintf(buf, PAGE_SIZE, "critical\n"); case THERMAL_TRIP_HOT: - return sprintf(buf, "hot\n"); + return scnprintf(buf, PAGE_SIZE, "hot\n"); case THERMAL_TRIP_PASSIVE: - return sprintf(buf, "passive\n"); + return scnprintf(buf, PAGE_SIZE, "passive\n"); case THERMAL_TRIP_ACTIVE: - return sprintf(buf, "active\n"); + return scnprintf(buf, PAGE_SIZE, "active\n"); + case THERMAL_TRIP_CONFIGURABLE_HI: + return scnprintf(buf, PAGE_SIZE, "configurable_hi\n"); + case THERMAL_TRIP_CONFIGURABLE_LOW: + return scnprintf(buf, PAGE_SIZE, "configurable_low\n"); + case THERMAL_TRIP_CRITICAL_LOW: + return scnprintf(buf, PAGE_SIZE, "critical_low\n"); + case THERMAL_TRIP_AVM_HOT: + return scnprintf(buf, PAGE_SIZE, "avm_hot\n"); default: - return sprintf(buf, "unknown\n"); + return scnprintf(buf, PAGE_SIZE, "unknown\n"); } } static ssize_t +trip_point_type_activate(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct thermal_zone_device *tz = to_thermal_zone(dev); + int trip, ret; + char *enabled = "enabled"; + char *disabled = "disabled"; + + if (!tz->ops->set_trip_activate) + return -EPERM; + + if (!sscanf(attr->attr.name, "trip_point_%d_type", &trip)) + return -EINVAL; + + if (!strncmp(buf, enabled, strlen(enabled))) + ret = tz->ops->set_trip_activate(tz, trip, + THERMAL_TRIP_ACTIVATION_ENABLED); + else if (!strncmp(buf, disabled, strlen(disabled))) + ret = tz->ops->set_trip_activate(tz, trip, + THERMAL_TRIP_ACTIVATION_DISABLED); + else + ret = -EINVAL; + + if (ret) + return ret; + + return count; +} + +static ssize_t trip_point_temp_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { @@ -557,6 +595,12 @@ tz->trip_type_attrs[indx].name; tz->trip_type_attrs[indx].attr.attr.mode = S_IRUGO; tz->trip_type_attrs[indx].attr.show = trip_point_type_show; + + if (IS_ENABLED(CONFIG_THERMAL_WRITABLE_TRIPS)) { + tz->trip_type_attrs[indx].attr.store + = trip_point_type_activate; + tz->trip_type_attrs[indx].attr.attr.mode |= S_IWUSR; + } attrs[indx] = &tz->trip_type_attrs[indx].attr.attr; /* create trip temp attribute */