* [PATCH 2/2] mdio-mux-gpio: use new gpiod_get_array and gpiod_put_array functions
@ 2015-01-09 15:19 Rojhalat Ibrahim
2015-01-14 5:11 ` Alexandre Courbot
0 siblings, 1 reply; 3+ messages in thread
From: Rojhalat Ibrahim @ 2015-01-09 15:19 UTC (permalink / raw)
To: linux-gpio@vger.kernel.org
Cc: Alexandre Courbot, Linus Walleij, David Miller, netdev
Use the new gpiod_get_array and gpiod_put_array functions for obtaining and
disposing of GPIO descriptors.
Signed-off-by: Rojhalat Ibrahim <imr@rtschenk.de>
---
This patch depends on my previous patch "gpiolib: add gpiod_get_array and
gpiod_put_array functions".
drivers/net/phy/mdio-mux-gpio.c | 28 ++++++++--------------------
1 file changed, 8 insertions(+), 20 deletions(-)
diff --git a/drivers/net/phy/mdio-mux-gpio.c b/drivers/net/phy/mdio-mux-gpio.c
index 1eaf81e..35c37da 100644
--- a/drivers/net/phy/mdio-mux-gpio.c
+++ b/drivers/net/phy/mdio-mux-gpio.c
@@ -47,7 +47,6 @@ static int mdio_mux_gpio_probe(struct platform_device *pdev)
{
struct mdio_mux_gpio_state *s;
int num_gpios;
- unsigned int n;
int r;
if (!pdev->dev.of_node)
@@ -63,16 +62,10 @@ static int mdio_mux_gpio_probe(struct platform_device *pdev)
s->num_gpios = num_gpios;
- for (n = 0; n < num_gpios; ) {
- struct gpio_desc *gpio = gpiod_get_index(&pdev->dev, NULL, n,
- GPIOD_OUT_LOW);
- if (IS_ERR(gpio)) {
- r = PTR_ERR(gpio);
- goto err;
- }
- s->gpio[n] = gpio;
- n++;
- }
+ r = gpiod_get_array(&pdev->dev, NULL, s->gpio, num_gpios,
+ GPIOD_OUT_LOW);
+ if (r != num_gpios)
+ return r;
r = mdio_mux_init(&pdev->dev,
mdio_mux_gpio_switch_fn, &s->mux_handle, s);
@@ -80,22 +73,17 @@ static int mdio_mux_gpio_probe(struct platform_device *pdev)
if (r == 0) {
pdev->dev.platform_data = s;
return 0;
+ } else {
+ gpiod_put_array(s->gpio, num_gpios);
+ return r;
}
-err:
- while (n) {
- n--;
- gpiod_put(s->gpio[n]);
- }
- return r;
}
static int mdio_mux_gpio_remove(struct platform_device *pdev)
{
- unsigned int n;
struct mdio_mux_gpio_state *s = dev_get_platdata(&pdev->dev);
mdio_mux_uninit(s->mux_handle);
- for (n = 0; n < s->num_gpios; n++)
- gpiod_put(s->gpio[n]);
+ gpiod_put_array(s->gpio, s->num_gpios);
return 0;
}
--
2.0.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 2/2] mdio-mux-gpio: use new gpiod_get_array and gpiod_put_array functions
2015-01-09 15:19 [PATCH 2/2] mdio-mux-gpio: use new gpiod_get_array and gpiod_put_array functions Rojhalat Ibrahim
@ 2015-01-14 5:11 ` Alexandre Courbot
2015-01-14 13:01 ` Rojhalat Ibrahim
0 siblings, 1 reply; 3+ messages in thread
From: Alexandre Courbot @ 2015-01-14 5:11 UTC (permalink / raw)
To: Rojhalat Ibrahim
Cc: linux-gpio@vger.kernel.org, Alexandre Courbot, Linus Walleij,
David Miller, netdev
On Sat, Jan 10, 2015 at 12:19 AM, Rojhalat Ibrahim <imr@rtschenk.de> wrote:
> Use the new gpiod_get_array and gpiod_put_array functions for obtaining and
> disposing of GPIO descriptors.
>
> Signed-off-by: Rojhalat Ibrahim <imr@rtschenk.de>
> ---
> This patch depends on my previous patch "gpiolib: add gpiod_get_array and
> gpiod_put_array functions".
>
> drivers/net/phy/mdio-mux-gpio.c | 28 ++++++++--------------------
> 1 file changed, 8 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/net/phy/mdio-mux-gpio.c b/drivers/net/phy/mdio-mux-gpio.c
> index 1eaf81e..35c37da 100644
> --- a/drivers/net/phy/mdio-mux-gpio.c
> +++ b/drivers/net/phy/mdio-mux-gpio.c
> @@ -47,7 +47,6 @@ static int mdio_mux_gpio_probe(struct platform_device *pdev)
> {
> struct mdio_mux_gpio_state *s;
> int num_gpios;
> - unsigned int n;
> int r;
>
> if (!pdev->dev.of_node)
> @@ -63,16 +62,10 @@ static int mdio_mux_gpio_probe(struct platform_device *pdev)
>
> s->num_gpios = num_gpios;
>
> - for (n = 0; n < num_gpios; ) {
> - struct gpio_desc *gpio = gpiod_get_index(&pdev->dev, NULL, n,
> - GPIOD_OUT_LOW);
> - if (IS_ERR(gpio)) {
> - r = PTR_ERR(gpio);
> - goto err;
> - }
> - s->gpio[n] = gpio;
> - n++;
> - }
> + r = gpiod_get_array(&pdev->dev, NULL, s->gpio, num_gpios,
> + GPIOD_OUT_LOW);
> + if (r != num_gpios)
> + return r;
>
> r = mdio_mux_init(&pdev->dev,
> mdio_mux_gpio_switch_fn, &s->mux_handle, s);
> @@ -80,22 +73,17 @@ static int mdio_mux_gpio_probe(struct platform_device *pdev)
> if (r == 0) {
> pdev->dev.platform_data = s;
> return 0;
> + } else {
> + gpiod_put_array(s->gpio, num_gpios);
> + return r;
> }
Suggestion: handle the errors in the if condition, and let normal
execution be visible at the first level of indentation of the
function. I.e:
if (r != 0) {
gpiod_put_array(s->gpio, num_gpios);
return r;
}
pdev->dev.platform_data = s;
return 0;
This is how previous errors are handled in this function and is
generally a good thing to do as it makes the function's logic easier
to follow.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 2/2] mdio-mux-gpio: use new gpiod_get_array and gpiod_put_array functions
2015-01-14 5:11 ` Alexandre Courbot
@ 2015-01-14 13:01 ` Rojhalat Ibrahim
0 siblings, 0 replies; 3+ messages in thread
From: Rojhalat Ibrahim @ 2015-01-14 13:01 UTC (permalink / raw)
To: Alexandre Courbot
Cc: linux-gpio@vger.kernel.org, Alexandre Courbot, Linus Walleij,
David Miller, netdev
On Wednesday 14 January 2015 14:11:27 Alexandre Courbot wrote:
> On Sat, Jan 10, 2015 at 12:19 AM, Rojhalat Ibrahim <imr@rtschenk.de> wrote:
> > Use the new gpiod_get_array and gpiod_put_array functions for obtaining and
> > disposing of GPIO descriptors.
> >
> > Signed-off-by: Rojhalat Ibrahim <imr@rtschenk.de>
> > ---
> > This patch depends on my previous patch "gpiolib: add gpiod_get_array and
> > gpiod_put_array functions".
> >
> > drivers/net/phy/mdio-mux-gpio.c | 28 ++++++++--------------------
> > 1 file changed, 8 insertions(+), 20 deletions(-)
> >
> > diff --git a/drivers/net/phy/mdio-mux-gpio.c b/drivers/net/phy/mdio-mux-gpio.c
> > index 1eaf81e..35c37da 100644
> > --- a/drivers/net/phy/mdio-mux-gpio.c
> > +++ b/drivers/net/phy/mdio-mux-gpio.c
> > @@ -47,7 +47,6 @@ static int mdio_mux_gpio_probe(struct platform_device *pdev)
> > {
> > struct mdio_mux_gpio_state *s;
> > int num_gpios;
> > - unsigned int n;
> > int r;
> >
> > if (!pdev->dev.of_node)
> > @@ -63,16 +62,10 @@ static int mdio_mux_gpio_probe(struct platform_device *pdev)
> >
> > s->num_gpios = num_gpios;
> >
> > - for (n = 0; n < num_gpios; ) {
> > - struct gpio_desc *gpio = gpiod_get_index(&pdev->dev, NULL, n,
> > - GPIOD_OUT_LOW);
> > - if (IS_ERR(gpio)) {
> > - r = PTR_ERR(gpio);
> > - goto err;
> > - }
> > - s->gpio[n] = gpio;
> > - n++;
> > - }
> > + r = gpiod_get_array(&pdev->dev, NULL, s->gpio, num_gpios,
> > + GPIOD_OUT_LOW);
> > + if (r != num_gpios)
> > + return r;
> >
> > r = mdio_mux_init(&pdev->dev,
> > mdio_mux_gpio_switch_fn, &s->mux_handle, s);
> > @@ -80,22 +73,17 @@ static int mdio_mux_gpio_probe(struct platform_device *pdev)
> > if (r == 0) {
> > pdev->dev.platform_data = s;
> > return 0;
> > + } else {
> > + gpiod_put_array(s->gpio, num_gpios);
> > + return r;
> > }
>
> Suggestion: handle the errors in the if condition, and let normal
> execution be visible at the first level of indentation of the
> function. I.e:
>
> if (r != 0) {
> gpiod_put_array(s->gpio, num_gpios);
> return r;
> }
>
> pdev->dev.platform_data = s;
> return 0;
>
> This is how previous errors are handled in this function and is
> generally a good thing to do as it makes the function's logic easier
> to follow.
>
Ok, will do.
Thanks for the review.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-01-14 13:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-09 15:19 [PATCH 2/2] mdio-mux-gpio: use new gpiod_get_array and gpiod_put_array functions Rojhalat Ibrahim
2015-01-14 5:11 ` Alexandre Courbot
2015-01-14 13:01 ` Rojhalat Ibrahim
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).