Devicetree
 help / color / mirror / Atom feed
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 v6 7/7] thermal/drivers: airoha: Add support for AN7583 Thermal Sensor
Date: Thu, 02 Jul 2026 11:04:33 +0000	[thread overview]
Message-ID: <20260702110433.C18AB1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260702094846.17325-8-ansuelsmth@gmail.com>

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

New issues:
- [Medium] The AIROHA_THERMAL_MUX_SENSOR regmap field is defined as 2 bits wide, which will silently truncate valid sensor enum values.
- [Medium] Potential signed integer overflow in temperature calculation.

Pre-existing issues:
- [High] Devm registration order causes a Use-After-Free of the thermal zone if an interrupt fires during driver unbind.
--

Note: The format of this review has been altered to a free-form summary
rather than an inline diff review to comply with automated code recitation
restrictions.

commit 20661087884d15a906fbdeeb53c5ad53bd3cd15e
Author: Christian Marangi <ansuelsmth@gmail.com>
Subject: thermal/drivers: airoha: Add support for AN7583 Thermal Sensor

Summary: This patch adds support for the Airoha AN7583 Thermal driver,
dropping the PTP_THERMAL subsystem, modifying mux logic, and updating
the EN7581 code to account for these changes.

[Severity: High]
This isn't a bug introduced by this patch, but there appears to be a
pre-existing devres registration order issue that could lead to a
use-after-free during driver unbind.

In en7581_thermal_probe(), devm_request_threaded_irq() is called to
request the IRQ early. Later, in airoha_thermal_probe(), the thermal zone is
registered via devm_thermal_of_zone_register() and assigned to priv->tz.

Because devres frees resources in the reverse order of allocation, during
an unbind or module removal, the thermal zone will be unregistered and
freed first, leaving the IRQ still active. If a hardware thermal interrupt
fires in this small window, en7581_thermal_irq() will execute and
dereference priv->tz, which has already been freed.

Should the IRQ registration be moved after the thermal zone registration,
or perhaps use devm_add_action_or_reset() to ensure safe cleanup ordering?

[Severity: Medium]
In an7583_chip_scu_fields, the AIROHA_THERMAL_MUX_SENSOR regmap field is
defined with LSB 2 and MSB 3, making it exactly 2 bits wide.

However, the an7583_thermal_adc_mux enum defines sensor indices that go
up to 6 (e.g., AN7583_CPU_TEMP_SENSOR). While the code currently only
reads sensor 0, if future or modified code attempts to select sensors 5
or 6 as provisioned by the newly added arrays, regmap_field_write() will
silently mask and truncate the value to fit into the 2 bits.

Does the AN7583_MUX_SENSOR register field span more than 2 bits in
hardware, or are the higher sensor indices handled differently?

[Severity: Medium]
In an7583_thermal_get_temp(), is there a risk of a signed integer overflow
during the temperature calculation?

The formula used is:
*temp = (slope * delta_diode * 10) / delta_gain - offset * 10;

Since slope can be up to 8390 (for the CPU sensor), multiplying slope by
delta_diode and 10 results in 83900 * delta_diode. If the ADC values
diverge such that delta_diode exceeds around 25,595, the multiplication
could overflow a 32-bit signed integer before the division by delta_gain
occurs.

Could this be mitigated by casting to s64 or using mul_u32_u32() if the
hardware ADC resolution allows for such large delta values?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260702094846.17325-1-ansuelsmth@gmail.com?part=7

      reply	other threads:[~2026-07-02 11:04 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-02  9:48 [PATCH v6 0/7] thermal/drivers: airoha: Add support for AN7583 Christian Marangi
2026-07-02  9:48 ` [PATCH v6 1/7] thermal/drivers: airoha: fix copy paste error on clamp_t low temp Christian Marangi
2026-07-02 10:00   ` sashiko-bot
2026-07-02  9:48 ` [PATCH v6 2/7] thermal/drivers: airoha: fix copy paste error for sen internal Christian Marangi
2026-07-02 10:07   ` sashiko-bot
2026-07-02  9:48 ` [PATCH v6 3/7] thermal/drivers: airoha: Convert to regmap API Christian Marangi
2026-07-02 10:16   ` sashiko-bot
2026-07-02  9:48 ` [PATCH v6 4/7] thermal/drivers: airoha: Generalize probe function Christian Marangi
2026-07-02 10:35   ` sashiko-bot
2026-07-02  9:48 ` [PATCH v6 5/7] thermal/drivers: airoha: Generalize get_thermal_ADC and set_mux function Christian Marangi
2026-07-02  9:48 ` [PATCH v6 6/7] dt-bindings: arm: airoha: Add the chip-scu node for AN7583 SoC Christian Marangi
2026-07-02 10:48   ` sashiko-bot
2026-07-02  9:48 ` [PATCH v6 7/7] thermal/drivers: airoha: Add support for AN7583 Thermal Sensor Christian Marangi
2026-07-02 11:04   ` 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=20260702110433.C18AB1F00A3A@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