Skip to contentSkip to conversation

some bugfix for acpi power meter

PATCH Superseded Huisong Li 2 participants 8 messages Jan 7, 2025 – Jan 9, 2025 Hardware monitoring

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Huisong Li

author
#0 lore raw

v2 cover some bugfix for acpi power meter

I found some bugfix when I use this driver. And remove a redundant variable by the way.

Huisong Li (3):
hwmon: (acpi_power_meter) Fix uninitialized variables
hwmon: (acpi_power_meter) Fix update the power trip points on failure
hwmon: (acpi_power_meter) Remove redundant 'sensors_valid' variable

 drivers/hwmon/acpi_power_meter.c | 55 ++++++++++++++++++++++----------
 1 file changed, 38 insertions(+), 17 deletions(-)
Signature · 1 line
2.22.0
author
#1 lore raw

PATCH v2 1/3 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
index 2f1c9d97ad21..0b337d4fb212 100644
@@ -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 ? true : false;
 		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(&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
maintainer
#2 lore raw

Re: [PATCH v2 1/3] hwmon: (acpi_power_meter) Fix uninitialized variables

Quoted 46 lines · Huisong Li

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 +5 -4
index 2f1c9d97ad21..0b337d4fb212 100644
@@ -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);

drivers/hwmon/acpi_power_meter.c static ssize_t show_val(struct device *dev, · line 440

Quoted 10 lines
drivers/hwmon/acpi_power_meter.c +10 -0
+		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 ? true : false;

The result of the comparison is already a boolean. ? : is unnecessary.

drivers/hwmon/acpi_power_meter.c static void acpi_power_meter_notify(struct acpi_device *device, u32 event) · line 864

Quoted 11 lines
drivers/hwmon/acpi_power_meter.c +4 -0
  		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(&device->dev, "update cap failed when capping value is changed.\n");

Please make this dev_err_once() to avoid logging noise if the problem is persistent.

Quoted 13 lines
drivers/hwmon/acpi_power_meter.c +4 -0
+		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;
#3 lore raw

Re: [PATCH v2 1/3] hwmon: (acpi_power_meter) Fix uninitialized variables

Quoted 51 lines · Guenter Roeck
Quoted 50 lines · Huisong Li

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 +4 -0
index 2f1c9d97ad21..0b337d4fb212 100644
@@ -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:

drivers/hwmon/acpi_power_meter.c +0 -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);

Quoted 8 lines
Quoted 6 lines

+            if (ret)
+                return ret;
+        }
+        val = resource->power_alarm || resource->power > resource->cap; +        resource->power_alarm = resource->power > resource->cap ? true : false;

The result of the comparison is already a boolean. ? : is unnecessary.

Right, will fix in v3.

Quoted 17 lines
Quoted 8 lines

          break;
      case 7:
      case 8:

drivers/hwmon/acpi_power_meter.c +0 -0
@@ -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;
Quoted 6 lines

      case METER_NOTIFY_CAP:
+        mutex_lock(&resource->lock);
+        res = update_cap(resource);
+        if (res)
+            dev_err(&device->dev, "update cap failed when capping value is changed.\n");

Please make this dev_err_once() to avoid logging noise if the problem is persistent.

will fix in v3.

Thanks.

Quoted 16 lines
Quoted 14 lines

+ 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;

.

author
#4 lore raw

PATCH v2 2/3 hwmon: (acpi_power_meter) Fix update the power trip points on failure

In reply to Huisong Li

The 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
index 0b337d4fb212..594f7681d523 100644
@@ -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
author
#5 lore raw

PATCH v2 3/3 hwmon: (acpi_power_meter) Remove redundant 'sensors_valid' variable

In reply to Huisong Li

The 'sensors_valid' in acpi_power_meter_resource structure is always '1' after querying power once. The default value of this variable is zero which just ensure user can query power successfully without any time requirement at first time. We can get power and fill the 'sensors_last_updated' field at probing phase to make sure that a valid value is returned to user at first query within the sampling interval. Then this redundant variable can be safely removed.

---
 drivers/hwmon/acpi_power_meter.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/hwmon/acpi_power_meter.c +9 -9
index 594f7681d523..49bef3350439 100644
@@ -85,7 +85,6 @@ struct acpi_power_meter_resource {
 	u64		cap;
 	u64		avg_interval;
 	bool		power_alarm;
-	int			sensors_valid;
 	unsigned long		sensors_last_updated;
 	struct sensor_device_attribute	sensors[NUM_SENSORS];
 	int			num_sensors;
@@ -316,15 +315,14 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
 }
 
 /* Power meter */
-static int update_meter(struct acpi_power_meter_resource *resource)
+static int update_meter(struct acpi_power_meter_resource *resource, bool check)
 {
 	unsigned long long data;
 	acpi_status status;
 	unsigned long local_jiffies = jiffies;
 
-	if (time_before(local_jiffies, resource->sensors_last_updated +
-			msecs_to_jiffies(resource->caps.sampling_time)) &&
-			resource->sensors_valid)
+	if (check && time_before(local_jiffies, resource->sensors_last_updated +
+			msecs_to_jiffies(resource->caps.sampling_time)))
 		return 0;
 
 	status = acpi_evaluate_integer(resource->acpi_dev->handle, "_PMM",
@@ -336,7 +334,6 @@ static int update_meter(struct acpi_power_meter_resource *resource)
 	}
 
 	resource->power = data;
-	resource->sensors_valid = 1;
 	resource->sensors_last_updated = jiffies;
 	return 0;
 }
