core: extend verify_line_bulk()
authorBartosz Golaszewski <bartekgola@gmail.com>
Mon, 9 Jan 2017 14:10:13 +0000 (15:10 +0100)
committerBartosz Golaszewski <bartekgola@gmail.com>
Mon, 9 Jan 2017 14:10:13 +0000 (15:10 +0100)
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 <bartekgola@gmail.com>
core.c

diff --git a/core.c b/core.c
index bd1db6e99dc38ee279c14791241f2a4c8f5d2ebe..eff1e68f34bc9343184490e0d2e47eb53f264518 100644 (file)
--- 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)