From b41901a2cf06f33c030be96c075872201089d47a Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Tue, 7 Aug 2018 09:36:30 +0200 Subject: ACPI / battery: Do not export energy_full[_design] on devices without full_charge_capacity 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 Signed-off-by: Rafael J. Wysocki --- drivers/acpi/battery.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'drivers/acpi/battery.c') diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index cb664e87cde8..cb97b6105f52 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -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 = -- cgit v1.2.3