From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796435831; b=HOiyRVCZnT7tpiZ6tZhP3QzvrPJq5gdEEyNMKSP9VN+26QOTAvHYevj54BhahKKTn24x sMStGvUh78AXJkWIwqE8nTAYXKJz808S5PgWnsiA2SM+ZzVmyMpg6mxfh8w9E/v796w2S 9FYXJC/AO0HqWeVGG6GgeRAsFTRXEs2Z37T6S7Cxe6jdmwpHQ0daE1odxx27Vo6TGMZ6q hjaen47NyS1MtyFwX+6DWVFL9RKPrLLSBWPkRNQNWmpotDwElJZmeRmviKDT4zHZR7/Px BfL3z4mm25O/FRyGTow+Dja52cn6kS2kLhsRKduPshNpOZ+S4VYfziJUY3zpgjFoG/w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796435831; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=H0zSGuY9IZGfodKxozH3ma87jf5Wu8EqyNYwOPOEjRc=; b=seY7ep15A8Rf7o+lpxM0okqdfisHwRALztwb3xOXRwxvhCwIebgkdyDmkohy63sGcQzl WxYYWE56Y/Kq4Obi2XuoxSPQsMs9h1Idxr0AWkWYNRGxw7GsS27d//mQhLKTJuqWjzY/x sHlkKYaU6b/RsLMaUE8/6cXvrIjtU40VhSiCBGJvUk6H0RiizXr2VBWOpe00UWZxo+nNC hsyV6lgJtn2WT9FFCdVoCnamqtKAfmv+TvbNrzZ94Ymxswat2XnSQs1xlTbamBfnTHRjz DWz9GdpH5TOa0ty3ppYrXESawWXAAOmwKwG87ZKbwcrgpmlwbkpZroO6qvfb1rikDqQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=PxC+eCtN; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D373606A322 for ; Sat, 5 Dec 2026 01:57:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=PxC+eCtN Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54FA71F00936; Sat, 5 Dec 2026 01:57:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796435831; bh=H0zSGuY9IZGfodKxozH3ma87jf5Wu8EqyNYwOPOEjRc=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=PxC+eCtN6A0PqMuIBfgIV9rqqqTsFhbJmhkB0BxR0smrXLj9BD6R53tuGTa/FGXAH coIqhoWWMhFubwVQ8QiahVY/4gXTGP8W02nCUCHXZVFuLxd4ruTZ8iFNzOTTjX7tb8 XVBpeTcLQ5dTh1aP7h3PE/LSKROEy897fC7HBynZgwSbBNWI4Yao4494NItoyFdD0m XsiEE0io8URO3yLn3wBzj1i8fTRDWYD+f6UqA1fWeMgtBSl92gB3j4ofz8CfHMZCtb Ryo/x4tHNKm8rkkAO9qhYHiYXXiH3sxexeHoNu6hR0LQzApcZr54vRH88PpX21gwIl RMi7eSLIj+zNA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2] hwmon: (tmp513) avoid divide by zero from rounded-down current LSB Reply-To: sashiko-reviews@lists.linux.dev To: "Shirong Zhao" Cc: linux-hwmon@vger.kernel.org In-Reply-To: <20261205014552.39-1-shxzhaosr@163.com> References: <20261205012428.120-1-shxzhaosr@163.com> <20261205014552.39-1-shxzhaosr@163.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 01:57:10 +0000 X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list > tmp51x_calibrate() computes the current LSB as >=20 > curr_lsb_ua =3D DIV_ROUND_CLOSEST_ULL(max_curr_ma * MILLI, 32767); >=20 > and then derives pwr_lsb_uw =3D 20 * curr_lsb_ua and >=20 > div =3D DIV_ROUND_CLOSEST_ULL(curr_lsb_ua * shunt_uohms, MICRO); >=20 > so the calibration register write is DIV_ROUND_CLOSEST(40960, div). > curr_lsb_ua decreasing with a larger shunt means that for large shunt > resistors DIV_ROUND_CLOSEST_ULL() rounds it to 0. Both div and > pwr_lsb_uw then become 0: the calibration division traps, and a later > write to power1_crit (tmp51x_set_value(), DIV_ROUND_CLOSEST(val, > pwr_lsb_uw)) traps as well, because tmp51x_is_visible() only hides the > attributes when shunt_uohms is exactly 0. >=20 > curr_lsb_ua is a minimum resolution that only needs to be >=3D 1 uA; round > it up with DIV_ROUND_UP_ULL() instead of to the nearest. This keeps > curr_lsb_ua, pwr_lsb_uw and div >=3D 1 for the entire valid shunt range a= nd > lets large (but valid) shunts calibrate normally instead of being > disabled. >=20 > Fixes: 59dfa75e5d82 ("hwmon: Add driver for Texas Instruments TMP512/513 = sensor chips.") > Cc: stable@vger.kernel.org > Signed-off-by: Shirong Zhao Sashiko has reviewed this patch and found no issues. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205014552.39-1= -shxzhaosr@163.com?part=3D1