From: sashiko-bot@kernel.org
To: "Luca Leonardo Scorcia" <l.scorcia@gmail.com>
Cc: mfd@lists.linux.dev, dmitry.torokhov@gmail.com,
conor+dt@kernel.org, lee@kernel.org, robh@kernel.org,
devicetree@vger.kernel.org, linux-input@vger.kernel.org
Subject: Re: [PATCH v10 8/9] regulator: Add MediaTek MT6392 regulator
Date: Wed, 02 Sep 2026 20:58:29 +0000 [thread overview]
Message-ID: <20260902205830.090891F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260902193351.185771-9-l.scorcia@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The driver mutates the statically defined global array `mt6392_regulators` during probe, causing state corruption and race conditions for multi-instance deployments or re-probing.
--
commit b458a23ed7fdbe7db2ebc29e150ed87ba4a12dbe
Author: Fabien Parent <parent.f@gmail.com>
regulator: Add MediaTek MT6392 regulator
This commit introduces support for the MediaTek MT6392 PMIC regulator.
The PMIC connects as a SPI slave wrapped inside PWRAP and is found on
MT8167 and MT8516 SoC based boards.
> diff --git a/drivers/regulator/mt6392-regulator.c b/drivers/regulator/mt6392-regulator.c
> new file mode 100644
> --- /dev/null
> +++ b/drivers/regulator/mt6392-regulator.c
[ ... ]
> +// Buck regulators can be in Register mode or Normal mode.
> +// Each mode uses a different register to set the desired voltage.
> +static int mt6392_set_buck_vsel_reg(struct platform_device *pdev)
> +{
> + struct mt6397_chip *mt6392 = dev_get_drvdata(pdev->dev.parent);
> + int i;
> + u32 regval;
> +
> + for (i = 0; i < MT6392_MAX_REGULATOR; i++) {
> + if (mt6392_regulators[i].vselctrl_reg) {
> + // Read the vselctrl_reg register
> + if (regmap_read(mt6392->regmap,
> + mt6392_regulators[i].vselctrl_reg,
> + ®val) < 0) {
> + dev_err(&pdev->dev,
> + "Failed to read buck ctrl\n");
> + return -EIO;
> + }
> +
> + // vselctrl_reg[vselctrl_mask] defines the mode
> + if (regval & mt6392_regulators[i].vselctrl_mask) {
> + // Regulator in Normal mode
> + mt6392_regulators[i].desc.vsel_reg =
> + mt6392_regulators[i].vsel_normal_mode_reg;
> + mt6392_regulators[i].desc.vsel_mask =
> + mt6392_regulators[i].vsel_normal_mode_mask;
[Severity: High]
Does this code mutate the shared global mt6392_regulators array based on
per-instance hardware state? If multiple instances of this PMIC are present,
or during unbind/re-bind cycles, won't this corrupt the state for other
instances since the regulator core expects regulator_desc to be static and
independent across deployments?
> + } else {
> + // Regulator in Register mode
> + mt6392_regulators[i].desc.vsel_reg =
> + mt6392_regulators[i].vsel_reg_mode_reg;
> + mt6392_regulators[i].desc.vsel_mask =
> + mt6392_regulators[i].vsel_reg_mode_mask;
> + }
> + }
> + }
> +
> + return 0;
> +}
> +
> +static int mt6392_regulator_probe(struct platform_device *pdev)
> +{
> + struct mt6397_chip *mt6392 = dev_get_drvdata(pdev->dev.parent);
> + struct regulator_config config = {};
> + struct regulator_dev *rdev;
> + int i;
> +
> + device_set_of_node_from_dev(&pdev->dev, pdev->dev.parent);
> +
> + // Initialize the bucks' vsel_reg and vsel_mask according to current HW state
> + if (mt6392_set_buck_vsel_reg(pdev))
> + return -EIO;
> +
> + config.dev = mt6392->dev;
> + config.regmap = mt6392->regmap;
> + for (i = 0; i < MT6392_MAX_REGULATOR; i++) {
> + config.driver_data = &mt6392_regulators[i];
> +
> + rdev = devm_regulator_register(&pdev->dev,
> + &mt6392_regulators[i].desc,
> + &config);
[Severity: High]
Because the regulator core stores a pointer to the passed regulator_desc,
will passing the mutated shared descriptor here cause the first PMIC
instance to use the second PMIC's register offsets if a second instance
is probed? Could this result in writing to incorrect registers when changing
voltages?
> + if (IS_ERR(rdev)) {
> + dev_err(&pdev->dev, "failed to register %s\n",
> + mt6392_regulators[i].desc.name);
> + return PTR_ERR(rdev);
> + }
> + }
> +
> + return 0;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260902193351.185771-1-l.scorcia@gmail.com?part=8
next prev parent reply other threads:[~2026-09-02 20:58 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 19:25 [PATCH v10 0/9] Add support for MT6392 PMIC Luca Leonardo Scorcia
2026-09-02 19:25 ` [PATCH v10 1/9] dt-bindings: mfd: mt6397: Add " Luca Leonardo Scorcia
2026-09-02 19:41 ` sashiko-bot
2026-09-03 8:24 ` Krzysztof Kozlowski
2026-09-02 19:25 ` [PATCH v10 2/9] dt-bindings: input: mtk-pmic-keys: Add MT6392 PMIC keys Luca Leonardo Scorcia
2026-09-02 19:50 ` sashiko-bot
2026-09-02 19:25 ` [PATCH v10 3/9] regulator: dt-bindings: Add MediaTek MT6392 PMIC Luca Leonardo Scorcia
2026-09-02 20:00 ` sashiko-bot
2026-09-02 19:25 ` [PATCH v10 4/9] mfd: mt6397: Use MFD_CELL_* to describe sub-devices Luca Leonardo Scorcia
2026-09-02 20:10 ` sashiko-bot
2026-09-02 19:25 ` [PATCH v10 5/9] mfd: mt6397: Add support for MT6392 PMIC Luca Leonardo Scorcia
2026-09-02 20:24 ` sashiko-bot
2026-09-02 19:25 ` [PATCH v10 6/9] input: keyboard: mtk-pmic-keys: Add MT6392 support Luca Leonardo Scorcia
2026-09-02 20:37 ` sashiko-bot
2026-09-02 19:25 ` [PATCH v10 7/9] pinctrl: mediatek: mt6397: Add MediaTek MT6392 Luca Leonardo Scorcia
2026-09-02 20:50 ` sashiko-bot
2026-09-02 19:25 ` [PATCH v10 8/9] regulator: Add MediaTek MT6392 regulator Luca Leonardo Scorcia
2026-09-02 20:58 ` sashiko-bot [this message]
2026-09-02 19:25 ` [PATCH v10 9/9] arm64: dts: mediatek: Add MediaTek MT6392 PMIC dtsi Luca Leonardo Scorcia
2026-09-02 21:05 ` 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=20260902205830.090891F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=l.scorcia@gmail.com \
--cc=lee@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=mfd@lists.linux.dev \
--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