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=1796434639; b=TaKMPOnUO9HIf2kZvNhTeXJ63sMSAFqTQKaC/7NvWgmCVEDVgPJhpmPsyZB8g6fPX734 BkYXrIpfVEn0zlQLJvnetHgC+bZ/JRnQr6hNRTd6OKQnagIv1z6U3RjIjscRqEvaH9DVs tzuVjOqhqUnSfExFv7g8V50Bud69zUb9wki+5HuxvNLggKk601BbrXQ3xNarEZg2377DW UECeNOhMiSEKeRABQN5JAhbjgtfjkEaN5Ic+vqhM678lfCoJHAB9jtwPGfcdhiUxNzAro igeld3MO9zSvyHlflRcrSSf4OrYf/HHDiPY5Xg3zV4Q4j2Pz0Pz2ZTA3OV4/QZNFavA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796434639; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=izQCW4PSsBPRPcjiqIUhGlH6I3J8BU8zhA2haKL1KyA=; b=tX0CZcCy9v6Y8pFi2/Ufc3fFem8o8HxI9n4Kom5X+tTaZMclkNRwed25oK11QG5nifzo w3YBLEB/DM6UKaKbQwlrQK+jA271IhNFL6L5f3yKfsd00u7KySVA+6wHTqmX7JdwArdTz Jxhte3LIgb6tTN8atxlXkWfUkbcIE8207oBUY2KZqm7VuO6IHxl+4lHEMDRR+JP2ahEZY 4+m59K467XEN/WCtIDw5+138xmJaJOXs+l+s6I49tv9Rd71injADk+mA3amq3y3i/PUCQ iu/DaJOtK80XCyIlF/5R145dy7M32uIzAm2HR5YSKmwRMm1WTiiepkwoaP2egwNYu1g== 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=jZZMAsEB; 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 2B18A606A322 for ; Sat, 5 Dec 2026 01:37:18 +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=jZZMAsEB Received: by smtp.kernel.org (Postfix) with ESMTPSA id A82421F0092B; Sat, 5 Dec 2026 01:37:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796434638; bh=izQCW4PSsBPRPcjiqIUhGlH6I3J8BU8zhA2haKL1KyA=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=jZZMAsEBYUc5wmwIcK5M9m9024OnzbWX9xromjKfKWpFr5TxLx8i0MwGq2A+BWYlZ Z65jD9PZkuYcf2uD9ffuWsqx28GKDcPi6Hrol3RNEKDYbTNaMQM1vIbzb5D30/4/HO mvR4byLwVlR/Lt3DbBqcgyddlDVwzd3N0p5JqqkjZTAXK4613GPiNNJRoVdeJ0qCcd dVp7zbWYCSV28AI5yvxqKpthx6WSQkgxRhyiRWPoSe6LuB/6cIbZEh5tY+9+UUn2Tl Er0NH08GcmZIKR8zQqx6qwfs9hgwhPgslZLXlXFv/qpvme646pSq8bVUhGsCxvWIPv iCKFAsWaVYfmA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] hwmon: (tmp513) fix division by zero when calibrating a large shunt Reply-To: sashiko-reviews@lists.linux.dev To: "Shirong Zhao" Cc: linux-hwmon@vger.kernel.org In-Reply-To: <20261205012428.120-1-shxzhaosr@163.com> References: <20261205012428.120-1-shxzhaosr@163.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 01:37:18 +0000 X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [High] hwmon: (tmp513) divide-by-zero in tmp51x_set_value() when div =3D=3D 0 - [Medium] hwmon: (tmp513) tmp51x_calibrate() disables sensing for valid large shunts - [Low] hwmon: (tmp513) inaccurate shunt bound units and direction in commit message -- commit a7739395a7938b1d11a4a6e3d2b569de06b0cc02 Author: Shirong Zhao hwmon: (tmp513) fix division by zero when calibrating a large shunt This commit adds a check for div =3D=3D 0 in tmp51x_calibrate() and writes = 0 to TMP51X_SHUNT_CALIBRATION to disable the current and power measurement engine instead of dividing by zero. > The shunt value comes from the "shunt-resistor-micro-ohms" device-tree / > firmware property (tmp51x_read_properties()), so this is a device > configuration issue, not a runtime userspace input. It is limited only > from above (shunt_uohms > pga_gain * 40 uOhm is rejected); there is no > lower bound that keeps curr_lsb_ua nonzero. For the default pga_gain of 8 > the trap triggers for shunt resistors from about 19.4 Ohm up to the 320 > Ohm upper bound, i.e. for perfectly ordinary shunt values. [Severity: Low] In tmp51x_read_properties(), the rejected threshold is pga_gain * 40 * MICRO uOhm (pga_gain * 40 Ohm), not pga_gain * 40 uOhm. Also, since curr_lsb_ua decreases as shunt_uohms grows, keeping curr_lsb_ua nonzero would require a tighter upper bound on shunt_uohms (or a lower bound on max_curr_ma), not a lower bound on shunt_uohms. > diff --git a/drivers/hwmon/tmp513.c b/drivers/hwmon/tmp513.c > index a3a4772a37e93..b7eb6143faff3 100644 > --- a/drivers/hwmon/tmp513.c > +++ b/drivers/hwmon/tmp513.c > @@ -565,6 +565,14 @@ static int tmp51x_calibrate(struct tmp51x_data *data) > =20 > div =3D DIV_ROUND_CLOSEST_ULL(data->curr_lsb_ua * data->shunt_uohms, MI= CRO); > =20 > + /* > + * A large shunt resistor can round curr_lsb_ua down to 0, which makes > + * div 0 as well. Just like the shunt_uohms =3D=3D 0 case above, disab= le the > + * current/power engine rather than dividing by zero. > + */ > + if (div =3D=3D 0) > + return regmap_write(data->regmap, TMP51X_SHUNT_CALIBRATION, 0); [Severity: High] Can writing to power1_crit still trigger a divide-by-zero when div =3D=3D 0? When div =3D=3D 0, data->curr_lsb_ua and data->pwr_lsb_uw are 0 while data->shunt_uohms stays non-zero. tmp51x_is_visible() only checks !data->shunt_uohms for hwmon_curr and hwmon_power, so power1_crit and the other disabled current/power attributes remain exposed in sysfs. drivers/hwmon/tmp513.c:tmp51x_set_value() { ... case TMP51X_POWER_LIMIT: regval =3D clamp_val(DIV_ROUND_CLOSEST(val, data->pwr_lsb_uw), 0, U16_MAX); break; ... } Any write to power1_crit calls tmp51x_write() -> tmp51x_set_value() and divides by data->pwr_lsb_uw =3D=3D 0, crashing the kernel. [Severity: Medium] Should tmp51x_calibrate() round curr_lsb_ua up instead of disabling sensing for valid large shunts? Documentation/devicetree/bindings/hwmon/ti,tmp513.yaml specifies that only 0 disables calibration and values up to pga-gain * 40 * 1000 * 1000 uOhm are valid. Disabling the engine on div =3D=3D 0 breaks current and power sensing from roughly 19.4 Ohm to 320 Ohm at the default pga_gain =3D 8. curr_lsb_ua is a minimum lower bound so the signed current register does not overflow, and only rounds to 0 because of DIV_ROUND_CLOSEST_ULL(). Using DIV_ROUND_UP_ULL() keeps curr_lsb_ua >=3D 1 uA and div in [1, 320] across the entire valid range so large shunts calibrate properly. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205012428.120-= 1-shxzhaosr@163.com?part=3D1