2019-09-26 12:42:30

by Dan Carpenter

[permalink] [raw]
Subject: [PATCH] ns2: Fix off by one bugs in ns2_pinmux_enable()

The pinctrl->functions[] array has pinctrl->num_functions elements and
the pinctrl->groups[] array is the same way. These are set in
ns2_pinmux_probe(). So the > comparisons should be >= so that we don't
read one element beyond the end of the array.

Fixes: b5aa1006e4a9 ("pinctrl: ns2: add pinmux driver support for Broadcom NS2 SoC")
Signed-off-by: Dan Carpenter <[email protected]>
---
drivers/pinctrl/bcm/pinctrl-ns2-mux.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/pinctrl/bcm/pinctrl-ns2-mux.c b/drivers/pinctrl/bcm/pinctrl-ns2-mux.c
index 2bf6af7df7d9..9fabc451550e 100644
--- a/drivers/pinctrl/bcm/pinctrl-ns2-mux.c
+++ b/drivers/pinctrl/bcm/pinctrl-ns2-mux.c
@@ -640,8 +640,8 @@ static int ns2_pinmux_enable(struct pinctrl_dev *pctrl_dev,
const struct ns2_pin_function *func;
const struct ns2_pin_group *grp;

- if (grp_select > pinctrl->num_groups ||
- func_select > pinctrl->num_functions)
+ if (grp_select >= pinctrl->num_groups ||
+ func_select >= pinctrl->num_functions)
return -EINVAL;

func = &pinctrl->functions[func_select];
--
2.20.1


2019-10-02 21:48:43

by Scott Branden

[permalink] [raw]
Subject: Re: [PATCH] ns2: Fix off by one bugs in ns2_pinmux_enable()

thanks for fix.

On 2019-09-26 1:14 a.m., Dan Carpenter wrote:
> The pinctrl->functions[] array has pinctrl->num_functions elements and
> the pinctrl->groups[] array is the same way. These are set in
> ns2_pinmux_probe(). So the > comparisons should be >= so that we don't
> read one element beyond the end of the array.
>
> Fixes: b5aa1006e4a9 ("pinctrl: ns2: add pinmux driver support for Broadcom NS2 SoC")
> Signed-off-by: Dan Carpenter <[email protected]>
Acked-by: Scott Branden <[email protected]>
> ---
> drivers/pinctrl/bcm/pinctrl-ns2-mux.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/pinctrl/bcm/pinctrl-ns2-mux.c b/drivers/pinctrl/bcm/pinctrl-ns2-mux.c
> index 2bf6af7df7d9..9fabc451550e 100644
> --- a/drivers/pinctrl/bcm/pinctrl-ns2-mux.c
> +++ b/drivers/pinctrl/bcm/pinctrl-ns2-mux.c
> @@ -640,8 +640,8 @@ static int ns2_pinmux_enable(struct pinctrl_dev *pctrl_dev,
> const struct ns2_pin_function *func;
> const struct ns2_pin_group *grp;
>
> - if (grp_select > pinctrl->num_groups ||
> - func_select > pinctrl->num_functions)
> + if (grp_select >= pinctrl->num_groups ||
> + func_select >= pinctrl->num_functions)
> return -EINVAL;
>
> func = &pinctrl->functions[func_select];

2019-10-04 22:17:50

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH] ns2: Fix off by one bugs in ns2_pinmux_enable()

On Thu, Sep 26, 2019 at 10:14 AM Dan Carpenter <[email protected]> wrote:

> The pinctrl->functions[] array has pinctrl->num_functions elements and
> the pinctrl->groups[] array is the same way. These are set in
> ns2_pinmux_probe(). So the > comparisons should be >= so that we don't
> read one element beyond the end of the array.
>
> Fixes: b5aa1006e4a9 ("pinctrl: ns2: add pinmux driver support for Broadcom NS2 SoC")
> Signed-off-by: Dan Carpenter <[email protected]>

Patch applied with Scott's ACK.

Yours,
Linus Walleij