From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Kent Gibson <warthog618@gmail.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: linux-gpio@vger.kernel.org,
Bartosz Golaszewski <bgolaszewski@baylibre.com>
Subject: [libgpiod][PATCH 1/2] core: provide gpiod_line_bulk_clear()
Date: Thu, 12 Nov 2020 12:06:41 +0100 [thread overview]
Message-ID: <20201112110642.14903-2-brgl@bgdev.pl> (raw)
In-Reply-To: <20201112110642.14903-1-brgl@bgdev.pl>
From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Provide a helper function that allows to reset an existing bulk object.
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
include/gpiod.h | 6 ++++++
lib/core.c | 8 +++++++-
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/include/gpiod.h b/include/gpiod.h
index 8276f6a..7610eb1 100644
--- a/include/gpiod.h
+++ b/include/gpiod.h
@@ -649,6 +649,12 @@ gpiod_chip_find_lines(struct gpiod_chip *chip, const char **names) GPIOD_API;
*/
struct gpiod_line_bulk *gpiod_line_bulk_new(unsigned int max_lines) GPIOD_API;
+/**
+ * @brief Reset a bulk object. Remove all lines and set size to 0.
+ * @param bulk Bulk object to reset.
+ */
+void gpiod_line_bulk_clear(struct gpiod_line_bulk *bulk) GPIOD_API;
+
/**
* @brief Release all resources allocated for this bulk object.
* @param bulk Bulk object to free.
diff --git a/lib/core.c b/lib/core.c
index eb7d499..34f9017 100644
--- a/lib/core.c
+++ b/lib/core.c
@@ -106,12 +106,18 @@ struct gpiod_line_bulk *gpiod_line_bulk_new(unsigned int max_lines)
if (!bulk)
return NULL;
- memset(bulk, 0, size);
bulk->max_lines = max_lines;
+ gpiod_line_bulk_clear(bulk);
return bulk;
}
+void gpiod_line_bulk_clear(struct gpiod_line_bulk *bulk)
+{
+ bulk->num_lines = 0;
+ memset(bulk->lines, 0, bulk->max_lines * sizeof(struct line *));
+}
+
void gpiod_line_bulk_free(struct gpiod_line_bulk *bulk)
{
free(bulk);
--
2.29.1
next prev parent reply other threads:[~2020-11-12 11:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-12 11:06 [libgpiod][PATCH 0/2] treewide: remove ctxless API Bartosz Golaszewski
2020-11-12 11:06 ` Bartosz Golaszewski [this message]
2020-11-13 8:41 ` [libgpiod][PATCH 1/2] core: provide gpiod_line_bulk_clear() Bartosz Golaszewski
2020-11-12 11:06 ` [libgpiod][PATCH 2/2] ctxless: drop all context-less interfaces Bartosz Golaszewski
2020-11-17 14:00 ` [libgpiod][PATCH 0/2] treewide: remove ctxless API 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=20201112110642.14903-2-brgl@bgdev.pl \
--to=brgl@bgdev.pl \
--cc=andriy.shevchenko@linux.intel.com \
--cc=bgolaszewski@baylibre.com \
--cc=linux-gpio@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.