devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Luca Leonardo Scorcia" <l.scorcia@gmail.com>
Cc: conor+dt@kernel.org, lee@kernel.org, mfd@lists.linux.dev,
	devicetree@vger.kernel.org, dmitry.torokhov@gmail.com,
	robh@kernel.org, linux-input@vger.kernel.org
Subject: Re: [PATCH v9 6/9] input: keyboard: mtk-pmic-keys: Add MT6392 support
Date: Thu, 20 Aug 2026 12:43:34 +0000	[thread overview]
Message-ID: <20260820124335.41B0D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260820122242.120039-7-l.scorcia@gmail.com>

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

Pre-existing issues:
- [High] Mismatch between bounds checking and child node iteration causes out-of-bounds array accesses if disabled child nodes are present.
- [High] Physical keys mapped to incorrect hardware resources and IRQs due to strict dependency on DT node parsing order.
--

--- Patch [6]: [PATCH v9 6/9] input: keyboard: mtk-pmic-keys: Add MT6392 support ---
commit 7d4906573abcc4f44ff8cbf94c0c7919e5484f08
Author: Val Packett <val@packett.cool>

input: keyboard: mtk-pmic-keys: Add MT6392 support

This commit adds support for the MT6392 PMIC to the keys driver.

> diff --git a/drivers/input/keyboard/mtk-pmic-keys.c b/drivers/input/keyboard/mtk-pmic-keys.c
> index c78d9f6d97c4f..8b4a89fce4fb1 100644
> --- a/drivers/input/keyboard/mtk-pmic-keys.c
> +++ b/drivers/input/keyboard/mtk-pmic-keys.c
[ ... ]
> @@ -301,6 +315,9 @@ static const struct of_device_id of_mtk_pmic_keys_match_tbl[] = {
>  	{
>  		.compatible = "mediatek,mt6397-keys",
>  		.data = &mt6397_regs,
> +	}, {
> +		.compatible = "mediatek,mt6392-keys",
> +		.data = &mt6392_regs,

[Severity: High]
This isn't a bug introduced by this patch, but I noticed a potential
out-of-bounds array access in mtk_pmic_keys_probe() when handling these keys.

The probe function limits the maximum number of keys by checking the count of
available nodes:

	keycount = of_get_available_child_count(node);
	if (keycount > MTK_PMIC_MAX_KEY_COUNT ||
	    keycount > ARRAY_SIZE(irqnames)) {
		dev_err(keys->dev, "too many keys defined (%d)\n", keycount);
		return -EINVAL;
	}

However, it then iterates over all child nodes, including disabled ones:

	for_each_child_of_node_scoped(node, child) {
		keys->keys[index].regs = &mtk_pmic_regs->keys_regs[index];

		keys->keys[index].irq =
			platform_get_irq_byname(pdev, irqnames[index]);

If a device tree defines disabled child nodes alongside available ones, such
that the available count passes the check but the total child count exceeds
MTK_PMIC_MAX_KEY_COUNT, could this loop iterate past the bounds of keys->keys[]
and irqnames[]?


[Severity: High]
This is also a pre-existing issue, but does this mapping logic safely correlate
device tree nodes to the correct physical hardware?

The driver maps the nodes based entirely on their iteration order (index)
rather than checking the node names:

	for_each_child_of_node_scoped(node, child) {
		keys->keys[index].regs = &mtk_pmic_regs->keys_regs[index];

Since index 0 is unconditionally treated as the power key and index 1 as the
home key, what happens if a device tree omits the power key and only defines
a home key? Will the home key node be improperly mapped to the power key
hardware resources and IRQs?

>  	}, {
>  		.compatible = "mediatek,mt6323-keys",
>  		.data = &mt6323_regs,

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260820122242.120039-1-l.scorcia@gmail.com?part=6

  reply	other threads:[~2026-08-20 12:43 UTC|newest]

Thread overview: 21+ 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 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
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 [this message]
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 6/9] input: keyboard: mtk-pmic-keys: Add MT6392 support Luca Leonardo Scorcia
2026-06-21  8:28   ` 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=20260820124335.41B0D1F000E9@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;
as well as URLs for NNTP newsgroup(s).