Re: [PATCH v5] thermal: rcar_gen3: check for sensors before reading the fuses

From: Niklas Söderlund

Date: Thu Nov 26 2026 - 06:58:17 EST


Hi Yaohan,

Thanks for your work and persistence.

On 2026-11-26 09:36:26 +0800, Yaohan Li wrote:
> rcar_gen3_thermal_read_fuses() reads the THSCP register through the
> first TSC. If the device has no TSC resources, priv->tscs[0] is NULL,
> and the read causes a NULL pointer dereference.
>
> Before hardware calibration support was added, leaving the
> !priv->num_tscs check at the end of probe was safe because TSCs were
> only accessed inside loops over the discovered sensors.
> rcar_gen3_thermal_read_fuses() introduced an unconditional access to
> priv->tscs[0] before that check.
>
> Move the existing zero-TSC check right after discovering the sensors,
> before reading the calibration fuses.
>
> Fixes: c3131bd5586d ("thermal: rcar_gen3_thermal: Read calibration from hardware")
> Signed-off-by: Yaohan Li <shunsheng1218@xxxxxxxxx>

Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@xxxxxxxxxxxx>

> ---
> Changes since v4 (split out from the withdrawn 3-patch series):
> - Split out as a standalone single patch per Niklas Söderlund's feedback
> (<20261125060429.GK3898744@xxxxxxxxxxxx>,
> <20261125113106.GM3898744@xxxxxxxxxxxx>).
> - Rewrote the commit message and added the Fixes tag per Niklas's review.
> - No functional code change relative to v4 patch 1/3.
>
> Testing:
> Compile tested only (no Renesas R-Car Gen3 hardware): arm64
> (aarch64-linux-gnu-gcc, CONFIG_ARCH_RENESAS=y, CONFIG_RCAR_GEN3_THERMAL=y,
> W=1, 0 warnings) against 666539eecdf4.
>
> AI assistance:
> AI tools assisted with initial static analysis and commit/patch drafting;
> the author manually reviewed the probe/remove paths, verified commit
> c3131bd5586d, ran the arm64 compile check, and takes full responsibility
> for the patch.
>
> drivers/thermal/renesas/rcar_gen3_thermal.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/thermal/renesas/rcar_gen3_thermal.c b/drivers/thermal/renesas/rcar_gen3_thermal.c
> index 9c64cbc2ee670..a96f02d4a8adf 100644
> --- a/drivers/thermal/renesas/rcar_gen3_thermal.c
> +++ b/drivers/thermal/renesas/rcar_gen3_thermal.c
> @@ -557,6 +557,10 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
> }
>
> priv->num_tscs = i;
> + if (!priv->num_tscs) {
> + ret = -ENODEV;
> + goto error_unregister;
> + }
>
> if (!rcar_gen3_thermal_read_fuses(priv))
> dev_info(dev, "No calibration values fused, fallback to driver values\n");
> @@ -588,11 +592,6 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
> dev_info(dev, "Sensor %u: Loaded\n", i);
> }
>
> - if (!priv->num_tscs) {
> - ret = -ENODEV;
> - goto error_unregister;
> - }
> -
> return 0;
>
> error_unregister:
> --
> 2.34.1
>

--
Kind Regards,
Niklas Söderlund