Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1421728 > unrolled thread

[PATCH 5/5] gpio: of: factor out common code to a new helper function

Started byMasahiro Yamada <yamada.masahiro@socionext.com>
First post2016-06-14 12:10 +0200
Last post2016-06-23 09:50 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 5/5] gpio: of: factor out common code to a new helper function Masahiro Yamada <yamada.masahiro@socionext.com> - 2016-06-14 12:10 +0200
    Re: [PATCH 5/5] gpio: of: factor out common code to a new helper function Linus Walleij <linus.walleij@linaro.org> - 2016-06-23 09:50 +0200

#1421728 — [PATCH 5/5] gpio: of: factor out common code to a new helper function

FromMasahiro Yamada <yamada.masahiro@socionext.com>
Date2016-06-14 12:10 +0200
Subject[PATCH 5/5] gpio: of: factor out common code to a new helper function
Message-ID<rJTsd-3r2-1@gated-at.bofh.it>
The conversion from a DT spec to struct gpio_desc is common between
of_get_named_gpiod_flags() and of_parse_own_gpio().  Factor out the
common code to a new helper, of_xlate_and_get_gpiod_flags().

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

 drivers/gpio/gpiolib-of.c | 37 ++++++++++++++++++-------------------
 1 file changed, 18 insertions(+), 19 deletions(-)

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index d5e19f6..75e7b39 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -37,6 +37,22 @@ static struct gpio_chip *of_find_gpiochip_by_node(struct device_node *np)
 	return gpiochip_find(np, of_gpiochip_match_node);
 }
 
+static struct gpio_desc *of_xlate_and_get_gpiod_flags(struct gpio_chip *chip,
+					struct of_phandle_args *gpiospec,
+					enum of_gpio_flags *flags)
+{
+	int ret;
+
+	if (chip->of_gpio_n_cells != gpiospec->args_count)
+		return ERR_PTR(-EINVAL);
+
+	ret = chip->of_xlate(chip, gpiospec, flags);
+	if (ret < 0)
+		return ERR_PTR(ret);
+
+	return gpiochip_get_desc(chip, ret);
+}
+
 /**
  * of_get_named_gpiod_flags() - Get a GPIO descriptor and flags for GPIO API
  * @np:		device node to get GPIO from
@@ -69,18 +85,8 @@ struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np,
 		desc = ERR_PTR(-EPROBE_DEFER);
 		goto out;
 	}
-	if (chip->of_gpio_n_cells != gpiospec.args_count) {
-		desc = ERR_PTR(-EINVAL);
-		goto out;
-	}
-
-	ret = chip->of_xlate(chip, &gpiospec, flags);
-	if (ret < 0) {
-		desc = ERR_PTR(ret);
-		goto out;
-	}
 
-	desc = gpiochip_get_desc(chip, ret);
+	desc = of_xlate_and_get_gpiod_flags(chip, &gpiospec, flags);
 	if (IS_ERR(desc))
 		goto out;
 
@@ -145,9 +151,6 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
 	if (ret)
 		return ERR_PTR(ret);
 
-	if (tmp != chip->of_gpio_n_cells)
-		return ERR_PTR(-EINVAL);
-
 	gpiospec.np = chip_np;
 	gpiospec.args_count = tmp;
 
@@ -155,11 +158,7 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
 	if (ret)
 		return ERR_PTR(ret);
 
-	ret = chip->of_xlate(chip, &gpiospec, &xlate_flags);
-	if (ret < 0)
-		return ERR_PTR(ret);
-
-	desc = gpiochip_get_desc(chip, ret);
+	desc = of_xlate_and_get_gpiod_flags(chip, &gpiospec, &xlate_flags);
 	if (IS_ERR(desc))
 		return desc;
 
-- 
1.9.1

[toc] | [next] | [standalone]


#1429537

FromLinus Walleij <linus.walleij@linaro.org>
Date2016-06-23 09:50 +0200
Message-ID<rN7yF-6MX-11@gated-at.bofh.it>
In reply to#1421728
On Tue, Jun 14, 2016 at 12:07 PM, Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:

> The conversion from a DT spec to struct gpio_desc is common between
> of_get_named_gpiod_flags() and of_parse_own_gpio().  Factor out the
> common code to a new helper, of_xlate_and_get_gpiod_flags().
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

Patch applied.

Yours,
Linus Walleij

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web