All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Binbin Zhou" <zhoubinbin@loongson.cn>
Cc: lee@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org,
	robh@kernel.org, mfd@lists.linux.dev
Subject: Re: [PATCH v2 1/4] thermal/drivers/loongson2: Correct thermal sensor registration loop
Date: Tue, 21 Jul 2026 12:36:28 +0000	[thread overview]
Message-ID: <20260721123628.C988B1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <38116cb29537aecc7ae88a6e4c2916f1a7966c4f.1784619512.git.zhoubinbin@loongson.cn>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

Pre-existing issues:
- [High] NULL Pointer Dereference via sysfs bind
- [Medium] Hardware Configuration Mismatch
- [Medium] Missing Teardown / Resource Leak
--

--- Patch [1]: [PATCH v2 1/4] thermal/drivers/loongson2: Correct thermal sensor registration loop ---
commit 381cd9ed04934716b53c8748d5c522210d6b54ff
Author: Binbin Zhou <zhoubinbin@loongson.cn>

thermal/drivers/loongson2: Correct thermal sensor registration loop

The registration loop in loongson2_thermal_probe() incorrectly uses
dev_err_probe() when the sensor is not present (-ENODEV). Fix this by
correctly handling -ENODEV and only returning on other errors.

Closes: https://sashiko.dev/#/patchset/cover.1783670011.git.zhoubinbin@loongson.cn?part=2

> diff --git a/drivers/thermal/loongson2_thermal.c b/drivers/thermal/loongson2_thermal.c
> index ea4dd2fb1f473..d7d221c3136d4 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 does device_get_match_data() return NULL
when binding the driver via sysfs to a platform device that lacks OF match
data?

In loongson2_thermal_probe(), data->chip_data is assigned from
device_get_match_data(dev) and then immediately dereferenced:

    data->chip_data = device_get_match_data(dev);
    ...
    if (data->chip_data->flags & LS2K2000_THSENS_OUT_FLAG) {

Could this cause a NULL pointer dereference crash if bound by name via sysfs?

>  
>  	for (i = 0; i <= LOONGSON2_MAX_SENSOR_SEL_NUM; i++) {
>  		tzd = devm_thermal_of_zone_register(dev, i, data, thermal_ops);
> -
>  		if (!IS_ERR(tzd))
>  			break;

[Severity: Medium]
This is a pre-existing issue, but does this code properly save the
discovered sensor index?

If the device tree specifies a non-zero sensor index, the actual sensor
index is discovered here but then discarded instead of being saved to
the instance data.

Later in loongson2_set_ctrl_regs(), the hardware register offset is
calculated using the hardcoded static match data rather than the index
actually discovered:

    int reg_off  = data->chip_data->thermal_sensor_sel * 2;

Could this cause the driver to report temperatures or configure thresholds
for the wrong hardware sensor (sensor 0) if the device tree specifies a
different index?

[ ... ]

> +	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);

[Severity: Medium]
This is a pre-existing issue, but is there a missing teardown for the
hardware interrupt state?

The probe function relies solely on devres for cleanup, but it does not
register a devm action to revert the hardware interrupt state initialized
by the thermal core:

    loongson2_thermal_set(data, 0, 0, false);

If the driver is manually unbound via sysfs or the module is unloaded, could
this leave the device actively asserting its interrupt line?

>  	if (ret < 0)

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

  reply	other threads:[~2026-07-21 12:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-21 12:24 [PATCH v2 0/4] thermal: loongson2: Add support for Loongson-2K0300 SoC Binbin Zhou
2026-07-21 12:24 ` [PATCH v2 1/4] thermal/drivers/loongson2: Correct thermal sensor registration loop Binbin Zhou
2026-07-21 12:36   ` sashiko-bot [this message]
2026-07-21 12:24 ` [PATCH v2 2/4] dt-bindings: mfd: syscon: Allow syscon compatible for Loongson-2K0300 chip id Binbin Zhou
2026-07-21 12:30   ` sashiko-bot
2026-07-21 15:39   ` Conor Dooley
2026-07-21 12:26 ` [PATCH v2 3/4] dt-bindings: thermal: loongson,ls2k-thermal: Add compatible for Loongson-2K0300 Binbin Zhou
2026-07-21 12:35   ` sashiko-bot
2026-07-21 15:39   ` Conor Dooley
2026-07-21 12:26 ` [PATCH v2 4/4] thermal/drivers/loongson2: Add support " Binbin Zhou
2026-07-21 12:33   ` sashiko-bot

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=20260721123628.C988B1F000E9@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.