diff mbox series

[v1,2/2] gpiolib: Switch to bitmap_alloc()

Message ID 20210525183518.63149-2-andriy.shevchenko@linux.intel.com
State Accepted
Commit c354c29524eeabba63da51f30a09b85ec9dc853a
Headers show
Series [v1,1/2] gpiolib: Split fastpath array to two | expand

Commit Message

Andy Shevchenko May 25, 2021, 6:35 p.m. UTC
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(-)

Comments

Linus Walleij May 28, 2021, 12:41 a.m. UTC | #1
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
Bartosz Golaszewski May 28, 2021, 2:15 p.m. UTC | #2
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
diff mbox series

Patch

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;
 }