From: sashiko-bot@kernel.org
To: "Binbin Zhou" <zhoubinbin@loongson.cn>
Cc: devicetree@vger.kernel.org, conor+dt@kernel.org, robh@kernel.org
Subject: Re: [PATCH v7 5/8] thermal/drivers/loongson2: Use bitfields and per-SoC thermal ops
Date: Fri, 09 Oct 2026 03:09:09 +0000 [thread overview]
Message-ID: <sashiko-outbox-164751@kernel.org> (raw)
In-Reply-To: <1375bd12403bffc496261953772a45833f9b5a3e.1791512067.git.zhoubinbin@loongson.cn>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] thermal: loongson2: API misuse of FIELD_PREP triggers potential BUILD_BUG_ON
--
commit 9fa005fd4a6e6873cf9a1897453c930665ef1a63
Author: Binbin Zhou <zhoubinbin@loongson.cn>
thermal/drivers/loongson2: Use bitfields and per-SoC thermal ops
This commit replaces open-coded masks and shifts with GENMASK() and FIELD_*
helpers. It also separates the temperature read and thermal zone ops into
SoC-specific variants to prepare for further expansion.
> diff --git a/drivers/thermal/loongson2_thermal.c b/drivers/thermal/loongson2_thermal.c
> index 94259d88da8a0..02f7545eaac1b 100644
> --- a/drivers/thermal/loongson2_thermal.c
> +++ b/drivers/thermal/loongson2_thermal.c
[ ... ]
> @@ -121,17 +135,18 @@ static void ls2k2000_thermal_set_trips_regs(struct loongson2_thermal_data *data,
> int temp, bool low, bool enable)
> {
> unsigned int sel = data->chip_data->thermal_sensor_sel;
> int hi_reg, ctrl_reg, val, gate;
>
> - gate = (temp + 311) * 0x4000 / 820;
> + gate = (temp + LS2K2000_TEMP_OFFSET) * LS2K2000_TEMP_DIV / LS2K2000_TEMP_MUL;
>
> /* Low byte of the gate value goes to the control register */
> ctrl_reg = low ? LOONGSON2_THSENS_CTRL_LOW_REG : LOONGSON2_THSENS_CTRL_HI_REG;
> - val = gate & 0xff;
> - val |= enable ? 0x100 : 0;
> - val |= sel << 10;
> + val = FIELD_PREP(LOONGSON2_THSENS_CTRL_GATE_MASK, gate) |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[Severity: Low]
Could this FIELD_PREP() macro usage break the build? It appears to pass a
16-bit value (gate) into an 8-bit mask (LOONGSON2_THSENS_CTRL_GATE_MASK
which is defined as GENMASK(7, 0)).
The FIELD_PREP() macro strictly expects the value to fit inside the mask
boundary. For ls2k2000, the calculated gate value is a 16-bit integer (for
example, at 0 degrees Celsius, it calculates to 6213).
If the compiler performs speculative devirtualization or constant propagation
(such as during LTO across loongson2_thermal_probe() calling
loongson2_thermal_set_trip_temp(data, 0, 0, false)), __builtin_constant_p(gate)
would evaluate to true. This can trigger the BUILD_BUG_ON_MSG("value too large
for the field") in bitfield.h and fail compilation.
> + FIELD_PREP(LOONGSON2_THSENS_CTRL_INTEN, enable) |
> + FIELD_PREP(LOONGSON2_THSENS_CTRL_SEL_MASK, sel);
> writew(val, data->ctrl_reg + ctrl_reg + sel * 2);
>
> /* High byte of the gate value goes to the low byte of the HI_GATE register */
> hi_reg = low ? LS2K2000_THSENS_HI_GATE_LOW_REG : LS2K2000_THSENS_HI_GATE_HI_REG;
> - val = (gate >> 8) & 0xff;
> + val = FIELD_GET(GENMASK(15, 8), gate);
> writeb(val, data->ctrl_reg + hi_reg + sel);
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1791512067.git.zhoubinbin@loongson.cn?part=5
next prev parent reply other threads:[~2026-10-09 3:09 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 2:57 [PATCH v7 0/8] thermal/drivers/loongson2: Fix trip programming and add Loongson-2K0300 support Binbin Zhou
2026-10-09 2:57 ` [PATCH v7 1/8] thermal/drivers/loongson2: Fix negative temperature conversion in set_trips Binbin Zhou
2026-10-09 2:57 ` [PATCH v7 2/8] thermal/drivers/loongson2: Fix clamp() usage for thermal trip points Binbin Zhou
2026-10-09 2:58 ` [PATCH v7 3/8] thermal/drivers/loongson2: Fix Loongson-2K2000 trip point programming Binbin Zhou
2026-10-09 2:58 ` [PATCH v7 4/8] thermal/drivers/loongson2: Simplify thermal sensor registration Binbin Zhou
2026-10-09 2:58 ` [PATCH v7 5/8] thermal/drivers/loongson2: Use bitfields and per-SoC thermal ops Binbin Zhou
2026-10-09 3:09 ` sashiko-bot [this message]
2026-10-09 2:58 ` [PATCH v7 6/8] thermal/drivers/loongson2: Move per-SoC ops into chip data Binbin Zhou
2026-10-09 2:58 ` [PATCH v7 7/8] dt-bindings: thermal: loongson,ls2k-thermal: Add compatible for Loongson-2K0300 Binbin Zhou
2026-10-09 2:58 ` [PATCH v7 8/8] thermal/drivers/loongson2: Add Loongson-2K0300 support Binbin Zhou
2026-10-09 3:07 ` 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=sashiko-outbox-164751@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