two bugfixes for acpi power meter
v3 cover two bugfixes for acpi power meter
Two bugfixes for acpi power meter.
---
- v3: drop the last patch and use dev_err_once to print as Guenter suggested.
- v2: get power alarm state and 'cap' value from notification.
Huisong Li (2):
hwmon: (acpi_power_meter) Fix uninitialized variables
hwmon: (acpi_power_meter) Fix update the power trip points on failure
drivers/hwmon/acpi_power_meter.c | 39 ++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 9 deletions(-)
Signature · 1 line
2.22.0
PATCH v3 1/2 hwmon: (acpi_power_meter) Fix uninitialized variables
The 'power1_alarm' attribute uses the 'power' and 'cap' in the acpi_power_meter_resource structure. Currently, these two fields are just updated when user query 'power' and 'cap' attribute. If user directly query the 'power1_alarm' attribute without queryng above two attributes, driver will use uninitialized variables to judge.
So this patch adds the setting of alarm state and update 'cap' in the notification callback and update 'power' and 'cap' if needed to show the real alarm state.
--- drivers/hwmon/acpi_power_meter.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)
drivers/hwmon/acpi_power_meter.c +23 -4
@@ -84,6 +84,7 @@ struct acpi_power_meter_resource {u64 power;u64 cap;u64 avg_interval; +bool power_alarm;int sensors_valid;unsigned long sensors_last_updated;struct sensor_device_attribute sensors[NUM_SENSORS ];
@@ -396,6 +397,9 @@ static ssize_t show_val(struct device *dev,struct acpi_device *acpi_dev =to_acpi_device (dev);struct acpi_power_meter_resource *resource = acpi_dev->driver_data;u64 val =0 ; +int ret; + +guard (mutex)(&resource->lock);switch (attr->index) {case 0 :
@@ -423,10 +427,17 @@ static ssize_t show_val(struct device *dev, val =0 ;break ;case 6 : -if (resource->power > resource->cap) - val =1 ; -else - val =0 ; + ret =update_meter (resource); +if (ret) +return ret; +/* need to update cap if not to support the notification. */ +if (!(resource->caps.flags &POWER_METER_CAN_NOTIFY )) { + ret =update_cap (resource); +if (ret) +return ret; + } + val = resource->power_alarm || resource->power > resource->cap; + resource->power_alarm = resource->power > resource->cap;break ;case 7 :case 8 :
@@ -847,12 +858,20 @@ static void acpi_power_meter_notify(struct acpi_device *device, u32 event)sysfs_notify (&device->dev.kobj,NULL ,POWER_AVERAGE_NAME );break ;case METER_NOTIFY_CAP : +mutex_lock (&resource->lock); + res =update_cap (resource); +if (res) +dev_err_once (&device->dev,"update cap failed when capping value is changed.\n" ); +mutex_unlock (&resource->lock);sysfs_notify (&device->dev.kobj,NULL ,POWER_CAP_NAME );break ;case METER_NOTIFY_INTERVAL :sysfs_notify (&device->dev.kobj,NULL ,POWER_AVG_INTERVAL_NAME );break ;case METER_NOTIFY_CAPPING : +mutex_lock (&resource->lock); + resource->power_alarm = true; +mutex_unlock (&resource->lock);sysfs_notify (&device->dev.kobj,NULL ,POWER_ALARM_NAME );dev_info (&device->dev,"Capping in progress.\n" );break ;
Signature · 1 line
2.22.0
Re: [PATCH v3 1/2] hwmon: (acpi_power_meter) Fix uninitialized variables
Quoted 11 lines · Huisong Li
The '
power1_alarm' attribute uses the 'power' and 'cap' in theacpi_power_meter_resourcestructure. Currently, these two fields are just updated when user query 'power' and 'cap' attribute. If user directly query the 'power1_alarm' attribute without queryng above two attributes, driver will use uninitialized variables to judge.So this patch adds the setting of alarm state and update 'cap' in the notification callback and update 'power' and 'cap' if needed to show the real alarm state.
Signed-off-by Huisong Li <[email protected]>
Applied.
Thanks,
Guenter
PATCH v3 2/2 hwmon: (acpi_power_meter) Fix update the power trip points on failure
In reply to Huisong LiThe power trip points maintained in local should not be updated when '_PTP' method fails to evaluate.
--- drivers/hwmon/acpi_power_meter.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/hwmon/acpi_power_meter.c +7 -5
@@ -293,8 +293,8 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,struct sensor_device_attribute *attr =to_sensor_dev_attr (devattr);struct acpi_device *acpi_dev =to_acpi_device (dev);struct acpi_power_meter_resource *resource = acpi_dev->driver_data; +unsigned long temp, trip_bk;int res; -unsigned long temp; res =kstrtoul (buf,10 , &temp);if (res)
@@ -302,13 +302,15 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr, temp =DIV_ROUND_CLOSEST (temp,1000 ); -mutex_lock (&resource->lock); +guard (mutex)(&resource->lock); + + trip_bk = resource->trip[attr->index -7 ]; resource->trip[attr->index -7 ] = temp; res =set_acpi_trip (resource); -mutex_unlock (&resource->lock); - -if (res) +if (res) { + resource->trip[attr->index -7 ] = trip_bk;return res; + }return count; }
Signature · 1 line
2.22.0
Re: [PATCH v3 2/2] hwmon: (acpi_power_meter) Fix update the power trip points on failure
Quoted 4 lines · Huisong Li
The power trip points maintained in local should not be updated when '
_PTP' method fails to evaluate.Signed-off-by Huisong Li <[email protected]>
Applied.
Thanks,
Guenter