From e4643104b793451501c3b8463ad1425e0c39da0d Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Tue, 10 Nov 2020 19:12:11 +0100 Subject: [PATCH] core: provide gpiod_line_bulk_reset() Provide a helper function that allows to reset an existing bulk object. Signed-off-by: Bartosz Golaszewski --- 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..2f4d3e4 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_reset(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..23c2047 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_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); -- 2.30.2