From 8233cead3c2dab25c5324405fa5a2f8891d53584 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Mon, 9 Jan 2017 15:10:13 +0100 Subject: [PATCH] core: extend verify_line_bulk() Make verify_line_bulk() set the last error number (according to the error condition) and verify if any line is busy too. Signed-off-by: Bartosz Golaszewski --- core.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/core.c b/core.c index bd1db6e..eff1e68 100644 --- a/core.c +++ b/core.c @@ -331,8 +331,15 @@ static bool verify_line_bulk(struct gpiod_line_bulk *line_bulk) chip = gpiod_line_get_chip(line_bulk->lines[0]); for (i = 1; i < line_bulk->num_lines; i++) { - if (chip != gpiod_line_get_chip(line_bulk->lines[i])) + if (chip != gpiod_line_get_chip(line_bulk->lines[i])) { + set_last_error(GPIOD_EBULKINCOH); return false; + } + + if (!gpiod_line_is_free(line_bulk->lines[i])) { + set_last_error(GPIOD_ELINEBUSY); + return false; + } } return true; @@ -348,10 +355,8 @@ int gpiod_line_request_bulk(struct gpiod_line_bulk *line_bulk, int status, fd; unsigned int i; - if (!verify_line_bulk(line_bulk)) { - set_last_error(GPIOD_EBULKINCOH); + if (!verify_line_bulk(line_bulk)) return -1; - } req = zalloc(sizeof(*req)); if (!req) -- 2.30.2