From: sashiko-bot@kernel.org
To: "Binbin Zhou" <zhoubinbin@loongson.cn>
Cc: conor+dt@kernel.org, mfd@lists.linux.dev, robh@kernel.org,
lee@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v4 1/5] thermal/drivers/loongson2: Correct thermal sensor registration loop
Date: Tue, 04 Aug 2026 13:01:45 +0000 [thread overview]
Message-ID: <20260804130146.548AE1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <1c0f32f83a43a11a35e151fe97e9b5d4b21ea459.1785829933.git.zhoubinbin@loongson.cn>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] The driver allows registering any sensor ID from 0 to 3 but unconditionally configures hardware registers for sensor 0.
- [High] The device's hardware interrupt is left enabled when probe fails or the driver is unbound.
- [High] Potential NULL pointer dereference if `device_get_match_data()` returns NULL.
--
--- Patch [1]: [PATCH v4 1/5] thermal/drivers/loongson2: Correct thermal sensor registration loop ---
commit 04ee4726d4d6013e77a52a26bf79466c2069029a
Author: Binbin Zhou <zhoubinbin@loongson.cn>
thermal/drivers/loongson2: Correct thermal sensor registration loop
This commit fixes the registration loop in loongson2_thermal_probe() by
correctly handling -ENODEV and only aborting on fatal errors. It also
ensures at least one thermal zone is registered before proceeding.
> diff --git a/drivers/thermal/loongson2_thermal.c b/drivers/thermal/loongson2_thermal.c
> index ea4dd2fb1f473..5f47fa51fb907 100644
> --- a/drivers/thermal/loongson2_thermal.c
> +++ b/drivers/thermal/loongson2_thermal.c
> @@ -161,16 +161,18 @@ static int loongson2_thermal_probe(struct platform_device *pdev)
[Severity: High]
This is a pre-existing issue, but if device_get_match_data() returns NULL
(for example, via manual sysfs binding), can this cause a NULL pointer
dereference earlier in this function?
drivers/thermal/loongson2_thermal.c:loongson2_thermal_probe() {
...
data->chip_data = device_get_match_data(dev);
...
if (data->chip_data->flags & LS2K2000_THSENS_OUT_FLAG) {
...
}
>
> for (i = 0; i <= LOONGSON2_MAX_SENSOR_SEL_NUM; i++) {
> tzd = devm_thermal_of_zone_register(dev, i, data, thermal_ops);
[Severity: High]
This isn't a bug introduced by this patch, but does this leave the hardware
interrupt enabled if probe fails later or the driver is unbound?
During devm_thermal_of_zone_register(), the thermal core registers the zone
and invokes tz->ops->set_trips(). This calls
loongson2_thermal_set(..., enable=true), which enables the hardware interrupt.
However, there appears to be no corresponding remove function in
loongson2_thermal_driver, nor a devm_add_action_or_reset() callback to
disable the interrupt if devm_request_threaded_irq() fails or the driver is
unbound.
[Severity: High]
This is also a pre-existing issue, but if the device tree specifies a thermal
zone for a sensor ID other than 0, will the hardware configuration match the
intended sensor?
The probe loop registers the zone for sensor index i and breaks, but
loongson2_set_ctrl_regs() uses a statically defined thermal_sensor_sel:
drivers/thermal/loongson2_thermal.c:loongson2_set_ctrl_regs() {
int reg_off = data->chip_data->thermal_sensor_sel * 2;
...
}
It seems this calculates the register offset ignoring the actually registered
sensor ID, potentially resulting in reading from and writing limits to the
hardware registers of sensor 0 instead.
> if (!IS_ERR(tzd))
> break;
>
> - if (PTR_ERR(tzd) != -ENODEV)
> + if (PTR_ERR(tzd) == -ENODEV)
> continue;
>
> - return dev_err_probe(dev, PTR_ERR(tzd), "failed to register");
> + return dev_err_probe(dev, PTR_ERR(tzd), "failed to register sensor %d\n", i);
> }
>
> + if (IS_ERR(tzd))
> + return dev_err_probe(dev, -ENODEV, "No thermal sensor registered\n");
> +
> ret = devm_request_threaded_irq(dev, irq, NULL, loongson2_thermal_irq_thread,
> IRQF_ONESHOT, "loongson2_thermal", tzd);
> if (ret < 0)
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1785829933.git.zhoubinbin@loongson.cn?part=1
next prev parent reply other threads:[~2026-08-04 13:01 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-04 12:40 [PATCH v4 0/5] thermal: loongson2: Add support for Loongson-2K0300 SoC Binbin Zhou
2026-08-04 12:42 ` [PATCH v4 1/5] thermal/drivers/loongson2: Correct thermal sensor registration loop Binbin Zhou
2026-08-04 13:01 ` sashiko-bot [this message]
2026-08-04 12:43 ` [PATCH v4 2/5] thermal/drivers/loongson2: Move thermal_ops to chip_data for SoC scalability Binbin Zhou
2026-08-04 12:55 ` sashiko-bot
2026-08-04 12:43 ` [PATCH v4 3/5] dt-bindings: mfd: syscon: Allow syscon compatible for Loongson-2K0300 chip id Binbin Zhou
2026-08-04 12:46 ` sashiko-bot
2026-08-05 6:59 ` Krzysztof Kozlowski
2026-08-04 12:43 ` [PATCH v4 4/5] dt-bindings: thermal: loongson,ls2k-thermal: Add compatible for Loongson-2K0300 Binbin Zhou
2026-08-04 12:49 ` sashiko-bot
2026-08-04 12:43 ` [PATCH v4 5/5] thermal/drivers/loongson2: Add support " Binbin Zhou
2026-08-04 12:59 ` sashiko-bot
2026-08-05 9:43 ` [PATCH v4 0/5] thermal: loongson2: Add support for Loongson-2K0300 SoC Huacai Chen
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=20260804130146.548AE1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=lee@kernel.org \
--cc=mfd@lists.linux.dev \
--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