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=1796382121; b=1I0GFZIhOuNDhM+FO8cDo7cbyweZyQq+eanZqfNJI1br89+nfMtj50aJ0RuPR0Zy7rBA dHUPjDrYsKkd/zmKjoZVBL7tGFSHkH6hf1//zdgLhcmKUKgU6YEQaGyh7wSg7ShxymHZe FZzU5i21Nzhcn45be7WJzaW17GWpfTmTXXoGGou8pP0uYZ97s/qaRHdPhF6Q/d4pUlbpw 5MoecC6qzvmrY5uhwwjJfmPRvbc0/SzELETjVbSQaW5EnkMavFqrmOWu6asSjbeBogCG1 daSblJn1kHyFGddcEMMO4rYnx1BBslz/3cmrCT1Mp3oSqbHUSNkstDaIuOoXexmHbJA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382121; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=RQBx6wJ/JKE5Goh0XVJC0kl6UakTEWh/MpFh+V4vLHU=; b=RH3NYPdNa7owaH2TooLXbVUZ/mr7o4enCbq/k+EEQTnFz9tH6drKIDRcvsmA19T3YHLF 79hNWjWCUKUFAon0rpb8H/Ra8zBp36PYFIEmvHxML6gTkTQ1MJFrIG1dFIzJdLNmOHb12 ZKOnAB5i26Dmvps7dtxy7h1UVz+NlG9hWj6UMQoW8Q+qyOsY/iLhVwznXxmpsII9KBPk1 rhKtfrDzPsQSJTmj7tbuStYbqYWStNKplwBR6KVWzImY+XYQ3bVnnWVeoOSqiITz8Y64o crSm3Uf2s3fGmKpSFtIxUeIEICs9pv/QdoxhUmoyyrlRYVEr3zWoLqeL6K4lHj4qWoA== 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=NKFggPHt; 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 4D6BF606A322; Fri, 4 Dec 2026 11:02:01 +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=NKFggPHt Received: by smtp.kernel.org (Postfix) with ESMTPSA id E50901F000C2; Fri, 4 Dec 2026 11:02:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796382121; bh=RQBx6wJ/JKE5Goh0XVJC0kl6UakTEWh/MpFh+V4vLHU=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=NKFggPHtzXrLjO0ZIykbYbvsKW9XShCcjM8A1rfB+UbQmMNRf41qkV49SwDXyHuGN Cok2pD4ON9wBSwDJJb27jyXDvJYHuzOpRff56nSBt4PsoDJw3LcZsemJU7+Lq4IkDD 2QA1m5nDbn+9jBFcqEEMq79DzHQNZ60UrZ7md4j9ukfcGFSn9+YK2TgybVez3RnhkM D62Nj5eHzf6SCNgQ89Xxw3pE01UBOK+be/bUYHfyqqTKtF+LaZNuypRW/uzc9WNyOV uVOaGoBmi4SRPEOKc+hcMMxKFRf9dbzx3vB/3czUZJr9iR3YI+KJ/PVhgnp+vb4Sej k9zTRwX2KNNbg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v7 4/5] thermal/drivers/sun8i: Add support for A523 THS0/1 controllers Reply-To: sashiko-reviews@lists.linux.dev To: "Mikhail Kalashnikov" Cc: devicetree@vger.kernel.org, linux-sunxi@lists.linux.dev, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <0ffd22347841e102ba4cc9e806894c7e714a4ec8.1796378254.git.iuncuim@gmail.com> References: <0ffd22347841e102ba4cc9e806894c7e714a4ec8.1796378254.git.iuncuim@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 11:02:00 +0000 X-Mailing-List: devicetree@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 4 potential issues to consider: - [Medium] thermal: sun8i: wrong bitfield check in sun55i_a523_ths_calibrate() - [Medium] thermal/sun8i: missing zero check in sun55i_a523_ths_calibrate() - [Low] thermal/sun8i: sun8i_ths_calibrate() skips devm_kfree() on 2nd cell error - [Low] thermal/sun8i: sun55i_a523_ths_calibrate() ignores high-temp scale -- commit 30ae4ac56f828a8fbb1c02d0d42f417911331818 Author: Mikhail Kalashnikov thermal/drivers/sun8i: Add support for A523 THS0/1 controllers This commit adds temperature calculation, eFuse calibration, and compatible entries for the Allwinner A523 THS0 and THS1 thermal controllers. > diff --git a/drivers/thermal/sun8i_thermal.c b/drivers/thermal/sun8i_ther= mal.c > index 3606548801f02..4a81486f8faec 100644 > --- a/drivers/thermal/sun8i_thermal.c > +++ b/drivers/thermal/sun8i_thermal.c [ ... ] > @@ -298,6 +319,105 @@ static int sun50i_h6_ths_calibrate(struct ths_devic= e *tmdev, > return 0; > } > =20 > +/* > + * The A523 calibration data is stored in the eFuse, split across two > + * nvmem cells. THS1 has four sensors, including ths1_3 which is used > + * for the NPU, each with its own calibration value. The fields are > + * packed as shown in the layouts below. > + * > + * efuse layout 0x38-0x3F (caldata[0..3]): > + * caldata[0] caldata[1] caldata[2] caldata[3] > + * 0 16 24 32 36 48 60 64 > + * +---------------+---------------+---------------+---------------+ > + * | | | temp | ths1_0 | ths1_1 | + > + * +---------------+---------------+---------------+---------------+ > + * > + * efuse layout 0x44-0x4B (caldata[4..7]): > + * caldata[4] caldata[5] caldata[6] caldata[7] > + * 0 12 16 24 32 36 48 64 > + * +---------------+---------------+---------------+---------------+ > + * | ths1_2 | ths1_3 | ths0 | | + > + * +---------------+---------------+---------------+---------------+ > + */ > +static int sun55i_a523_ths_calibrate(struct ths_device *tmdev, > + u16 *caldata, int callen) > +{ > + struct device *dev =3D tmdev->dev; > + int i, ft_temp; > + > + if (!caldata[1]) > + return -EINVAL; > + > + ft_temp =3D (((caldata[2] << 8) | (caldata[1] >> 8)) & FT_TEMP_MASK) * = 100; [Severity: Medium] Should this check ft_temp instead of caldata[1]? Per the layout comment above, caldata[1] covers bits 16..31, combining unrelated eFuse byte 0x3a with only the low 8 bits of the 12-bit factory temperature field (bits 24..35). When byte 0x3a is 0, a valid 25.6 C (0x100) factory calibration has caldata[1] =3D=3D 0 and is rejected, silent= ly leaving all sensors uncalibrated at default 0x800. Conversely, on an unprogrammed eFuse where byte 0x3a is non-zero, caldata[1] is non-zero and calibration proceeds with ft_temp =3D=3D 0. Computing ft_temp first and checking if (!ft_temp) avoids both cases. [ ... ] > + sensor_temp =3D tmdev->chip->calc_temp(tmdev, i, sensor_reg); > + > + /* > + * Calibration data is CALIBRATE_DEFAULT - (calculated > + * temperature from sensor reading at factory temperature > + * minus actual factory temperature) * X (scale from > + * temperature to register values). > + * > + * The BSP's SUN55IW3_CAL_COM(5000) is applied as ft_deviation > + * in sun8i_ths_get_temp(), after calc_temp(), and therefore > + * intentionally not repeated here. > + */ > + cdata =3D CALIBRATE_DEFAULT - > + ((sensor_temp - ft_temp) / SUN55I_A523_SCALE_BELOW); [Severity: Low] Can this divide by the wrong scale when sensor_reg is below SUN55I_A523_DELIMITER (0x7c8, ~55 C)? sun55i_a523_calc_temp() uses SUN55I_A523_SCALE_ABOVE (65) when reg is below SUN55I_A523_DELIMITER, but this always divides by SUN55I_A523_SCALE_BELOW (74). If factory calibration happens above ~55 C, the computed calibration offset is under-corrected by ~12.2%. > + > + if (cdata & ~TEMP_CALIB_MASK) { [Severity: Medium] Does missing a zero check on sensor_reg allow an unprogrammed sensor slot to bypass the 12-bit range check? If sensor_reg is 0 (for example, on an A523 variant with only 3 calibrated THS1 sensors), sun55i_a523_calc_temp() takes the reg < SUN55I_A523_DELIMITER branch and returns 65 * 2825 =3D 183625 mC. Because cdata then divides by SUN55I_A523_SCALE_BELOW (74), any ft_temp >=3D 32.0 C yields cdata in [0, 4095], passing this check and overwriting the hardware default 0x800 with a near-zero value that shifts readings by ~130-152 C and can trigger thermal shutdown. Checking if (!sensor_reg) and skipping calibration before calling calc_temp() avoids corrupting SUN50I_H6_THS_TEMP_CALIB. [ ... ] > @@ -729,6 +874,8 @@ static const struct of_device_id of_ths_match[] =3D { > { .compatible =3D "allwinner,sun50i-h6-ths", .data =3D &sun50i_h6_ths }, > { .compatible =3D "allwinner,sun20i-d1-ths", .data =3D &sun20i_d1_ths }, > { .compatible =3D "allwinner,sun50i-h616-ths", .data =3D &sun50i_h616_t= hs }, > + { .compatible =3D "allwinner,sun55i-a523-ths0", .data =3D &sun55i_a523_= ths0 }, > + { .compatible =3D "allwinner,sun55i-a523-ths1", .data =3D &sun55i_a523_= ths1 }, > { /* sentinel */ }, > }; [Severity: Low] Now that these two-cell compatibles exercise the multi-cell path added in commit "thermal/drivers/sun8i: get calibration data from two nvmem cells", can sun8i_ths_calibrate() keep the temporary caldata buffer pinned on devres until unbind? drivers/thermal/sun8i_thermal.c:sun8i_ths_calibrate() { ... calcell =3D of_nvmem_cell_get(np, cellname); if (IS_ERR(calcell)) { if (PTR_ERR(calcell) =3D=3D -EPROBE_DEFER) return -EPROBE_DEFER; goto out; } ... devm_kfree(dev, caldata); caldata =3D NULL; out: if (!IS_ERR_OR_NULL(calcell)) nvmem_cell_put(calcell); return ret; } If of_nvmem_cell_get() fails on the second cell with a non-EPROBE_DEFER error (such as -ENOENT on an incomplete DT), it jumps to out with ret =3D= =3D 0, skipping devm_kfree(dev, caldata) while probe succeeds. Moving devm_kfree(dev, caldata) below the out label releases it on all exit paths. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1796378254.gi= t.iuncuim@gmail.com?part=3D4