From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 072D91E1A18; Tue, 11 Mar 2025 15:35:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741707301; cv=none; b=svNFwle+d4wttf6EEwbzcBdoEecaNHYMUoosjYayOBOOqpFVJxr8VsRGugr1nOZujuwVhYqOpwN/DB7LNr+03xUo9+/Gud9jqAWouMWZ/RPRbJL5nSAiA7aAEOAk77IczEBEoHbDSO0ewmqrqEfMUSsOhkE3mf79MmqHHBfaFA0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741707301; c=relaxed/simple; bh=nZPlRUOqZeFxgw2JHkcnyCcn2OOjvsZShZGIKGxjTJs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BNMfYZIXy1n9nE8K1BiVRgc+4Axo82YZ2FrLoE31UiKDC9KtBuFI1KBf9AZs+JEbEqzT62lLpbl/2iJ9Uq1QuN2yAuGAmKwDLuaj2XfUF/T+pJlmfd3emaqh21xwAhYqXyK93eusqJ/sGRRja5/dJ9oeNd5LUsZDdVfaLnTn7GA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Z4sHnyjN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Z4sHnyjN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2DB65C4CEE9; Tue, 11 Mar 2025 15:35:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1741707300; bh=nZPlRUOqZeFxgw2JHkcnyCcn2OOjvsZShZGIKGxjTJs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z4sHnyjNgbeZ/193V9+7ej/JLFe/Tv0PMjX1VZwlavF3tLaE99pB68txnlIPdeF62 6NKww19g8zU+ct3mXivcK1KySQnYqNzH/FM2ze7JINi026KoyzR3w1FsKFHIRf8BBK 9zgExbYlBA6uooMJ7vsVWSG+W6YVnIT5zjRTFf44= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Andrey Vatoropin , Sebastian Reichel , Sasha Levin Subject: [PATCH 5.10 341/462] power: supply: da9150-fg: fix potential overflow Date: Tue, 11 Mar 2025 16:00:07 +0100 Message-ID: <20250311145811.836423715@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250311145758.343076290@linuxfoundation.org> References: <20250311145758.343076290@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Andrey Vatoropin [ Upstream commit 3fb3cb4350befc4f901c54e0cb4a2a47b1302e08 ] Size of variable sd_gain equals four bytes - DA9150_QIF_SD_GAIN_SIZE. Size of variable shunt_val equals two bytes - DA9150_QIF_SHUNT_VAL_SIZE. The expression sd_gain * shunt_val is currently being evaluated using 32-bit arithmetic. So during the multiplication an overflow may occur. As the value of type 'u64' is used as storage for the eventual result, put ULL variable at the first position of each expression in order to give the compiler complete information about the proper arithmetic to use. According to C99 the guaranteed width for a variable of type 'unsigned long long' >= 64 bits. Remove the explicit cast to u64 as it is meaningless. Just for the sake of consistency, perform the similar trick with another expression concerning 'iavg'. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: a419b4fd9138 ("power: Add support for DA9150 Fuel-Gauge") Signed-off-by: Andrey Vatoropin Link: https://lore.kernel.org/r/20250130090030.53422-1-a.vatoropin@crpt.ru Signed-off-by: Sebastian Reichel Signed-off-by: Sasha Levin --- drivers/power/supply/da9150-fg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/power/supply/da9150-fg.c b/drivers/power/supply/da9150-fg.c index 6e367826aae92..d5e1fbac87f22 100644 --- a/drivers/power/supply/da9150-fg.c +++ b/drivers/power/supply/da9150-fg.c @@ -247,9 +247,9 @@ static int da9150_fg_current_avg(struct da9150_fg *fg, DA9150_QIF_SD_GAIN_SIZE); da9150_fg_read_sync_end(fg); - div = (u64) (sd_gain * shunt_val * 65536ULL); + div = 65536ULL * sd_gain * shunt_val; do_div(div, 1000000); - res = (u64) (iavg * 1000000ULL); + res = 1000000ULL * iavg; do_div(res, div); val->intval = (int) res; -- 2.39.5