linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH next] pinctrl: tegra: Fix off by one in tegra_pinctrl_get_group()
@ 2025-03-19  7:05 Dan Carpenter
  2025-03-19  7:11 ` Kunwu Chan
  2025-03-20  8:13 ` Linus Walleij
  0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2025-03-19  7:05 UTC (permalink / raw)
  To: Prathamesh Shete
  Cc: Linus Walleij, Thierry Reding, Jonathan Hunter, Peng Fan,
	linux-gpio, linux-tegra, linux-kernel, kernel-janitors

This should be >= pmx->soc->ngroups instead of > to avoid an out of
bounds access.  The pmx->soc->groups[] array is allocated in
tegra_pinctrl_probe().

Fixes: c12bfa0fee65 ("pinctrl-tegra: Restore SFSEL bit when freeing pins")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/pinctrl/tegra/pinctrl-tegra.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pinctrl/tegra/pinctrl-tegra.c b/drivers/pinctrl/tegra/pinctrl-tegra.c
index 0246acba7703..11ecbd6a9b2a 100644
--- a/drivers/pinctrl/tegra/pinctrl-tegra.c
+++ b/drivers/pinctrl/tegra/pinctrl-tegra.c
@@ -306,7 +306,7 @@ static const struct tegra_pingroup *tegra_pinctrl_get_group(struct pinctrl_dev *
 {
 	struct tegra_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);
 
-	if (group_index < 0 || group_index > pmx->soc->ngroups)
+	if (group_index < 0 || group_index >= pmx->soc->ngroups)
 		return NULL;
 
 	return &pmx->soc->groups[group_index];
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH next] pinctrl: tegra: Fix off by one in tegra_pinctrl_get_group()
  2025-03-19  7:05 [PATCH next] pinctrl: tegra: Fix off by one in tegra_pinctrl_get_group() Dan Carpenter
@ 2025-03-19  7:11 ` Kunwu Chan
  2025-03-20  8:13 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Kunwu Chan @ 2025-03-19  7:11 UTC (permalink / raw)
  To: Dan Carpenter, Prathamesh Shete
  Cc: Linus Walleij, Thierry Reding, Jonathan Hunter, Peng Fan,
	linux-gpio, linux-tegra, linux-kernel, kernel-janitors

On 2025/3/19 15:05, Dan Carpenter wrote:
> This should be >= pmx->soc->ngroups instead of > to avoid an out of
> bounds access.  The pmx->soc->groups[] array is allocated in
> tegra_pinctrl_probe().
>
> Fixes: c12bfa0fee65 ("pinctrl-tegra: Restore SFSEL bit when freeing pins")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
>   drivers/pinctrl/tegra/pinctrl-tegra.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/pinctrl/tegra/pinctrl-tegra.c b/drivers/pinctrl/tegra/pinctrl-tegra.c
> index 0246acba7703..11ecbd6a9b2a 100644
> --- a/drivers/pinctrl/tegra/pinctrl-tegra.c
> +++ b/drivers/pinctrl/tegra/pinctrl-tegra.c
> @@ -306,7 +306,7 @@ static const struct tegra_pingroup *tegra_pinctrl_get_group(struct pinctrl_dev *
>   {
>   	struct tegra_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);
>   
> -	if (group_index < 0 || group_index > pmx->soc->ngroups)
> +	if (group_index < 0 || group_index >= pmx->soc->ngroups)
>   		return NULL;
>   
>   	return &pmx->soc->groups[group_index];

Reviewed-by: Kunwu Chan <kunwu.chan@linux.dev>

-- 
Thanks,
   Kunwu.Chan(Tao.Chan)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH next] pinctrl: tegra: Fix off by one in tegra_pinctrl_get_group()
  2025-03-19  7:05 [PATCH next] pinctrl: tegra: Fix off by one in tegra_pinctrl_get_group() Dan Carpenter
  2025-03-19  7:11 ` Kunwu Chan
@ 2025-03-20  8:13 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2025-03-20  8:13 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Prathamesh Shete, Thierry Reding, Jonathan Hunter, Peng Fan,
	linux-gpio, linux-tegra, linux-kernel, kernel-janitors

On Wed, Mar 19, 2025 at 8:05 AM Dan Carpenter <dan.carpenter@linaro.org> wrote:

> This should be >= pmx->soc->ngroups instead of > to avoid an out of
> bounds access.  The pmx->soc->groups[] array is allocated in
> tegra_pinctrl_probe().
>
> Fixes: c12bfa0fee65 ("pinctrl-tegra: Restore SFSEL bit when freeing pins")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

Thanks Dan, excellent find.

Patch applied!

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-03-20  8:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-19  7:05 [PATCH next] pinctrl: tegra: Fix off by one in tegra_pinctrl_get_group() Dan Carpenter
2025-03-19  7:11 ` Kunwu Chan
2025-03-20  8:13 ` Linus Walleij

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).