Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Binbin Zhou" <zhoubinbin@loongson.cn>
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org, robh@kernel.org
Subject: Re: [PATCH v6 7/7] thermal/drivers/loongson2: Add Loongson-2K0300 support
Date: Mon, 28 Sep 2026 04:53:46 +0000	[thread overview]
Message-ID: <20260928045347.0B8D41F000FF@smtp.kernel.org> (raw)
In-Reply-To: <549b204c1621341edc5b4aa4f81e164ec5ce7fed.1790561983.git.zhoubinbin@loongson.cn>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] thermal/loongson2: hardware race in ADC initialization triggers false fallback
- [Medium] thermal/loongson2: missing sign bit check for ID0 calibration data
--

commit 0cea5de8d422086175b271d663470bc3da490430
Author: Binbin Zhou <zhoubinbin@loongson.cn>

thermal/drivers/loongson2: Add Loongson-2K0300 support
    
This commit adds support for the Loongson-2K0300 thermal sensor by reading
calibration offsets from syscon, initializing the sensor, and calculating
the temperature. It also includes logic to detect early fuse revisions and
fall back to an older calibration formula if the initial reading is out of
bounds.

> diff --git a/drivers/thermal/loongson2_thermal.c b/drivers/thermal/loongson2_thermal.c
> index 17aa1d80a2e67..a53d70b824f32 100644
> --- a/drivers/thermal/loongson2_thermal.c
> +++ b/drivers/thermal/loongson2_thermal.c
[ ... ]
> +static int ls2k0300_thermal_read_calib(struct loongson2_thermal_data *data)
> +{
> +	u32 chip_id0, chip_id1;
> +	int calib_data, calib_offset, ret;
> +
> +	ret = regmap_read(data->regmap_cfg, LS2K0300_CHIP_ID0, &chip_id0);
> +	if (ret)
> +		return ret;
> +
> +	ret = regmap_read(data->regmap_cfg, LS2K0300_CHIP_ID1, &chip_id1);
> +	if (ret)
> +		return ret;
> +
> +	if (chip_id0 & LS2K0300_EXTERN_ID) {
> +		calib_data = FIELD_GET(LS2K0300_ID1_VAL_MASK, chip_id1);
> +		calib_offset = FIELD_GET(LS2K0300_COMP_VAL_MASK, calib_data);
> +		if (calib_data & LS2K0300_COMP_SIGN_BIT)
> +			calib_offset = -calib_offset;
> +	} else {
> +		calib_data = FIELD_GET(LS2K0300_ID0_VAL_MASK, chip_id0);
> +		calib_offset = FIELD_GET(LS2K0300_COMP_VAL_MASK, calib_data);
> +	}

[Severity: Medium]
Is there a missing sign bit check for the chip_id0 branch?

The chip_id1 branch explicitly checks LS2K0300_COMP_SIGN_BIT to negate the
offset, but the chip_id0 branch does not. Furthermore, the extracted 
LS2K0300_ID0_VAL_MASK is 12 bits, but it is masked against 
LS2K0300_COMP_VAL_MASK which is 15 bits. 

Could negative calibration offsets provided via chip_id0 be incorrectly 
treated as large positive offsets, leading to completely wrong temperature 
readings?

> +
> +	data->calib_offset = calib_offset;
> +	return 0;
> +}
> +
> +static int ls2k0300_thermal_init_extend_resource(struct platform_device *pdev,
> +						 struct loongson2_thermal_data *data)
> +{
> +	struct device *dev = &pdev->dev;
> +	int ret;
> +
> +	data->regmap_cfg =
> +		syscon_regmap_lookup_by_phandle(dev->of_node, "loongson,chipid");
> +	if (IS_ERR(data->regmap_cfg))
> +		return PTR_ERR(data->regmap_cfg);
> +
> +	ret = ls2k0300_thermal_read_calib(data);
> +	if (ret)
> +		return dev_err_probe(dev, ret, "failed to read calibration data\n");
> +
> +	writel(LS2K0300_THSENS_INIT_MASK, data->ctrl_reg + LS2K0300_THSENS_CFG_REG);
> +
> +	ls2k0300_thermal_detect_old_fuse(dev, data);

[Severity: Medium]
Could this trigger a false fallback to the old fuse formula due to a hardware
initialization race?

Here, the sensor is initialized by writing LS2K0300_THSENS_INIT_MASK to the
configuration register. Immediately after, ls2k0300_thermal_detect_old_fuse() 
is called, which reads the ADC value via ls2k0300_adc_to_temp_mc() without any
readiness poll or sleep delay.

If the hardware ADC requires time to complete its first conversion after being
configured, this immediate read might yield an artificially low or invalid
temperature. This would cause the out-of-bounds check in 
ls2k0300_thermal_detect_old_fuse() to fail, permanently falling back to the 
incorrect old fuse formula.

> +
> +	return 0;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1790561983.git.zhoubinbin@loongson.cn?part=7

      reply	other threads:[~2026-09-28  4:53 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-28  4:44 [PATCH v6 0/7] thermal: loongson2: Add support for Loongson-2K0300 SoC Binbin Zhou
2026-09-28  4:44 ` [PATCH v6 1/7] thermal/drivers/loongson2: Correct thermal sensor registration loop Binbin Zhou
2026-09-28  7:15   ` Daniel Lezcano
2026-09-28  8:17     ` Binbin Zhou
2026-09-28 13:23       ` Daniel Lezcano
2026-09-29  3:06         ` Binbin Zhou
2026-09-29  5:46           ` Daniel Lezcano
2026-09-29  8:23             ` Binbin Zhou
2026-09-29  8:43               ` Daniel Lezcano
2026-09-28  4:44 ` [PATCH v6 2/7] thermal/drivers/loongson2: Fix clamp() usage for thermal trip points Binbin Zhou
2026-09-28  4:44 ` [PATCH v6 3/7] thermal/drivers/loongson2: Fix Loongson-2K2000 trip point programming Binbin Zhou
2026-09-28  4:54   ` sashiko-bot
2026-09-28  4:44 ` [PATCH v6 4/7] thermal/drivers/loongson2: Use bitfields and per-SoC thermal ops Binbin Zhou
2026-09-28  4:52   ` sashiko-bot
2026-09-28  4:44 ` [PATCH v6 5/7] thermal/drivers/loongson2: Move per-SoC ops into chip data Binbin Zhou
2026-09-28  4:44 ` [PATCH v6 6/7] dt-bindings: thermal: loongson,ls2k-thermal: Add compatible for Loongson-2K0300 Binbin Zhou
2026-09-28  4:44 ` [PATCH v6 7/7] thermal/drivers/loongson2: Add Loongson-2K0300 support Binbin Zhou
2026-09-28  4:53   ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260928045347.0B8D41F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=zhoubinbin@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox