From: Bartosz Golaszewski Date: Wed, 28 Jun 2017 14:39:36 +0000 (+0200) Subject: core: kill gpiod_line_event_release() X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=0799d0b9349d11c36e565bf8e733593f9e5c86af;p=qemu-gpiodev%2Flibgpiod.git core: kill gpiod_line_event_release() We can (and already do in gpiod_chip_close()) easily figure out if a GPIO line was configured for events or values, so there's no need to have a separate release function for events. Signed-off-by: Bartosz Golaszewski --- diff --git a/include/gpiod.h b/include/gpiod.h index 9a0863b..d2e6204 100644 --- a/include/gpiod.h +++ b/include/gpiod.h @@ -620,12 +620,6 @@ int gpiod_line_event_request_all(struct gpiod_line *line, const char *consumer, bool active_low) GPIOD_API; -/** - * @brief Stop listening for events and release the line. - * @param line GPIO line object. - */ -void gpiod_line_event_release(struct gpiod_line *line) GPIOD_API; - /** * @brief Check if event notifications are configured on this line. * @param line GPIO line object. diff --git a/src/lib/core.c b/src/lib/core.c index 27ccbe8..dd7e188 100644 --- a/src/lib/core.c +++ b/src/lib/core.c @@ -395,9 +395,18 @@ void gpiod_line_release_bulk(struct gpiod_line_bulk *bulk) for (i = 0; i < bulk->num_lines; i++) { line = bulk->lines[i]; - line_remove_handle(line); + if (line_get_state(line) == LINE_TAKEN) + line_remove_handle(line); + else if (line_get_state(line) == LINE_EVENT) + close(line_get_event_fd(line)); + line_set_state(line, LINE_FREE); - line_maybe_update(line); + /* + * FIXME This is a temporary check before we add a better way + * to determine whether a line object is valid. + */ + if (line->chip) + line_maybe_update(line); } } @@ -611,12 +620,6 @@ int gpiod_line_event_request_all(struct gpiod_line *line, GPIOD_EVENT_BOTH_EDGES); } -void gpiod_line_event_release(struct gpiod_line *line) -{ - close(line_get_event_fd(line)); - line_set_state(line, LINE_FREE); -} - bool gpiod_line_event_configured(struct gpiod_line *line) { return line_get_state(line) == LINE_EVENT; @@ -827,17 +830,10 @@ struct gpiod_chip * gpiod_chip_open_lookup(const char *descr) void gpiod_chip_close(struct gpiod_chip *chip) { - struct gpiod_line *line; unsigned int i; - for (i = 0; i < chip->cinfo.lines; i++) { - line = &chip->lines[i]; - - if (line_get_state(line) == LINE_TAKEN) - gpiod_line_release(line); - else if (line_get_state(line) == LINE_EVENT) - gpiod_line_event_release(line); - } + for (i = 0; i < chip->cinfo.lines; i++) + gpiod_line_release(&chip->lines[i]); close(chip->fd); free(chip->lines); diff --git a/src/lib/simple.c b/src/lib/simple.c index 88d879d..bcf3c06 100644 --- a/src/lib/simple.c +++ b/src/lib/simple.c @@ -183,7 +183,7 @@ int gpiod_simple_event_loop(const char *consumer, const char *device, } out: - gpiod_line_event_release(line); + gpiod_line_release(line); gpiod_chip_close(chip); return status;