linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/2] gpiolib: Split fastpath array to two
@ 2021-05-25 18:35 Andy Shevchenko
  2021-05-25 18:35 ` [PATCH v1 2/2] gpiolib: Switch to bitmap_alloc() Andy Shevchenko
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Andy Shevchenko @ 2021-05-25 18:35 UTC (permalink / raw)
  To: Kent Gibson, linux-gpio, linux-kernel
  Cc: Linus Walleij, Bartosz Golaszewski, Andy Shevchenko

Split fastpath array to two, i.e. for mask and for bits.
At the same time declare them as bitmaps.

This makes code better to read and gives a clue about use of
bitmap API.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/gpio/gpiolib.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 97a69362a584..79df075f8b82 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2540,21 +2540,24 @@ int gpiod_get_array_value_complex(bool raw, bool can_sleep,
 
 	while (i < array_size) {
 		struct gpio_chip *gc = desc_array[i]->gdev->chip;
-		unsigned long fastpath[2 * BITS_TO_LONGS(FASTPATH_NGPIO)];
+		DECLARE_BITMAP(fastpath_mask, FASTPATH_NGPIO);
+		DECLARE_BITMAP(fastpath_bits, FASTPATH_NGPIO);
 		unsigned long *mask, *bits;
 		int first, j;
 
 		if (likely(gc->ngpio <= FASTPATH_NGPIO)) {
-			mask = fastpath;
+			mask = fastpath_mask;
+			bits = fastpath_bits;
 		} else {
 			mask = kmalloc_array(2 * BITS_TO_LONGS(gc->ngpio),
 					   sizeof(*mask),
 					   can_sleep ? GFP_KERNEL : GFP_ATOMIC);
 			if (!mask)
 				return -ENOMEM;
+
+			bits = mask + BITS_TO_LONGS(gc->ngpio);
 		}
 
-		bits = mask + BITS_TO_LONGS(gc->ngpio);
 		bitmap_zero(mask, gc->ngpio);
 
 		if (!can_sleep)
@@ -2577,7 +2580,7 @@ int gpiod_get_array_value_complex(bool raw, bool can_sleep,
 
 		ret = gpio_chip_get_multiple(gc, mask, bits);
 		if (ret) {
-			if (mask != fastpath)
+			if (mask != fastpath_mask)
 				kfree(mask);
 			return ret;
 		}
@@ -2598,7 +2601,7 @@ int gpiod_get_array_value_complex(bool raw, bool can_sleep,
 						       j);
 		}
 
-		if (mask != fastpath)
+		if (mask != fastpath_mask)
 			kfree(mask);
 	}
 	return 0;
@@ -2823,21 +2826,24 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep,
 
 	while (i < array_size) {
 		struct gpio_chip *gc = desc_array[i]->gdev->chip;
-		unsigned long fastpath[2 * BITS_TO_LONGS(FASTPATH_NGPIO)];
+		DECLARE_BITMAP(fastpath_mask, FASTPATH_NGPIO);
+		DECLARE_BITMAP(fastpath_bits, FASTPATH_NGPIO);
 		unsigned long *mask, *bits;
 		int count = 0;
 
 		if (likely(gc->ngpio <= FASTPATH_NGPIO)) {
-			mask = fastpath;
+			mask = fastpath_mask;
+			bits = fastpath_bits;
 		} else {
 			mask = kmalloc_array(2 * BITS_TO_LONGS(gc->ngpio),
 					   sizeof(*mask),
 					   can_sleep ? GFP_KERNEL : GFP_ATOMIC);
 			if (!mask)
 				return -ENOMEM;
+
+			bits = mask + BITS_TO_LONGS(gc->ngpio);
 		}
 
-		bits = mask + BITS_TO_LONGS(gc->ngpio);
 		bitmap_zero(mask, gc->ngpio);
 
 		if (!can_sleep)
@@ -2882,7 +2888,7 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep,
 		if (count != 0)
 			gpio_chip_set_multiple(gc, mask, bits);
 
-		if (mask != fastpath)
+		if (mask != fastpath_mask)
 			kfree(mask);
 	}
 	return 0;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v1 2/2] gpiolib: Switch to bitmap_alloc()
  2021-05-25 18:35 [PATCH v1 1/2] gpiolib: Split fastpath array to two Andy Shevchenko
@ 2021-05-25 18:35 ` Andy Shevchenko
  2021-05-28  0:41   ` Linus Walleij
  2021-05-28 14:15   ` Bartosz Golaszewski
  2021-05-28  0:40 ` [PATCH v1 1/2] gpiolib: Split fastpath array to two Linus Walleij
  2021-05-28 14:16 ` Bartosz Golaszewski
  2 siblings, 2 replies; 6+ messages in thread
