From nobody Thu Apr 9 13:31:47 2026 Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4841A35A397 for ; Fri, 27 Feb 2026 07:15:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772176516; cv=none; b=aa3JJLUjXcHwecwJuo9RCZz0qWH2JlMRRuqf44ffluMvxQ2MQrM2y25n4eoECeobgleWZ4WCuapnd10iMGOpbYL9v0KvZOUkll9isiwfB8Na51i1v8un2/H8YkJXjm58I4Ts7u2cWA9b5F6gFTARD9cxXTK0cUvSFq8A91L/gAg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772176516; c=relaxed/simple; bh=Yt0sNw9b+pj9fmaA7tM3vgRmJfOjPqWF3O7G+LpIrnI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NSiIFoudW+8KQt9kNZtFRcRMfY4ki1SoPsl/JukgaHjYEUKGYuHCbgDhOQp0INvhlOMx6BafqzoUuWBFZVReZM7Vwte6fF/sSyJo11q7RGr8RgH92H0lel01TW/DnsNLhv32h7qSfMq/x6jHBLigWr6c6p/UoQrHolbzajFazXA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=stESTL+C; arc=none smtp.client-ip=209.85.208.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="stESTL+C" Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-65bf302471dso2019452a12.1 for ; Thu, 26 Feb 2026 23:15:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1772176513; x=1772781313; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=WClHPYuZJqN8n1xZlLHGmGajkWi1sdB8zHmMALTl0VI=; b=stESTL+Cj6Rs2il/ypkebqlgradv5Sh2J1GLm2AtBXiMblJy6GdIxvIPLKEA3km20F D6ybw12H+LoQMTpMlkxWAIHWew/YQ7aAh226SLiSjaiGhp/twLtOP1otHBXq24lJ7++r 9NefHOQzCjsM1CB1G+X7bLxgdo0o2YjKPBChSe6hM+RCmcCs9ozUHP5IUoEYi5UamkpI qgtLMSKbsiF0s3VZQP2ZTEiLea0Z7m41ZvDCmot3/DTLmPCBZGpibd+Wx4ni9yFbrkUA x7hudALjSr/V5/q1dXCJhefFojFmuOIEO+rXsHtho//BuL9zt0SSwN9Woq/sk5KkHisP 3eZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772176513; x=1772781313; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=WClHPYuZJqN8n1xZlLHGmGajkWi1sdB8zHmMALTl0VI=; b=KfqOyS4lsgMpy5zHwdiXJjuwOLMi1hpZ5NJGChepn/PgvFyYGiXTBgiJzefct2eZ9u R1ee6TxEzHhWtcT95GF67/BrkDO4DHZ7L1OH58T55MectV1TPUM5iz/hBFCiR/dqe4Xo I+Td++6mOLYMHASfILk4FaqzJh3peLoeafP1KKUSg+jhTSqTsI/ogddF6YIxUh66QVlP 43L0atXYn+0GuBpWneznnbop6Velr+H/0MB+t7QYGwIsz7BHxrnHB1dWVaf8TjdbSV4R nYXuAKD1ZMo8ogerfmBcGvjItBrWn+R2UEhZZoYycSoknza+qzuKHGjIpdjwZZWQWfGB 2GEg== X-Forwarded-Encrypted: i=1; AJvYcCVgC3/SKJLxGJHf/IdYBVN3KW4UbEPxEMy+uCpMc36Olk7LVY7+ZeHQ0sMjtukmzMO9WP6KQDBsn60Ag88=@vger.kernel.org X-Gm-Message-State: AOJu0YzFNVCyDyQ4O4GvjOSHs6KP+nJf4kQb/ebeiVqJJDBwCV553K2/ PTGJjOR/gEiImw8mGS7qThZsjc77HV1+WZSNi+FKexoaz1oqsC4PeEnCfO7Sr6luOd0= X-Gm-Gg: ATEYQzzvwIf28HHbhKgo03GjOJQI8teqLwrkmi1SMcVIThmPHGKCKbylykqe0WKhnq+ Ep6qBHI1v54R/nUAyEpBPb/cjxxpbAQp7/6Tmp9RkQNgH21H/JuGAFtuEv8vT/ffHQ5imI9SXz+ d5qSYCS7eFyAECn1pfVTXZzGGGFHtNTrLcwkcsWzig0xX0063PeHWEPI/ltcZgmYq5NPVaOLyY+ YiU2Ph284zc6+x1yHlzJEzjZEt48jcc4e2vTSQeegGSrtgZ4yqa8fwB5N5jKO0ZuOfJ1vW5uvJk cgqnuvvpxUFqvyN47aeSdVxiKi8UAWQcudYB5n9n0+iIBxnJCd/ZEDsGMtjcJpVQxiC5tzINuAH 55RNFe8IiIhrT2WWcFvOKZJfNeQFQyIsjaXs2uUIhArcLOTUpwsBb7nEwYiIY6/NPexHBkrRDMj FgScTZggsH2QfDTLu4amamJLvfKZfaE48Ne1oimFlYO85k5auAZqfp/cPvZ5LOcZ6x8kqZiTDaV 3ldwP3ORHPSv5Yb4A== X-Received: by 2002:a17:907:3e91:b0:b93:5521:b57a with SMTP id a640c23a62f3a-b93764b5f90mr102410666b.31.1772176512558; Thu, 26 Feb 2026 23:15:12 -0800 (PST) Received: from puffmais2.c.googlers.com (244.175.141.34.bc.googleusercontent.com. [34.141.175.244]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b935aeee867sm124205066b.66.2026.02.26.23.15.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Feb 2026 23:15:12 -0800 (PST) From: =?utf-8?q?Andr=C3=A9_Draszik?= Date: Fri, 27 Feb 2026 07:15:11 +0000 Subject: [PATCH v2 06/11] power: supply: max17042: avoid overflow when determining health Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260227-max77759-fg-v2-6-e50be5f191f0@linaro.org> References: <20260227-max77759-fg-v2-0-e50be5f191f0@linaro.org> In-Reply-To: <20260227-max77759-fg-v2-0-e50be5f191f0@linaro.org> To: Hans de Goede , Krzysztof Kozlowski , Marek Szyprowski , Sebastian Krzyszkowiak , Purism Kernel Team , Sebastian Reichel , Rob Herring , Conor Dooley Cc: Peter Griffin , Tudor Ambarus , Juan Yescas , Amit Sunil Dhamne , kernel-team@android.com, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Andr=C3=A9_Draszik?= X-Mailer: b4 0.14.3 If vmax has the default value of INT_MAX (e.g. because not specified in DT), battery health is reported as over-voltage. This is because adding any value to vmax (the vmax tolerance in this case) causes it to wrap around, making it negative and smaller than the measured battery voltage. Avoid that by using size_add(). Signed-off-by: Andr=C3=A9 Draszik --- drivers/power/supply/max17042_battery.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply= /max17042_battery.c index b9277f81a25d..8808c0d2ad10 100644 --- a/drivers/power/supply/max17042_battery.c +++ b/drivers/power/supply/max17042_battery.c @@ -201,7 +201,11 @@ static int max17042_get_battery_health(struct max17042= _chip *chip, int *health) goto out; } =20 - if (vbatt > chip->pdata->vmax + MAX17042_VMAX_TOLERANCE) { + /* avoid + * /sys/class/power_supply/max170xx_battery/health:Over voltage + * due to overflow + */ + if (vbatt > size_add(chip->pdata->vmax, MAX17042_VMAX_TOLERANCE)) { *health =3D POWER_SUPPLY_HEALTH_OVERVOLTAGE; goto out; } --=20 2.53.0.473.g4a7958ca14-goog