]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ACPI / battery: Do not export energy_full[_design] on devices without full_charge_cap...
authorHans de Goede <hdegoede@redhat.com>
Tue, 7 Aug 2018 07:36:30 +0000 (09:36 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Thu, 9 Aug 2018 08:49:35 +0000 (10:49 +0200)
On some devices (with a buggy _BIX implementation) full_charge_capacity
always reports as 0. This means that our energy_full sysfs attribute will
also always be 0, which is not useful to export.

Worse we calculate our reported capacity on full_charge_capacity and if it
is 0 we always report 0. This causes userspace to immediately shutdown or
hibernate the laptop since it assumes that the battery is critically low.

This commit makes us not report energy_full[_design] or capacity on such
broken devices, avoiding the immediate shutdown / hibernate from userspace.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=83941
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/acpi/battery.c

index cb664e87cde82e0fc6db1c1ab0ae76df1eb5c3b7..cb97b6105f5286fa6c11c8bf787a3e1b49baf52c 100644 (file)
@@ -364,6 +364,20 @@ static enum power_supply_property energy_battery_props[] = {
        POWER_SUPPLY_PROP_SERIAL_NUMBER,
 };
 
+static enum power_supply_property energy_battery_full_cap_broken_props[] = {
+       POWER_SUPPLY_PROP_STATUS,
+       POWER_SUPPLY_PROP_PRESENT,
+       POWER_SUPPLY_PROP_TECHNOLOGY,
+       POWER_SUPPLY_PROP_CYCLE_COUNT,
+       POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
+       POWER_SUPPLY_PROP_VOLTAGE_NOW,
+       POWER_SUPPLY_PROP_POWER_NOW,
+       POWER_SUPPLY_PROP_ENERGY_NOW,
+       POWER_SUPPLY_PROP_MODEL_NAME,
+       POWER_SUPPLY_PROP_MANUFACTURER,
+       POWER_SUPPLY_PROP_SERIAL_NUMBER,
+};
+
 /* --------------------------------------------------------------------------
                                Battery Management
    -------------------------------------------------------------------------- */
@@ -798,6 +812,11 @@ static int sysfs_add_battery(struct acpi_battery *battery)
                battery->bat_desc.properties = charge_battery_props;
                battery->bat_desc.num_properties =
                        ARRAY_SIZE(charge_battery_props);
+       } else if (battery->full_charge_capacity == 0) {
+               battery->bat_desc.properties =
+                       energy_battery_full_cap_broken_props;
+               battery->bat_desc.num_properties =
+                       ARRAY_SIZE(energy_battery_full_cap_broken_props);
        } else {
                battery->bat_desc.properties = energy_battery_props;
                battery->bat_desc.num_properties =