From: Andy Shevchenko @ 2021-05-25 18:35 UTC (permalink / raw)
  To: Kent Gibson, linux-gpio, linux-kernel
  Cc: Linus Walleij, Bartosz Golaszewski, Andy Shevchenko

Switch to bitmap_alloc() to show clearly what we are allocating.
Besides that it returns pointer of bitmap type instead of opaque void *.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/gpio/gpiolib.c | 36 +++++++++++++++++++++++++-----------
 1 file changed, 25 insertions(+), 11 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 79df075f8b82..068f18624da0 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2549,13 +2549,17 @@ int gpiod_get_array_value_complex(bool raw, bool can_sleep,
 			mask = fastpath_mask;
 			bits = fastpath_bits;
 		} else {
-			mask = kmalloc_array(2 * BITS_TO_LONGS(gc->ngpio),
-					   sizeof(*mask),
-					   can_sleep ? GFP_KERNEL : GFP_ATOMIC);
+			gfp_t flags = can_sleep ? GFP_KERNEL : GFP_ATOMIC;
+
+			mask = bitmap_alloc(gc->ngpio, flags);
 			if (!mask)
 				return -ENOMEM;
 
-			bits = mask + BITS_TO_LONGS(gc->ngpio);
+			bits = bitmap_alloc(gc->ngpio, flags);
+			if (!bits) {
+				bitmap_free(mask);
+				return -ENOMEM;
+			}
 		}
 
 		bitmap_zero(mask, gc->ngpio);
@@ -2581,7 +2585,9 @@ int gpiod_get_array_value_complex(bool raw, bool can_sleep,
 		ret = gpio_chip_get_multiple(gc, mask, bits);
 		if (ret) {
 			if (mask != fastpath_mask)
-				kfree(mask);
+				bitmap_free(mask);
+			if (bits != fastpath_bits)
+				bitmap_free(bits);
 			return ret;
 		}
 
@@ -2602,7 +2608,9 @@ int gpiod_get_array_value_complex(bool raw, bool can_sleep,
 		}
 
 		if (mask != fastpath_mask)
-			kfree(mask);
+			bitmap_free(mask);
+		if (bits != fastpath_bits)
+			bitmap_free(bits);
 	}
 	return 0;
 }
@@ -2835,13 +2843,17 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep,
 			mask = fastpath_mask;
 			bits = fastpath_bits;
 		} else {
-			mask = kmalloc_array(2 * BITS_TO_LONGS(gc->ngpio),
-					   sizeof(*mask),
-					   can_sleep ? GFP_KERNEL : GFP_ATOMIC);
+			gfp_t flags = can_sleep ? GFP_KERNEL : GFP_ATOMIC;
+
+			mask = bitmap_alloc(gc->ngpio, flags);
 			if (!mask)
 				return -ENOMEM;
 
-			bits = mask + BITS_TO_LONGS(gc->ngpio);
+			bits = bitmap_alloc(gc->ngpio, flags);
+			if (!bits) {
+				bitmap_free(mask);
+				return -ENOMEM;
+			}
 		}
 
 		bitmap_zero(mask, gc->ngpio);
@@ -2889,7 +2901,9 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep,
 			gpio_chip_set_multiple(gc, mask, bits);
 
 		if (mask != fastpath_mask)
