[2/2] pinctrl: sprd: fix off by one bugs

Message ID 20170907073211.zgcgmdfrphtqy3d7@mwanda
State New
Headers show
Series
  • [1/2] pinctrl: sprd: check for allocation failure
Related show

Commit Message

Dan Carpenter Sept. 7, 2017, 11:12 a.m.
info->groups[] has info->ngroups elements so these comparisons should be
>= instead of >.

Fixes: 41d32cfce1ae ("pinctrl: sprd: Add Spreadtrum pin control driver")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Baolin Wang Sept. 7, 2017, 11:29 a.m. | #1
On ε››,  9月 07, 2017 at 02:12:05δΈ‹εˆ +0300, Dan Carpenter wrote:
> info->groups[] has info->ngroups elements so these comparisons should be
> >= instead of >.
> 
> Fixes: 41d32cfce1ae ("pinctrl: sprd: Add Spreadtrum pin control driver")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Thanks for fixing my mistakes, please add my tag if it is useful.
Reviewed-by: Baolin Wang <baolin.wang@spreadtrum.com>

> 
> diff --git a/drivers/pinctrl/sprd/pinctrl-sprd.c b/drivers/pinctrl/sprd/pinctrl-sprd.c
> index 673b77bbbc8c..939e1bbf6253 100644
> --- a/drivers/pinctrl/sprd/pinctrl-sprd.c
> +++ b/drivers/pinctrl/sprd/pinctrl-sprd.c
> @@ -400,7 +400,7 @@ static int sprd_pmx_set_mux(struct pinctrl_dev *pctldev,
>  	unsigned long reg;
>  	unsigned int val = 0;
>  
> -	if (group_selector > info->ngroups)
> +	if (group_selector >= info->ngroups)
>  		return -EINVAL;
>  
>  	switch (func_selector) {
> @@ -734,7 +734,7 @@ static int sprd_pinconf_group_get(struct pinctrl_dev *pctldev,
>  	struct sprd_pin_group *grp;
>  	unsigned int pin_id;
>  
> -	if (selector > info->ngroups)
> +	if (selector >= info->ngroups)
>  		return -EINVAL;
>  
>  	grp = &info->groups[selector];
> @@ -753,7 +753,7 @@ static int sprd_pinconf_group_set(struct pinctrl_dev *pctldev,
>  	struct sprd_pin_group *grp;
>  	int ret, i;
>  
> -	if (selector > info->ngroups)
> +	if (selector >= info->ngroups)
>  		return -EINVAL;
>  
>  	grp = &info->groups[selector];
> @@ -813,7 +813,7 @@ static void sprd_pinconf_group_dbg_show(struct pinctrl_dev *pctldev,
>  	const char *name;
>  	int i, ret;
>  
> -	if (selector > info->ngroups)
> +	if (selector >= info->ngroups)
>  		return;
>  
>  	grp = &info->groups[selector];
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Linus Walleij Sept. 12, 2017, 9:28 a.m. | #2
On Thu, Sep 7, 2017 at 1:12 PM, Dan Carpenter <dan.carpenter@oracle.com> wrote:

> info->groups[] has info->ngroups elements so these comparisons should be
>>= instead of >.
>
> Fixes: 41d32cfce1ae ("pinctrl: sprd: Add Spreadtrum pin control driver")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Patch applied with Baolin's review tag.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/drivers/pinctrl/sprd/pinctrl-sprd.c b/drivers/pinctrl/sprd/pinctrl-sprd.c
index 673b77bbbc8c..939e1bbf6253 100644
--- a/drivers/pinctrl/sprd/pinctrl-sprd.c
+++ b/drivers/pinctrl/sprd/pinctrl-sprd.c
@@ -400,7 +400,7 @@  static int sprd_pmx_set_mux(struct pinctrl_dev *pctldev,
 	unsigned long reg;
 	unsigned int val = 0;
 
-	if (group_selector > info->ngroups)
+	if (group_selector >= info->ngroups)
 		return -EINVAL;
 
 	switch (func_selector) {
@@ -734,7 +734,7 @@  static int sprd_pinconf_group_get(struct pinctrl_dev *pctldev,
 	struct sprd_pin_group *grp;
 	unsigned int pin_id;
 
-	if (selector > info->ngroups)
+	if (selector >= info->ngroups)
 		return -EINVAL;
 
 	grp = &info->groups[selector];
@@ -753,7 +753,7 @@  static int sprd_pinconf_group_set(struct pinctrl_dev *pctldev,
 	struct sprd_pin_group *grp;
 	int ret, i;
 
-	if (selector > info->ngroups)
+	if (selector >= info->ngroups)
 		return -EINVAL;
 
 	grp = &info->groups[selector];
@@ -813,7 +813,7 @@  static void sprd_pinconf_group_dbg_show(struct pinctrl_dev *pctldev,
 	const char *name;
 	int i, ret;
 
-	if (selector > info->ngroups)
+	if (selector >= info->ngroups)
 		return;
 
 	grp = &info->groups[selector];