@@ -349,7 +346,7 @@ static ssize_t show_power(struct device *dev,
 	struct acpi_power_meter_resource *resource = acpi_dev->driver_data;
 
 	mutex_lock(&resource->lock);
-	update_meter(resource);
+	update_meter(resource, true);
 	mutex_unlock(&resource->lock);
 
 	if (resource->power == UNKNOWN_POWER)
@@ -429,7 +426,7 @@ static ssize_t show_val(struct device *dev,
 			val = 0;
 		break;
 	case 6:
-		ret = update_meter(resource);
+		ret = update_meter(resource, true);
 		if (ret)
 			return ret;
 		/* need to update cap if not to support the notification. */
@@ -699,6 +696,10 @@ static int setup_attrs(struct acpi_power_meter_resource *resource)
 		return res;
 
 	if (resource->caps.flags & POWER_METER_CAN_MEASURE) {
+		res = update_meter(resource, false);
+		if (res)
+			goto error;
+
 		res = register_attrs(resource, meter_attrs);
 		if (res)
 			goto error;
@@ -898,7 +899,6 @@ static int acpi_power_meter_add(struct acpi_device *device)
 	if (!resource)
 		return -ENOMEM;
 
-	resource->sensors_valid = 0;
 	resource->acpi_dev = device;
 	mutex_init(&resource->lock);
 	strcpy(acpi_device_name(device), ACPI_POWER_METER_DEVICE_NAME);
Signature · 1 line
2.22.0
maintainer
#6 lore raw

Re: [PATCH v2 3/3] hwmon: (acpi_power_meter) Remove redundant 'sensors_valid' variable

Quoted 8 lines · Huisong Li

The 'sensors_valid' in acpi_power_meter_resource structure is always '1' after querying power once. The default value of this variable is zero which just ensure user can query power successfully without any time requirement at first time. We can get power and fill the 'sensors_last_updated' field at probing phase to make sure that a valid value is returned to user at first query within the sampling interval. Then this redundant variable can be safely removed.

The "benefit" of this change is the saved variable. The cost associated with it is that update_meter() is now _always_ called from setup_attrs(), during probe and when handling configuration change notifications. It seems to me that this is much more costly than keeping the variable since it is unlikely that the show functions are actually called within the sampling time.

I fail to see why removing a variable would be more beneficial than the overhead of unnecessarily calling update_meter() during probe (which also increases probe time) and while handling configuration change notifications.

This would need a much better rationale to be acceptable.

Guenter

Quoted 81 lines
---
  drivers/hwmon/acpi_power_meter.c | 18 +++++++++---------
  1 file changed, 9 insertions(+), 9 deletions(-)
drivers/hwmon/acpi_power_meter.c +9 -9
index 594f7681d523..49bef3350439 100644
@@ -85,7 +85,6 @@ struct acpi_power_meter_resource {
  	u64		cap;
  	u64		avg_interval;
  	bool		power_alarm;
-	int			sensors_valid;
  	unsigned long		sensors_last_updated;
  	struct sensor_device_attribute	sensors[NUM_SENSORS];
  	int			num_sensors;
@@ -316,15 +315,14 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
  }
 
  /* Power meter */
-static int update_meter(struct acpi_power_meter_resource *resource)
+static int update_meter(struct acpi_power_meter_resource *resource, bool check)
  {
  	unsigned long long data;
  	acpi_status status;
  	unsigned long local_jiffies = jiffies;
 
-	if (time_before(local_jiffies, resource->sensors_last_updated +
-			msecs_to_jiffies(resource->caps.sampling_time)) &&
-			resource->sensors_valid)
+	if (check && time_before(local_jiffies, resource->sensors_last_updated +
+			msecs_to_jiffies(resource->caps.sampling_time)))
  		return 0;
 
  	status = acpi_evaluate_integer(resource->acpi_dev->handle, "_PMM",
@@ -336,7 +334,6 @@ static int update_meter(struct acpi_power_meter_resource *resource)
  	}
 
  	resource->power = data;
-	resource->sensors_valid = 1;
  	resource->sensors_last_updated = jiffies;
  	return 0;
  }
@@ -349,7 +346,7 @@ static ssize_t show_power(struct device *dev,
  	struct acpi_power_meter_resource *resource = acpi_dev->driver_data;
 
  	mutex_lock(&resource->lock);
-	update_meter(resource);
+	update_meter(resource, true);
  	mutex_unlock(&resource->lock);
 
  	if (resource->power == UNKNOWN_POWER)
@@ -429,7 +426,7 @@ static ssize_t show_val(struct device *dev,
  			val = 0;
  		break;
  	case 6:
-		ret = update_meter(resource);
+		ret = update_meter(resource, true);
  		if (ret)
  			return ret;
  		/* need to update cap if not to support the notification. */
@@ -699,6 +696,10 @@ static int setup_attrs(struct acpi_power_meter_resource *resource)
  		return res;
 
  	if (resource->caps.flags & POWER_METER_CAN_MEASURE) {
+		res = update_meter(resource, false);
+		if (res)
+			goto error;
+
  		res = register_attrs(resource, meter_attrs);
  		if (res)
  			goto error;
@@ -898,7 +899,6 @@ static int acpi_power_meter_add(struct acpi_device *device)
  	if (!resource)
  		return -ENOMEM;
 
-	resource->sensors_valid = 0;
  	resource->acpi_dev = device;
  	mutex_init(&resource->lock);
  	strcpy(acpi_device_name(device), ACPI_POWER_METER_DEVICE_NAME);
#7 lore raw

Re: [PATCH v2 3/3] hwmon: (acpi_power_meter) Remove redundant 'sensors_valid' variable

Quoted 16 lines · Guenter Roeck
Quoted 8 lines · Huisong Li

The 'sensors_valid' in acpi_power_meter_resource structure is always '1' after querying power once. The default value of this variable is zero which just ensure user can query power successfully without any time requirement at first time. We can get power and fill the 'sensors_last_updated' field at probing phase to make sure that a valid value is returned to user at first query within the sampling interval. Then this redundant variable can be safely removed.

The "benefit" of this change is the saved variable. The cost associated with it is that update_meter() is now _always_ called from setup_attrs(), during probe and when handling configuration change notifications. It seems to me that this is much more costly than keeping the variable since it is unlikely that the show functions are actually called within the sampling time.

Quoted 3 lines

I fail to see why removing a variable would be more beneficial than the overhead of unnecessarily calling update_meter() during probe (which also increases probe time) and while handling configuration change notifications.

That's what it sounds like.
Ok, let's drop this patch.

Quoted 86 lines

This would need a much better rationale to be acceptable.

Guenter

Quoted 78 lines

---
  drivers/hwmon/acpi_power_meter.c | 18 +++++++++---------

  1 file changed, 9 insertions(+), 9 deletions(-)
drivers/hwmon/acpi_power_meter.c +1 -2
index 594f7681d523..49bef3350439 100644
@@ -85,7 +85,6 @@ struct acpi_power_meter_resource {
       u64        cap;
       u64        avg_interval;
       bool        power_alarm;
-    int            sensors_valid;
       unsigned long        sensors_last_updated;
       struct sensor_device_attribute    sensors[NUM_SENSORS];
       int            num_sensors;
@@ -316,15 +315,14 @@ static ssize_t set_trip(struct device *dev, 
 struct device_attribute *devattr,
   }
     /* Power meter */
-static int update_meter(struct acpi_power_meter_resource *resource)
+static int update_meter(struct acpi_power_meter_resource *resource, 
 bool check)
   {
       unsigned long long data;
       acpi_status status;
       unsigned long local_jiffies = jiffies;

  -    if (time_before(local_jiffies, resource->sensors_last_updated + -            msecs_to_jiffies(resource->caps.sampling_time)) && -            resource->sensors_valid)
+    if (check && time_before(local_jiffies, resource->sensors_last_updated +
+            msecs_to_jiffies(resource->caps.sampling_time))) return 0;
        status = acpi_evaluate_integer(resource->acpi_dev->handle, "_PMM",

drivers/hwmon/acpi_power_meter.c +1 -2
@@ -336,7 +334,6 @@ static int update_meter(struct 
 acpi_power_meter_resource *resource)
       }
         resource->power = data;
-    resource->sensors_valid = 1;
       resource->sensors_last_updated = jiffies;
       return 0;
   }
@@ -349,7 +346,7 @@ static ssize_t show_power(struct device *dev,
       struct acpi_power_meter_resource *resource = acpi_dev->driver_data;
         mutex_lock(&resource->lock);
-    update_meter(resource);
+    update_meter(resource, true);
       mutex_unlock(&resource->lock);
         if (resource->power == UNKNOWN_POWER)
@@ -429,7 +426,7 @@ static ssize_t show_val(struct device *dev,
               val = 0;
           break;

      case 6:
-        ret = update_meter(resource);
+        ret = update_meter(resource, true);
          if (ret)
              return ret;
          /* need to update cap if not to support the notification. */

drivers/hwmon/acpi_power_meter.c +4 -0
@@ -699,6 +696,10 @@ static int setup_attrs(struct 
 acpi_power_meter_resource *resource)
           return res;
         if (resource->caps.flags & POWER_METER_CAN_MEASURE) {
+        res = update_meter(resource, false);
+        if (res)
+            goto error;
+
           res = register_attrs(resource, meter_attrs);
           if (res)
               goto error;
@@ -898,7 +899,6 @@ static int acpi_power_meter_add(struct 
 acpi_device *device)
       if (!resource)
           return -ENOMEM;
   -    resource->sensors_valid = 0;
       resource->acpi_dev = device;
       mutex_init(&resource->lock);
Quoted 1 line

      strcpy(acpi_device_name(device), ACPI_POWER_METER_DEVICE_NAME);

.