-			kfree(mask);
+			bitmap_free(mask);
+		if (bits != fastpath_bits)
+			bitmap_free(bits);
 	}
 	return 0;
 }
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v1 1/2] gpiolib: Split fastpath array to two
  2021-05-25 18:35 [PATCH v1 1/2] gpiolib: Split fastpath array to two Andy Shevchenko
  2021-05-25 18:35 ` [PATCH v1 2/2] gpiolib: Switch to bitmap_alloc() Andy Shevchenko
@ 2021-05-28  0:40 ` Linus Walleij
  2021-05-28 14:16 ` Bartosz Golaszewski
  2 siblings, 0 replies; 6+ messages in thread
From: Linus Walleij @ 2021-05-28  0:40 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Kent Gibson, open list:GPIO SUBSYSTEM, linux-kernel, Bartosz Golaszewski

On Tue, May 25, 2021 at 8:35 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:

> Split fastpath array to two, i.e. for mask and for bits.
> At the same time declare them as bitmaps.
>
> This makes code better to read and gives a clue about use of
> bitmap API.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Excellent code!

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1 2/2] gpiolib: Switch to bitmap_alloc()
  2021-05-25 18:35 ` [PATCH v1 2/2] gpiolib: Switch to bitmap_alloc() Andy Shevchenko
@ 2021-05-28  0:41   ` Linus Walleij
  2021-05-28 14:15   ` Bartosz Golaszewski
  1 sibling, 0 replies; 6+ messages in thread
From: Linus Walleij @ 2021-05-28  0:41 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Kent Gibson, open list:GPIO SUBSYSTEM, linux-kernel, Bartosz Golaszewski

On Tue, May 25, 2021 at 8:35 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:

> Switch to bitmap_alloc() to show clearly what we are allocating.
> Besides that it returns pointer of bitmap type instead of opaque void *.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1 2/2] gpiolib: Switch to bitmap_alloc()
  2021-05-25 18:35 ` [PATCH v1 2/2] gpiolib: Switch to bitmap_alloc() Andy Shevchenko
  2021-05-28  0:41   ` Linus Walleij
@ 2021-05-28 14:15   ` Bartosz Golaszewski
  1 sibling, 0 replies; 6+ messages in thread
From: Bartosz Golaszewski @ 2021-05-28 14:15 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Kent Gibson, linux-gpio, LKML, Linus Walleij

On Tue, May 25, 2021 at 8:35 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> Switch to bitmap_alloc() to show clearly what we are allocating.
> Besides that it returns pointer of bitmap type instead of opaque void *.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---

Applied, thanks!

Bart

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1 1/2] gpiolib: Split fastpath array to two
  2021-05-25 18:35 [PATCH v1 1/2] gpiolib: Split fastpath array to two Andy Shevchenko
  2021-05-25 18:35 ` [PATCH v1 2/2] gpiolib: Switch to bitmap_alloc() Andy Shevchenko
  2021-05-28  0:40 ` [PATCH v1 1/2] gpiolib: Split fastpath array to two Linus Walleij
@ 2021-05-28 14:16 ` Bartosz Golaszewski
  2 siblings, 0 replies; 6+ messages in thread
From: Bartosz Golaszewski @ 2021-05-28 14:16 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Kent Gibson, linux-gpio, LKML, Linus Walleij

On Tue, May 25, 2021 at 8:35 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> Split fastpath array to two, i.e. for mask and for bits.
> At the same time declare them as bitmaps.
>
> This makes code better to read and gives a clue about use of
> bitmap API.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---

Applied, thanks!

Bart

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-05-28 14:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-25 18:35 [PATCH v1 1/2] gpiolib: Split fastpath array to two Andy Shevchenko
2021-05-25 18:35 ` [PATCH v1 2/2] gpiolib: Switch to bitmap_alloc() Andy Shevchenko
2021-05-28  0:41   ` Linus Walleij
2021-05-28 14:15   ` Bartosz Golaszewski
2021-05-28  0:40 ` [PATCH v1 1/2] gpiolib: Split fastpath array to two Linus Walleij
2021-05-28 14:16 ` Bartosz Golaszewski

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).