From: Bartosz Golaszewski Date: Thu, 28 Sep 2017 07:54:10 +0000 (+0200) Subject: core: implement gpiod_line_close_chip() X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=7a9dae7e32d58b3d52d40de5adfeb631b9d6dbaf;p=qemu-gpiodev%2Flibgpiod.git core: implement gpiod_line_close_chip() This function works nicely with gpiod_line_find_by_name() which returns a line object whose owning chip must be later freed by the caller. With this routine the caller can skip creating a temporary chip object. Signed-off-by: Bartosz Golaszewski --- diff --git a/include/gpiod.h b/include/gpiod.h index 6853884..506f3e4 100644 --- a/include/gpiod.h +++ b/include/gpiod.h @@ -877,6 +877,14 @@ int gpiod_line_set_value_bulk(struct gpiod_line_bulk *bulk, */ struct gpiod_line * gpiod_line_find_by_name(const char *name) GPIOD_API; +/** + * @brief Close a GPIO chip owning this line and release all resources. + * @param line GPIO line object + * + * After this function returns, the line must no longer be used. + */ +void gpiod_line_close_chip(struct gpiod_line *line) GPIOD_API; + /** * @brief Get the handle to the GPIO chip controlling this line. * @param line The GPIO line object. diff --git a/src/lib/core.c b/src/lib/core.c index a19ed57..2dc78b4 100644 --- a/src/lib/core.c +++ b/src/lib/core.c @@ -938,6 +938,13 @@ struct gpiod_line * gpiod_line_find_by_name(const char *name) return NULL; } +void gpiod_line_close_chip(struct gpiod_line *line) +{ + struct gpiod_chip *chip = gpiod_line_get_chip(line); + + gpiod_chip_close(chip); +} + int gpiod_line_event_wait(struct gpiod_line *line, const struct timespec *timeout) {