diff mbox series

[4.4.y,18/52] gpiolib: Extract mask allocation into subroutine

Message ID 1557761837-24993-19-git-send-email-fabrizio.castro@bp.renesas.com (mailing list archive)
State Accepted
Headers show
Series Add basic support for the iwg23s | expand

Commit Message

Fabrizio Castro May 13, 2019, 3:36 p.m. UTC
From: Stephen Boyd <swboyd@chromium.org>

commit e4371f6e079294369ecb4cfa03aaeb60831e8b91 upstream.

We're going to use similar code to allocate and set all the bits in a
mask for valid gpios to use. Extract the code from the irqchip version
so it can be reused.

Signed-off-by: Stephen Boyd <swboyd@chromium.org>
Tested-by: Timur Tabi <timur@codeaurora.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
[fab: removed change from function gpiochip_irqchip_init_valid_mask]
Signed-off-by: Fabrizio Castro <fabrizio.castro@bp.renesas.com>
---
 drivers/gpio/gpiolib.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Comments

Pavel Machek May 13, 2019, 7:44 p.m. UTC | #1
On Mon 2019-05-13 16:36:43, Fabrizio Castro wrote:
> From: Stephen Boyd <swboyd@chromium.org>
> 
> commit e4371f6e079294369ecb4cfa03aaeb60831e8b91 upstream.
> 
> We're going to use similar code to allocate and set all the bits in a
> mask for valid gpios to use. Extract the code from the irqchip version
> so it can be reused.
...
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -279,6 +279,20 @@ static int gpiochip_set_desc_names(struct gpio_chip *gc)
>  	return 0;
>  }
>  
> +static unsigned long *gpiochip_allocate_mask(struct gpio_chip *chip)
> +{
> +	unsigned long *p;
> +
> +	p = kcalloc(BITS_TO_LONGS(chip->ngpio), sizeof(long), GFP_KERNEL);
> +	if (!p)
> +		return NULL;
> +
> +	/* Assume by default all GPIOs are valid */
> +	bitmap_fill(p, chip->ngpio);
> +
> +	return p;
> +}

I'd do

    if (p)
         bitmap_fill();

    return p;

But it is not that important.
									Pavel
Fabrizio Castro May 14, 2019, 9:25 a.m. UTC | #2
Hi Pavel,

Thank you for your feedback!

> From: Pavel Machek <pavel@denx.de>
> Sent: 13 May 2019 20:45
> Subject: Re: [cip-dev] [PATCH 4.4.y 18/52] gpiolib: Extract mask allocation into subroutine
> 
> On Mon 2019-05-13 16:36:43, Fabrizio Castro wrote:
> > From: Stephen Boyd <swboyd@chromium.org>
> >
> > commit e4371f6e079294369ecb4cfa03aaeb60831e8b91 upstream.
> >
> > We're going to use similar code to allocate and set all the bits in a
> > mask for valid gpios to use. Extract the code from the irqchip version
> > so it can be reused.
> ...
> > --- a/drivers/gpio/gpiolib.c
> > +++ b/drivers/gpio/gpiolib.c
> > @@ -279,6 +279,20 @@ static int gpiochip_set_desc_names(struct gpio_chip *gc)
> >  	return 0;
> >  }
> >
> > +static unsigned long *gpiochip_allocate_mask(struct gpio_chip *chip)
> > +{
> > +	unsigned long *p;
> > +
> > +	p = kcalloc(BITS_TO_LONGS(chip->ngpio), sizeof(long), GFP_KERNEL);
> > +	if (!p)
> > +		return NULL;
> > +
> > +	/* Assume by default all GPIOs are valid */
> > +	bitmap_fill(p, chip->ngpio);
> > +
> > +	return p;
> > +}
> 
> I'd do
> 
>     if (p)
>          bitmap_fill();
> 
>     return p;
> 
> But it is not that important.

I could send an additional patch for this if you'd like?
Just let me know.

Thanks,
Fab

> 									Pavel
> --
> (english) http://www.livejournal.com/~pavelmachek
> (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
diff mbox series

Patch

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 827510d..0e4e753 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -279,6 +279,20 @@  static int gpiochip_set_desc_names(struct gpio_chip *gc)
 	return 0;
 }
 
+static unsigned long *gpiochip_allocate_mask(struct gpio_chip *chip)
+{
+	unsigned long *p;
+
+	p = kcalloc(BITS_TO_LONGS(chip->ngpio), sizeof(long), GFP_KERNEL);
+	if (!p)
+		return NULL;
+
+	/* Assume by default all GPIOs are valid */
+	bitmap_fill(p, chip->ngpio);
+
+	return p;
+}
+
 /**
  * gpiochip_add_data() - register a gpio_chip
  * @chip: the chip to register, with chip->base initialized