From: sashiko-bot@kernel.org
To: "Christian Marangi" <ansuelsmth@gmail.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v5 3/7] thermal/drivers: airoha: Convert to regmap API
Date: Wed, 20 May 2026 16:48:02 +0000 [thread overview]
Message-ID: <20260520164802.8EF4C1F00894@smtp.kernel.org> (raw)
In-Reply-To: <20260520155525.22239-4-ansuelsmth@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] Simultaneous temperature trip interrupts are dropped instead of being handled.
- [High] The IRQ is requested before the thermal zone is registered, allowing a potential NULL pointer dereference in the IRQ handler.
- [High] Non-atomic read-modify-restore sequence on a shared syscon regmap without external locking.
--
commit 952c01597265eea8ee25e21cc2c92bef3e5ca97e
Author: Christian Marangi <ansuelsmth@gmail.com>
thermal/drivers: airoha: Convert to regmap API
In preparation for support of Airoha AN7583, convert the driver to
regmap API. This is needed as Airoha AN7583 will be based on syscon
regmap.
> diff --git a/drivers/thermal/airoha_thermal.c b/drivers/thermal/airoha_thermal.c
> index 829a7327fc403..b63893a8997a3 100644
> --- a/drivers/thermal/airoha_thermal.c
> +++ b/drivers/thermal/airoha_thermal.c
[ ... ]
> @@ -300,9 +300,9 @@ static irqreturn_t airoha_thermal_irq(int irq, void *data)
> struct airoha_thermal_priv *priv = data;
> enum thermal_notify_event event;
> bool update = false;
> - u32 status;
> + u32 status = 0;
>
> - status = readl(priv->base + EN7581_TEMPMONINTSTS);
> + regmap_read(priv->map, EN7581_TEMPMONINTSTS, &status);
> switch (status & (EN7581_HOFSINTSTS0 | EN7581_LOFSINTSTS0)) {
> case EN7581_HOFSINTSTS0:
> event = THERMAL_TRIP_VIOLATED;
[Severity: High]
This is a pre-existing issue, but what happens if both high and low
temperature interrupt status bits are set simultaneously?
If both EN7581_HOFSINTSTS0 and EN7581_LOFSINTSTS0 are set, the bitwise AND
will yield a combination of both bits. Since there are only case statements
for the individual bits, the code will fall through to the default case.
The status will be written back to clear the interrupts, but the events
will be silently dropped without notifying the thermal core.
Would it be safer to replace this switch statement with independent if
checks for each interrupt flag?
> @@ -329,18 +329,19 @@ static irqreturn_t airoha_thermal_irq(int irq, void *data)
> static void airoha_thermal_setup_adc_val(struct device *dev,
> struct airoha_thermal_priv *priv)
> {
> - u32 efuse_calib_info, cpu_sensor;
> + u32 efuse_calib_info = 0;
> + u32 cpu_sensor = 0;
>
> /* Setup thermal sensor to ADC mode and setup the mux to DIODE1 */
> airoha_init_thermal_ADC_mode(priv);
[Severity: High]
This isn't a bug introduced by this patch, but is it possible for the
chip_scu regmap sequence to race with other drivers?
Looking at airoha_init_thermal_ADC_mode(), it performs a read-modify-restore
sequence on a shared syscon regmap:
static void airoha_init_thermal_ADC_mode(struct airoha_thermal_priv *priv)
{
...
regmap_read(priv->chip_scu, EN7581_PLLRG_PROTECT, &pllrg);
regmap_write(priv->chip_scu, EN7581_PLLRG_PROTECT,
EN7581_SCU_THERMAL_PROTECT_KEY);
...
regmap_write(priv->chip_scu, EN7581_PLLRG_PROTECT, pllrg);
}
Because the internal regmap lock is only held during individual register
accesses, could another driver (like a clock or pinctrl driver) accessing
the SCU concurrently cause the protect key to be incorrectly overwritten or
prematurely removed?
[ ... ]
> @@ -462,8 +475,8 @@ static int airoha_thermal_probe(struct platform_device *pdev)
> platform_set_drvdata(pdev, priv);
>
> /* Enable LOW and HIGH interrupt */
> - writel(EN7581_HOFSINTEN0 | EN7581_LOFSINTEN0,
> - priv->base + EN7581_TEMPMONINT);
> + regmap_write(priv->map, EN7581_TEMPMONINT,
> + EN7581_HOFSINTEN0 | EN7581_LOFSINTEN0);
>
> return 0;
> }
[Severity: High]
This is a pre-existing issue, but could we encounter a NULL pointer
dereference if an interrupt fires before the thermal zone is registered?
Looking earlier in airoha_thermal_probe():
ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
airoha_thermal_irq, IRQF_ONESHOT,
pdev->name, priv);
...
priv->tz = devm_thermal_of_zone_register(dev, 0, priv, &thdev_ops);
If an interrupt is already pending (for example, left active by the
bootloader) when the IRQ is requested, the handler will run immediately.
If an event is detected, airoha_thermal_irq() will call
thermal_zone_device_update(priv->tz, event). Since priv->tz is still NULL
at that point, it will crash.
Should the IRQ be requested after the thermal zone registration is complete?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260520155525.22239-1-ansuelsmth@gmail.com?part=3
next prev parent reply other threads:[~2026-05-20 16:48 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-20 15:55 [PATCH v5 0/7] thermal/drivers: airoha: Add support for AN7583 Christian Marangi
2026-05-20 15:55 ` [PATCH v5 1/7] thermal/drivers: airoha: fix copy paste error on clamp_t low temp Christian Marangi
2026-05-20 16:11 ` sashiko-bot
2026-05-20 15:55 ` [PATCH v5 2/7] thermal/drivers: airoha: fix copy paste error for sen internal Christian Marangi
2026-05-20 15:55 ` [PATCH v5 3/7] thermal/drivers: airoha: Convert to regmap API Christian Marangi
2026-05-20 16:48 ` sashiko-bot [this message]
2026-05-20 15:55 ` [PATCH v5 4/7] thermal/drivers: airoha: Generalize probe function Christian Marangi
2026-05-20 17:04 ` sashiko-bot
2026-05-20 15:55 ` [PATCH v5 5/7] thermal/drivers: airoha: Generalize get_thermal_ADC and set_mux function Christian Marangi
2026-05-20 17:24 ` sashiko-bot
2026-05-20 15:55 ` [PATCH v5 6/7] dt-bindings: arm: airoha: Add the chip-scu node for AN7583 SoC Christian Marangi
2026-05-20 17:28 ` sashiko-bot
2026-05-20 15:55 ` [PATCH v5 7/7] thermal/drivers: airoha: Add support for AN7583 Thermal Sensor Christian Marangi
2026-05-20 18:04 ` 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=20260520164802.8EF4C1F00894@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=ansuelsmth@gmail.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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