From nobody Fri Apr 19 03:17:25 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VLKZZ0GfXz5HgK3; Fri, 19 Apr 2024 03:17:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VLKZY6c1pz46Z6; Fri, 19 Apr 2024 03:17:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1713496645; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Udo9XnrhX9gXuuMZ/V05AoaNNfLvPHAjqIIu8jfGajY=; b=Vc1h3vmTjwHdbSU7Jh+AxD12M78rG9alPK3frVp3O20TfQ3UgCEOavVVpgZnME8kR5JWN8 8ujbSLAob2bTUlJ/RAINeKN7xZtLFtMfZ38QLftXDyFPF9oZI3MpMXEihcfePhp91/6z/k c52QEKOy9x8lIY7kF22XM/V8cTUBs75CoXuS3nzE3f1ck0D3VjXZiD1f2NnD+QboJuOamH 17BE+2j44lmpdOrcXsKaEWI9Cbsq2ocjb9bGs1WDBwNCjhiXmn2O6j2m1vJhHxxzowYSMw 8gKVZT/TLh9Q8NpHWqTJyqFAgVbn23Z1BYLAHDxyhz8ZqtEbaQWZnm1haHAwFQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1713496645; a=rsa-sha256; cv=none; b=rb2jJVODmOOiA54wyPihOMN7ENggvN5PeXe5x6euD/lLYgx37ZEvtTRFFQD9OC7H2OWfxn 18KnPhWIHBqaOUgRRqIALJupth72HLA98KAua9/JQuCV5dkSWYqWDKRazG/0A4tVaURv3v ZVv0nOLQ0jfHN1koOtwfMZxGXVaF5ygJ01+r3ATDbKYWesEd8hk8wuxvbGtbIAlQFIRPGu TTiGNUIp1EdfK9gan4ffjFo5+6A1hbSGy/nLnt9+hUa4M7gohP72sRvA8jGVu1DAcpPwKP yUbblARDpv9P14TrUdpziZKePdZ8ii9WRYQNIG/0XeIel2ZIV2wDRh4MKrBmCQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1713496645; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Udo9XnrhX9gXuuMZ/V05AoaNNfLvPHAjqIIu8jfGajY=; b=bbt5AnyKDTL5QLMvSIwour36btTCa6aCqkMjWZ9h5OCC01X+8p84rlZAFwkhed0TYlhf8o vEtlrzTCXXIfMXImRTd9tYSeKegroYu2Q9HMNLD5rfxYrJKZv8Ipll7WUoO9zkUgm8PQF5 NuOAicBDCkGVeywogmnJIR50OshP2A7T4dUCjXw2W16J3ASQe0GyMypLoqb/xRpy5EjDeL Tm3jQidy0IwDG7ZiSCdhzE2kB1BA1LSebCtrl+7DqASggALjlmnKHJU99Z0g8MSZD/TS20 TxIYnYttvcVyscaLuXr7kBpswifHiAWFsVcqwQ/rGRb29SpblWLwl5jqOC98OA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VLKZY6CXkzcrs; Fri, 19 Apr 2024 03:17:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 43J3HP5K035569; Fri, 19 Apr 2024 03:17:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 43J3HPIF035566; Fri, 19 Apr 2024 03:17:25 GMT (envelope-from git) Date: Fri, 19 Apr 2024 03:17:25 GMT Message-Id: <202404190317.43J3HPIF035566@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ed Maste Subject: git: 788987e034b1 - stable/14 - acpi_battery: avoid divide-by-zero when no devices have capacity info List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: emaste X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 788987e034b1c73d779a3aa179f79f672bbdb366 Auto-Submitted: auto-generated The branch stable/14 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=788987e034b1c73d779a3aa179f79f672bbdb366 commit 788987e034b1c73d779a3aa179f79f672bbdb366 Author: Josef 'Jeff' Sipek AuthorDate: 2024-04-16 23:01:28 +0000 Commit: Ed Maste CommitDate: 2024-04-19 03:16:52 +0000 acpi_battery: avoid divide-by-zero when no devices have capacity info On laptops with builtin batteries, disconnecting the battery may show up as a battery without any capacity information. (The theory is that one is disconnecting the cells but the electronics identifying the battery are still connected.) As a result, the loop over all batteries in acpi_battery_get_battinfo results in total_lfcap == 0. So, just check that total_lfcap is non-zero to avoid a division by zero (triggerable by sysctl hw.acpi.battery). Reported by: Stefano Marinelli Tested by: Stefano Marinelli Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D44818 (cherry picked from commit 2e850b832f5d2adb9b230d191277d67c00caaab9) --- sys/dev/acpica/acpi_battery.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sys/dev/acpica/acpi_battery.c b/sys/dev/acpica/acpi_battery.c index 7455c6afc6a6..cfd8261d5eab 100644 --- a/sys/dev/acpica/acpi_battery.c +++ b/sys/dev/acpica/acpi_battery.c @@ -266,7 +266,14 @@ acpi_battery_get_battinfo(device_t dev, struct acpi_battinfo *battinfo) */ if (valid_units > 0) { if (dev == NULL) { - battinfo->cap = (total_cap * 100) / total_lfcap; + /* + * Avoid division by zero if none of the batteries had valid + * capacity info. + */ + if (total_lfcap > 0) + battinfo->cap = (total_cap * 100) / total_lfcap; + else + battinfo->cap = 0; battinfo->min = total_min; battinfo->state = batt_stat; battinfo->rate = valid_rate;