From nobody Wed Apr 24 14:06:43 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 4VPglS0rTHz5HQsn; Wed, 24 Apr 2024 14:06:44 +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 4VPglS0CCXz4Xtw; Wed, 24 Apr 2024 14:06:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1713967604; 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=NrBehe1CZZ/+PvPSg/5ncwWtvNJ71ZMjv4yuWiQfSIs=; b=HdTiKffhhsKz+OAdrY9Rx5i3+wfwpBL0uxpcz0sHGam2iC6YzUeBDVq67rVJXzmFUPy2yQ XgQdv6ybqp3Yd8fLBzZv0jLU5a0SRIXwmhuzDKdFW2s6EO40AO04UZ+sXlV06ysGLXdCJD tKubfwQDGEmXU5AFyY55NkXMwzmVzPS9zyV9Wd+aT9DoJjG6+MLznoCQKqEbw6Uhr6EdWR YDkX3QT1iTiQWwZh1L5KhQOuGNyTmujFPe0aYBUE52YHK4KD2RR5C2I5ytP4CMWLn08Mb6 zAHrQHOuIyLtxuBpRQhJkMyV5mHxZ+M+HYPZzpQ5RWVkgV/rK9aXAz1KVx4wPg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1713967604; a=rsa-sha256; cv=none; b=PSe14gdjzWJ1+LuX1OK6b7+eVz1JnKqKrKq16KiewygU2LGJK3/ZKCSFiT9wT9FlPSl0fo pLsIIIoO3rvqI1+/929HhqTBrlt34VEmBSS75yfBuMICtlO8c9oSejo2tNesXZ9iwV7DoO k3HlJBH66szFj+QEXfmp6Sn5/KrkS1mgEuwdGYaoEoAmYMPnl5QqR9Iig1o460oVPQ+spA sESNFRoaqCpQ2TGuBg+P/oKIEC1Ew74gmSQUZ5IUX0S6ItVXrb7uSW22TFdEjVAZe25fL/ N373oeBGBoX1xJpAQ9EnfHWW7eAPLpPLRD9i41n8QOs1AA02u7q87V0mnS1YaQ== 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=1713967604; 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=NrBehe1CZZ/+PvPSg/5ncwWtvNJ71ZMjv4yuWiQfSIs=; b=aiOG/iicLDVdpgXjL89J+nvgydZcvcqjwQiuRR53S74/okr3ezb4Aeb4RiYGVdc3pZcy9p Y8NIccrGJrj4UsxSNyLDI3v6joBh0MlZJztqjkYb8qTGu1v4v9yRJ7OWICZZq7Vgjwc2so m+gUeA4ttXHdJbC9e0NUthsABU9lGDvImctxLrTQQXX01GQMBfC+hyTWMoMwwuI6d9FNv5 pPd5oiNq5QYyRBrrxU5PDNORBv1FvDVxrNgu2eI2O5/9ub0ve8VFxhBTr1Pke0ta7OLDbj 76Dql4rU37EteZ+0rA/enzu+YmQEo8wUMHyAlhDsXmDhaaEa8QZdP6UerMfilw== 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 4VPglR6w1gzJWQ; Wed, 24 Apr 2024 14:06:43 +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 43OE6hcP039312; Wed, 24 Apr 2024 14:06:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 43OE6hE9039309; Wed, 24 Apr 2024 14:06:43 GMT (envelope-from git) Date: Wed, 24 Apr 2024 14:06:43 GMT Message-Id: <202404241406.43OE6hE9039309@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: 1a4e512adbab - stable/13 - 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/13 X-Git-Reftype: branch X-Git-Commit: 1a4e512adbab4dfc072d6331a7483f4188fb96ce Auto-Submitted: auto-generated The branch stable/13 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=1a4e512adbab4dfc072d6331a7483f4188fb96ce commit 1a4e512adbab4dfc072d6331a7483f4188fb96ce Author: Josef 'Jeff' Sipek AuthorDate: 2024-04-16 23:01:28 +0000 Commit: Ed Maste CommitDate: 2024-04-24 14:06:08 +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) (cherry picked from commit 788987e034b1c73d779a3aa179f79f672bbdb366) --- 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;