From: sashiko-bot@kernel.org
To: "Luca Leonardo Scorcia" <l.scorcia@gmail.com>
Cc: conor+dt@kernel.org, dmitry.torokhov@gmail.com,
mfd@lists.linux.dev, lee@kernel.org, devicetree@vger.kernel.org,
linux-input@vger.kernel.org, robh@kernel.org
Subject: Re: [PATCH v9 5/9] mfd: mt6397: Add support for MT6392 PMIC
Date: Thu, 20 Aug 2026 12:49:29 +0000 [thread overview]
Message-ID: <20260820124929.78F0C1F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260820122242.120039-6-l.scorcia@gmail.com>
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
New issues:
- [Low] Driver-specific header files for MT6392 are placed in the global `include/linux/mfd/` directory.
Pre-existing issues:
- [High] Missing resource teardown for the PM notifier and IRQ domain on device unbind and probe error paths, leading to memory leaks and a Use-After-Free crash.
- [High] The IRQ domain is created with a hardcoded maximum size of 32, truncating the IRQ space for chips like MT6328 that require up to 47 IRQs.
- [High] Race condition on probe failure between irq_domain removal and active threaded IRQ handler.
- [High] The PM notifier modifies hardware IRQ registers without holding the irqlock mutex, potentially breaking system wakeup functionality.
--
--- Patch [5]: [PATCH v9 5/9] mfd: mt6397: Add support for MT6392 PMIC ---
commit b2217cbb3b951021ff7eb4a8b7e1f3c678b7c4bc
Author: Fabien Parent <parent.f@gmail.com>
mfd: mt6397: Add support for MT6392 PMIC
This commit modifies the MT6397 driver to use identifier matching instead
of passing core structures in the data field. It also introduces support
for the MT6392 PMIC, including its regulators, RTC, keys, and pinctrl.
> diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
> index ccd97d66d7f1c..f683e878543e1 100644
> --- a/drivers/mfd/mt6397-core.c
> +++ b/drivers/mfd/mt6397-core.c
[ ... ]
> @@ -278,6 +311,7 @@ static int mt6397_probe(struct platform_device *pdev)
> unsigned int id = 0;
> struct mt6397_chip *pmic;
> const struct chip_data *pmic_core;
> + int chip_variant;
>
> pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL);
> if (!pmic)
> @@ -293,9 +327,36 @@ static int mt6397_probe(struct platform_device *pdev)
> if (!pmic->regmap)
> return -ENODEV;
>
> - pmic_core = of_device_get_match_data(&pdev->dev);
> - if (!pmic_core)
> + chip_variant = (unsigned int)(uintptr_t)device_get_match_data(&pdev->dev);
> + switch (chip_variant) {
[ ... ]
[Severity: High]
This is a pre-existing issue, but is there a use-after-free race on the
probe error path?
If devm_mfd_add_devices() fails further down in mt6397_probe(), the error
path calls irq_domain_remove(pmic->irq_domain) to explicitly free the
domain memory. However, the devm-managed threaded IRQ handler remains fully
active until the probe function returns. If an interrupt triggers during this
window, could mt6397_irq_thread() call irq_find_mapping() and dereference
the freed irq_domain pointer?
[Severity: High]
This is another pre-existing issue, but does the device unbind path leak
resources and cause a crash?
If devm_mfd_add_devices() fails, or if the driver is unbound, the PM
notifier registered in mt6397_irq_init() via register_pm_notifier() is
never explicitly unregistered because mt6397_driver lacks a .remove callback.
Since devres frees the mt6397_chip structure, would a subsequent suspend or
resume event traverse the global notifier list and dereference this freed
pointer?
> diff --git a/drivers/mfd/mt6397-irq.c b/drivers/mfd/mt6397-irq.c
> index 5d2e5459f7444..80ea5b92d232f 100644
> --- a/drivers/mfd/mt6397-irq.c
> +++ b/drivers/mfd/mt6397-irq.c
> @@ -203,6 +205,12 @@ int mt6397_irq_init(struct mt6397_chip *chip)
> chip->int_status[0] = MT6397_INT_STATUS0;
> chip->int_status[1] = MT6397_INT_STATUS1;
> break;
> + case MT6392_CHIP_ID:
> + chip->int_con[0] = MT6392_INT_CON0;
> + chip->int_con[1] = MT6392_INT_CON1;
> + chip->int_status[0] = MT6392_INT_STATUS0;
> + chip->int_status[1] = MT6392_INT_STATUS1;
> + break;
>
> default:
> dev_err(chip->dev, "unsupported chip: 0x%x\n", chip->chip_id);
[Severity: High]
This is a pre-existing issue, but does the hardcoded domain size cause
interrupts to be dropped?
Further down in mt6397_irq_init(), the IRQ domain is created unconditionally
with MT6397_IRQ_NR (which is 32):
chip->irq_domain = irq_domain_create_linear(dev_fwnode(chip->dev),
MT6397_IRQ_NR,
&mt6397_irq_domain_ops,
chip);
Since the MT6328 chip requires up to 47 IRQs, could mt6397_irq_thread()
fail when calling irq_find_mapping() for interrupts exceeding the allocated
linear domain size of 32?
[Severity: High]
This is also a pre-existing issue, but does the PM notifier overwrite
wake masks without synchronization?
The mt6397_irq_pm_notifier() writes to the hardware interrupt control
registers to set wake masks during PM_SUSPEND_PREPARE without acquiring
chip->irqlock:
case PM_SUSPEND_PREPARE:
regmap_write(chip->regmap, chip->int_con[0], chip->wake_mask[0]);
If a child device driver alters an IRQ state during its own suspend phase,
could the bus unlock callback mt6397_irq_sync_unlock() concurrently write
chip->irq_masks_cur to the same registers and overwrite the configured
wake masks?
> diff --git a/include/linux/mfd/mt6392/core.h b/include/linux/mfd/mt6392/core.h
> new file mode 100644
> index 0000000000000..8777b3abf9292
> --- /dev/null
> +++ b/include/linux/mfd/mt6392/core.h
> @@ -0,0 +1,43 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Copyright (c) 2020 MediaTek Inc.
> + * Copyright (c) 2026 Luca Leonardo Scorcia <l.scorcia@gmail.com>
> + * Author: Chen Zhong <chen.zhong@mediatek.com>
> + */
> +
> +#ifndef __MFD_MT6392_CORE_H__
> +#define __MFD_MT6392_CORE_H__
[Severity: Low]
Are these driver-specific header files placed correctly? The MFD subsystem
guidelines state that driver-specific headers should not be placed in the
global include/linux/mfd/ directory if they are only used by the parent
and immediate children. Should these instead be kept local to drivers/mfd/?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260820122242.120039-1-l.scorcia@gmail.com?part=5
next prev parent reply other threads:[~2026-08-20 12:49 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-20 12:19 [PATCH RESEND v9 0/9] Add support for MT6392 PMIC Luca Leonardo Scorcia
2026-08-20 12:19 ` [PATCH v9 1/9] dt-bindings: mfd: mt6397: Add " Luca Leonardo Scorcia
2026-08-20 12:40 ` sashiko-bot
2026-08-20 16:23 ` Luca Leonardo Scorcia
2026-08-20 12:20 ` [PATCH v9 2/9] dt-bindings: input: mtk-pmic-keys: Add MT6392 PMIC keys Luca Leonardo Scorcia
2026-08-20 12:44 ` sashiko-bot
2026-08-20 12:20 ` [PATCH v9 3/9] regulator: dt-bindings: Add MediaTek MT6392 PMIC Luca Leonardo Scorcia
2026-08-20 12:39 ` sashiko-bot
2026-08-20 12:20 ` [PATCH v9 4/9] mfd: mt6397: Use MFD_CELL_* to describe sub-devices Luca Leonardo Scorcia
2026-08-20 12:47 ` sashiko-bot
2026-08-20 12:20 ` [PATCH v9 5/9] mfd: mt6397: Add support for MT6392 PMIC Luca Leonardo Scorcia
2026-08-20 12:49 ` sashiko-bot [this message]
2026-08-20 12:20 ` [PATCH v9 6/9] input: keyboard: mtk-pmic-keys: Add MT6392 support Luca Leonardo Scorcia
2026-08-20 12:43 ` sashiko-bot
2026-08-20 12:20 ` [PATCH v9 7/9] pinctrl: mediatek: mt6397: Add MediaTek MT6392 Luca Leonardo Scorcia
2026-08-20 12:51 ` sashiko-bot
2026-08-20 12:20 ` [PATCH v9 8/9] regulator: Add MediaTek MT6392 regulator Luca Leonardo Scorcia
2026-08-20 12:40 ` sashiko-bot
2026-08-20 12:20 ` [PATCH v9 9/9] arm64: dts: mediatek: Add MediaTek MT6392 PMIC dtsi Luca Leonardo Scorcia
2026-08-20 12:58 ` sashiko-bot
-- strict thread matches above, loose matches on Subject: below --
2026-06-21 8:13 [PATCH v9 0/9] Add support for MT6392 PMIC Luca Leonardo Scorcia
2026-06-21 8:13 ` [PATCH v9 5/9] mfd: mt6397: " Luca Leonardo Scorcia
2026-06-21 8:32 ` 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=20260820124929.78F0C1F00A3D@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