core: provide gpiod_line_bulk_reset()
authorBartosz Golaszewski <bgolaszewski@baylibre.com>
Tue, 10 Nov 2020 18:12:11 +0000 (19:12 +0100)
committerBartosz Golaszewski <bgolaszewski@baylibre.com>
Wed, 18 Nov 2020 08:22:06 +0000 (09:22 +0100)
Provide a helper function that allows to reset an existing bulk object.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
include/gpiod.h
lib/core.c

index 8276f6ab8f72fe01533e2dc6a42e41db7891f0d1..2f4d3e476ce9b18ece96395448bf18affb88a711 100644 (file)
@@ -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_reset(struct gpiod_line_bulk *bulk) GPIOD_API;
+
 /**
  * @brief Release all resources allocated for this bulk object.
  * @param bulk Bulk object to free.
index eb7d4997631c8c4388b64db41c87469b1e7a4e8a..23c2047401867d4af458dc0920108dbc8c0ec3b2 100644 (file)
@@ -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_reset(bulk);
 
        return bulk;
 }
 
+void gpiod_line_bulk_reset(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);