Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3709880ybv; Mon, 10 Feb 2020 05:07:15 -0800 (PST) X-Google-Smtp-Source: APXvYqySwp2DmepwRX3mZBc99+nHB/WeVJls+0/xETYc+QlSkTSGr4kMy8uJreN50tLxmwqnpj9m X-Received: by 2002:aca:d15:: with SMTP id 21mr774551oin.120.1581340035057; Mon, 10 Feb 2020 05:07:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581340035; cv=none; d=google.com; s=arc-20160816; b=ZnWVGC+FcFhClxLHEeXvv/gHlaPyKDVhwOaPcuna94uFxFvGORs1oolQ1E+zaz3mK2 EdDtes48qi/lZZHOA/D0yCIIgpVjR/2F7iWa2QNXK5K1hyh5p5pb8rMQohSjJOj02Mms kdUr0E8gZWsHXgMguoMo1v0QVlbW7DGA+2KqGnTCfK42ovfMQAES7hLTIsF19uXDojGr sGw3KsI5B2catinq1cVs8+nC4F7CpZ/JnuF/JZe5/MNHGHDB7MzIjbmYzZzWln952K5J Wfn4en38kwK8wKjK/JSWxfpHB6bpMN27GWFWRjGgqNypP55hAj97L3Um5NdlSFt2wn8M pf+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5/WqxiqVqBN3sQ2QLpTWOd9MKcV3ZJ2lgr3OQrPB2iw=; b=c+0SRSeY04/K1hWLvKzp8z+majA6qSHOxjSjY4a93+JyVasiNGEiTNIeIIJveYujO2 0Yi2fKfyOYpvH427WoY3puF0SPIdKO/4/WHdpUN0KUjB4fXMUjfw/5O4nUxIAvna18aV jP26gEhaNcCvbOy3s24Q9sxOJQl7NxRVZYBe/8Cm0G9+jBko0DPwLNwWkycHyHVc1LxR E7mhomU3iL0JYPKsHFzwOM/sZ6xThym6zGBNifEDi+QaY69fZdsXh4BoIsTw5L5aM7uF eT273V2HjKK3cS2exmEgR9wzkYmCoO3vaDC2Hc9f+H9PMhRwABi41T7IT9f9VEEkulN+ pLZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=we6d2d3Z; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z14si132006oih.89.2020.02.10.05.07.02; Mon, 10 Feb 2020 05:07:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=we6d2d3Z; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729727AbgBJNFv (ORCPT + 99 others); Mon, 10 Feb 2020 08:05:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:38920 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729592AbgBJMkA (ORCPT ); Mon, 10 Feb 2020 07:40:00 -0500 Received: from localhost (unknown [209.37.97.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D6C512465D; Mon, 10 Feb 2020 12:39:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581338399; bh=tmBSDLVN9TjuA3cwnx4XYoof6ua0qOeDDb97kojFmIk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=we6d2d3ZXYmAe2xv/h0g15HviGBefJkHsyWimCrSdoNkq0h3GkRYARys5MLBIK9vl ejY9HjEicFDF2+fed5fosIjdJ5wpSx22ezCF/ZvahPevMEig1BIsxBEK/NMAeP069r mPGNIn3J6Asg5DNwHmyuLtD4ItoCwLM6ie6Zi9FQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hans de Goede , "Rafael J. Wysocki" Subject: [PATCH 5.5 098/367] ACPI / battery: Deal better with neither design nor full capacity not being reported Date: Mon, 10 Feb 2020 04:30:11 -0800 Message-Id: <20200210122433.425050841@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200210122423.695146547@linuxfoundation.org> References: <20200210122423.695146547@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hans de Goede commit ff3154d1d89a2343fd5f82e65bc0cf1d4e6659b3 upstream. Commit b41901a2cf06 ("ACPI / battery: Do not export energy_full[_design] on devices without full_charge_capacity") added support for some (broken) devices which always report 0 for both design_capacity and full_charge_capacity. Since the device that commit was written as a fix for is not reporting any form of "full" capacity we cannot calculate the value for the POWER_SUPPLY_PROP_CAPACITY, this is worked around by using an alternative array of available properties which does not contain this property. This is necessary because userspace (upower) treats us returning -ENODEV as 0 and then typically will trigger an emergency shutdown because of that. Userspace does not do this if the capacity sysfs attribute is not present at all. There are two potential problems with that commit: 1) It assumes that both full_charge- and design-capacity are broken at the same time and only checks if full_charge- is broken. 2) It assumes that this only ever happens for devices which report energy units rather then charge units. This commit fixes both issues by only using the alternative array of available properties if both full_charge- and design-capacity are broken and by also adding an alternative array of available properties for devices using mA units. Fixes: b41901a2cf06 ("ACPI / battery: Do not export energy_full[_design] on devices without full_charge_capacity") Cc: 4.19+ # 4.19+ Signed-off-by: Hans de Goede Signed-off-by: Rafael J. Wysocki Signed-off-by: Greg Kroah-Hartman --- drivers/acpi/battery.c | 51 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 12 deletions(-) --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -342,6 +342,20 @@ static enum power_supply_property charge POWER_SUPPLY_PROP_SERIAL_NUMBER, }; +static enum power_supply_property charge_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_CURRENT_NOW, + POWER_SUPPLY_PROP_CHARGE_NOW, + POWER_SUPPLY_PROP_MODEL_NAME, + POWER_SUPPLY_PROP_MANUFACTURER, + POWER_SUPPLY_PROP_SERIAL_NUMBER, +}; + static enum power_supply_property energy_battery_props[] = { POWER_SUPPLY_PROP_STATUS, POWER_SUPPLY_PROP_PRESENT, @@ -803,21 +817,34 @@ static void __exit battery_hook_exit(voi static int sysfs_add_battery(struct acpi_battery *battery) { struct power_supply_config psy_cfg = { .drv_data = battery, }; + bool full_cap_broken = false; + + if (!ACPI_BATTERY_CAPACITY_VALID(battery->full_charge_capacity) && + !ACPI_BATTERY_CAPACITY_VALID(battery->design_capacity)) + full_cap_broken = true; if (battery->power_unit == ACPI_BATTERY_POWER_UNIT_MA) { - battery->bat_desc.properties = charge_battery_props; - battery->bat_desc.num_properties = - ARRAY_SIZE(charge_battery_props); - } else if (!ACPI_BATTERY_CAPACITY_VALID( - battery->full_charge_capacity)) { - battery->bat_desc.properties = - energy_battery_full_cap_broken_props; - battery->bat_desc.num_properties = - ARRAY_SIZE(energy_battery_full_cap_broken_props); + if (full_cap_broken) { + battery->bat_desc.properties = + charge_battery_full_cap_broken_props; + battery->bat_desc.num_properties = + ARRAY_SIZE(charge_battery_full_cap_broken_props); + } else { + battery->bat_desc.properties = charge_battery_props; + battery->bat_desc.num_properties = + ARRAY_SIZE(charge_battery_props); + } } else { - battery->bat_desc.properties = energy_battery_props; - battery->bat_desc.num_properties = - ARRAY_SIZE(energy_battery_props); + if (full_cap_broken) { + 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 = + ARRAY_SIZE(energy_battery_props); + } } battery->bat_desc.name = acpi_device_bid(battery->device);