core: implement gpiod_line_close_chip()
authorBartosz Golaszewski <bartekgola@gmail.com>
Thu, 28 Sep 2017 07:54:10 +0000 (09:54 +0200)
committerBartosz Golaszewski <bartekgola@gmail.com>
Thu, 28 Sep 2017 07:54:10 +0000 (09:54 +0200)
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 <bartekgola@gmail.com>
include/gpiod.h
src/lib/core.c

index 6853884b2af886b993ebab4512af9a83dbc1427d..506f3e48fc578c7f0cf512e4ab03f6282edd5ebe 100644 (file)
@@ -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.
index a19ed57ca16aba00a39083d1283014589ffec016..2dc78b4e2ad5a2a7093b18d25421162ac6bd9393 100644 (file)
@@ -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)
 {