[04/33] gpiolib-of: use match_string() helper

Message ID 1526903890-35761-5-git-send-email-xieyisheng1@huawei.com
State New
Headers show
Series
  • Untitled series #45613
Related show

Commit Message

Yisheng Xie May 21, 2018, 11:57 a.m.
match_string() returns the index of an array for a matching string,
which can be used intead of open coded variant.

Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: linux-gpio@vger.kernel.org
Signed-off-by: Yisheng Xie <xieyisheng1@huawei.com>
---
 drivers/gpio/gpiolib-of.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

Comments

Andy Shevchenko May 21, 2018, 9:36 p.m. | #1
On Mon, May 21, 2018 at 2:57 PM, Yisheng Xie <xieyisheng1@huawei.com> wrote:
> match_string() returns the index of an array for a matching string,
> which can be used intead of open coded variant.
>

https://patchwork.ozlabs.org/patch/908134/

> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: linux-gpio@vger.kernel.org
> Signed-off-by: Yisheng Xie <xieyisheng1@huawei.com>

Patch

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 586d151..9cbc898 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -202,7 +202,6 @@  static struct gpio_desc *of_find_regulator_gpio(struct device *dev, const char *
 	};
 	struct device_node *np = dev->of_node;
 	struct gpio_desc *desc;
-	int i;
 
 	if (!IS_ENABLED(CONFIG_REGULATOR))
 		return ERR_PTR(-ENOENT);
@@ -210,11 +209,7 @@  static struct gpio_desc *of_find_regulator_gpio(struct device *dev, const char *
 	if (!con_id)
 		return ERR_PTR(-ENOENT);
 
-	for (i = 0; i < ARRAY_SIZE(whitelist); i++)
-		if (!strcmp(con_id, whitelist[i]))
-			break;
-
-	if (i == ARRAY_SIZE(whitelist))
+	if (match_string(whitelist, ARRAY_SIZE(whitelist), con_id) < 0)
 		return ERR_PTR(-ENOENT);
 
 	desc = of_get_named_gpiod_flags(np, con_id, 0, of_flags);