linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Kent Gibson <warthog618@gmail.com>,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Linus Walleij <linus.walleij@linaro.org>,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v1 2/2] gpiolib: Switch to bitmap_alloc()
Date: Tue, 25 May 2021 21:35:18 +0300	[thread overview]
Message-ID: <20210525183518.63149-2-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20210525183518.63149-1-andriy.shevchenko@linux.intel.com>

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


  reply	other threads:[~2021-05-25 18:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-25 18:35 [PATCH v1 1/2] gpiolib: Split fastpath array to two Andy Shevchenko
2021-05-25 18:35 ` Andy Shevchenko [this message]
2021-05-28  0:41   ` [PATCH v1 2/2] gpiolib: Switch to bitmap_alloc() 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210525183518.63149-2-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=warthog618@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).