From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Guanglei Zhu <zhugl3@xiaopeng.com>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
liuc63@xiaopeng.com, stable@vger.kernel.org
Subject: Re: [PATCH] Input: tegra-kbc - check the pin numbers from the device tree
Date: Wed, 04 Nov 2026 09:08:46 -0800 [thread overview]
Message-ID: <219a70bd93416777ae88becb34d8cb72@gmail.com> (raw)
In-Reply-To: <20261103084135.426629-7-zhugl3@xiaopeng.com>
Hi Guanglei,
On Tue, Nov 03, 2026 at 04:41:34PM +0800, Guanglei Zhu wrote:
> The row and column pin lists are read straight from the device tree
> and used to index the fixed pin configuration array:
>
> num_rows = of_property_read_variable_u32_array(np, "nvidia,kbc-row-pins",
> rows_cfg, 1, KBC_MAX_GPIO);
> ...
> for (i = 0; i < num_rows; i++) {
> kbc->pin_cfg[rows_cfg[i]].type = PIN_CFG_ROW;
> kbc->pin_cfg[rows_cfg[i]].num = i;
> }
>
> The helper only limits how many entries it reads, not what they
> contain, and the pin_cfg array holds KBC_MAX_GPIO entries, so a pin
> number from the device tree indexes past the array into the rest
> of the driver data. The later configuration check validates the
> row and column counts stored this way, not the index itself, so it
> cannot undo the write.
>
> Reject pin numbers the array does not have.
>
> Fixes: 88390243a993 ("Input: tegra-kbc - add support for rows/columns configuration from dt")
> Cc: stable@vger.kernel.org
> Signed-off-by: Guanglei Zhu <zhugl3@xiaopeng.com>
> ---
> drivers/input/keyboard/tegra-kbc.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/drivers/input/keyboard/tegra-kbc.c b/drivers/input/keyboard/tegra-kbc.c
> index e6177f2bdf8d..f086ccf1a075 100644
> --- a/drivers/input/keyboard/tegra-kbc.c
> +++ b/drivers/input/keyboard/tegra-kbc.c
> @@ -522,6 +522,10 @@ static int tegra_kbc_parse_dt(struct tegra_kbc *kbc)
> }
>
> for (i = 0; i < num_rows; i++) {
> + if (rows_cfg[i] >= KBC_MAX_GPIO) {
> + dev_err(kbc->dev, "invalid row pin %u\n", rows_cfg[i]);
> + return -EINVAL;
> + }
> kbc->pin_cfg[rows_cfg[i]].type = PIN_CFG_ROW;
> kbc->pin_cfg[rows_cfg[i]].num = i;
> }
> @@ -538,6 +542,10 @@ static int tegra_kbc_parse_dt(struct tegra_kbc *kbc)
> }
>
> for (i = 0; i < num_cols; i++) {
> + if (cols_cfg[i] >= KBC_MAX_GPIO) {
> + dev_err(kbc->dev, "invalid col pin %u\n", cols_cfg[i]);
> + return -EINVAL;
> + }
> kbc->pin_cfg[cols_cfg[i]].type = PIN_CFG_COL;
> kbc->pin_cfg[cols_cfg[i]].num = i;
> }
Could you please check against kbc->num_rows_and_columns instead of
KBC_MAX_GPIO? Not all Tegra variants have 24 KBC pins (for example,
Tegra114 only has 11 rows + 8 columns = 19 pins), and the loop right
above only initializes kbc->pin_cfg[] up to kbc->num_rows_and_columns.
Thanks.
--
Dmitry
next prev parent reply other threads:[~2026-11-04 17:08 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 8:41 [PATCH] Input: joydev - avoid an undefined shift in the legacy 0x read Guanglei Zhu
2026-11-03 8:41 ` [PATCH] Input: joydev - avoid signed overflow in the broken-axis correction Guanglei Zhu
2026-11-03 8:48 ` sashiko-bot
2026-11-03 8:55 ` [PATCH v2] " Guanglei Zhu
2026-11-04 3:38 ` Dmitry Torokhov
2026-11-04 5:50 ` [PATCH v3] " Guanglei Zhu
2026-11-04 6:02 ` Guanglei Zhu
2026-11-03 8:41 ` [PATCH] Input: adi - bound the two-stream packet merge Guanglei Zhu
2026-11-03 8:55 ` sashiko-bot
2026-11-03 11:17 ` [PATCH v2] " Guanglei Zhu
2026-11-03 8:41 ` [PATCH] Input: db9 - enlarge the Saturn multitap packet buffer Guanglei Zhu
2026-11-03 8:41 ` [PATCH] Input: lpc32xx-keys - reject matrices bigger than the hardware has Guanglei Zhu
2026-11-03 18:54 ` Dmitry Torokhov
2026-11-04 3:07 ` [PATCH v2] " Guanglei Zhu
2026-11-04 6:25 ` Dmitry Torokhov
2026-11-03 8:41 ` [PATCH] Input: mt6779-keypad - check the reported row and column Guanglei Zhu
2026-11-03 8:41 ` [PATCH] Input: tegra-kbc - check the pin numbers from the device tree Guanglei Zhu
2026-11-04 17:08 ` Dmitry Torokhov [this message]
2026-11-03 8:41 ` [PATCH] Input: cyapa_gen3 - clamp the reported finger count to the array Guanglei Zhu
2026-11-03 18:45 ` [PATCH] Input: joydev - avoid an undefined shift in the legacy 0x read Dmitry Torokhov
2026-11-04 3:07 ` [PATCH v2] " Guanglei Zhu
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=219a70bd93416777ae88becb34d8cb72@gmail.com \
--to=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liuc63@xiaopeng.com \
--cc=stable@vger.kernel.org \
--cc=zhugl3@xiaopeng.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.