Skip to content

Commit 95677a9

Browse files
spandruvadarafaeljw
authored andcommitted
PowerCap: Fix mode for energy counter
As per the documentation of powercap sysfs, energy_uj field is read only, if it can't be reset. Currently it always allows write but will fail, if there is no reset callback. Changing mode field, to read only if there is no reset callback. Signed-off-by: Srinivas Pandruvada <[email protected]> Reported-by: Dirk Brandewie <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 08ff4cb commit 95677a9

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

drivers/powercap/powercap_sys.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,14 @@ static void create_power_zone_common_attributes(
377377
if (power_zone->ops->get_max_energy_range_uj)
378378
power_zone->zone_dev_attrs[count++] =
379379
&dev_attr_max_energy_range_uj.attr;
380-
if (power_zone->ops->get_energy_uj)
380+
if (power_zone->ops->get_energy_uj) {
381+
if (power_zone->ops->reset_energy_uj)
382+
dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
383+
else
384+
dev_attr_energy_uj.attr.mode = S_IRUGO;
381385
power_zone->zone_dev_attrs[count++] =
382386
&dev_attr_energy_uj.attr;
387+
}
383388
if (power_zone->ops->get_power_uw)
384389
power_zone->zone_dev_attrs[count++] =
385390
&dev_attr_power_uw.attr;

0 commit comments

Comments
 (0)