linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ns2: Fix off by one bugs in ns2_pinmux_enable()
@ 2019-09-26  8:14 Dan Carpenter
  2019-10-02 20:06 ` Scott Branden
  2019-10-04 22:14 ` Linus Walleij
  0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2019-09-26  8:14 UTC (permalink / raw)
  To: Ray Jui, Yendapally Reddy Dhananjaya Reddy
  Cc: Scott Branden, bcm-kernel-feedback-list, Linus Walleij,
	linux-gpio, linux-kernel, kernel-janitors

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 <dan.carpenter@oracle.com>
---
 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


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

* Re: [PATCH] ns2: Fix off by one bugs in ns2_pinmux_enable()
  2019-09-26  8:14 [PATCH] ns2: Fix off by one bugs in ns2_pinmux_enable() Dan Carpenter
@ 2019-10-02 20:06 ` Scott Branden
  2019-10-04 22:14 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Scott Branden @ 2019-10-02 20:06 UTC (permalink / raw)
  To: Dan Carpenter, Ray Jui, Yendapally Reddy Dhananjaya Reddy
  Cc: Scott Branden, bcm-kernel-feedback-list, Linus Walleij,
	linux-gpio, linux-kernel, kernel-janitors

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 <dan.carpenter@oracle.com>
Acked-by: Scott Branden <scott.branden@broadcom.com>
> ---
>   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];


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

* Re: [PATCH] ns2: Fix off by one bugs in ns2_pinmux_enable()
  2019-09-26  8:14 [PATCH] ns2: Fix off by one bugs in ns2_pinmux_enable() Dan Carpenter
  2019-10-02 20:06 ` Scott Branden
@ 2019-10-04 22:14 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2019-10-04 22:14 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Ray Jui, Yendapally Reddy Dhananjaya Reddy, Scott Branden,
	bcm-kernel-feedback-list, open list:GPIO SUBSYSTEM, linux-kernel,
	kernel-janitors

On Thu, Sep 26, 2019 at 10:14 AM Dan Carpenter <dan.carpenter@oracle.com> 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 <dan.carpenter@oracle.com>

Patch applied with Scott's ACK.

Yours,
Linus Walleij

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

end of thread, other threads:[~2019-10-04 22:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-26  8:14 [PATCH] ns2: Fix off by one bugs in ns2_pinmux_enable() Dan Carpenter
2019-10-02 20:06 ` Scott Branden
2019-10-04 22:14 ` 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).