core: new error number
authorBartosz Golaszewski <bartekgola@gmail.com>
Tue, 17 Jan 2017 08:42:55 +0000 (09:42 +0100)
committerBartosz Golaszewski <bartekgola@gmail.com>
Tue, 17 Jan 2017 08:42:55 +0000 (09:42 +0100)
Introduce an error number indicating that the caller tried to request
too many lines at once. This is only relevant for the 'simple' API, as
the bulk operations are limited by the bulk buffer size.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
include/gpiod.h
src/lib/core.c

index 59f0b22689ee980ede485b3135501b73db51b263..ca0e81dd39035c60502487afc2934c3d88911479 100644 (file)
@@ -85,6 +85,8 @@ enum {
        /**< Not all lines in bulk belong to the same GPIO chip. */
        GPIOD_ELINEBUSY,
        /**< This line is currently in use. */
+       GPIOD_ELINEMAX,
+       /**< Number of lines in the request exceeds limit. */
        __GPIOD_MAX_ERR,
        /**< Private: number of libgpiod-specific error numbers. */
 };
index 9ec925fb8803ca5745483d31b6a9b551709fc13d..e3e5f74e5536d577562f72a088ea5760ad96aa94 100644 (file)
@@ -85,6 +85,7 @@ static const char *const error_descr[] = {
        "no events configured on GPIO line",
        "GPIO lines in bulk don't belong to the same gpiochip",
        "GPIO line currently in use",
+       "number of lines in the request exceeds limit",
 };
 
 static void set_last_error(int errnum)
@@ -168,6 +169,11 @@ int gpiod_simple_get_value_multiple(const char *device, unsigned int *offsets,
        unsigned int i;
        int status;
 
+       if (num_lines > GPIOD_REQUEST_MAX_LINES) {
+               set_last_error(GPIOD_ELINEMAX);
+               return -1;
+       }
+
        chip = gpiod_chip_open_lookup(device);
        if (!chip)
                return -1;
@@ -211,6 +217,11 @@ int gpiod_simple_set_value_multiple(const char *device, unsigned int *offsets,
        unsigned int i;
        int status;
 
+       if (num_lines > GPIOD_REQUEST_MAX_LINES) {
+               set_last_error(GPIOD_ELINEMAX);
+               return -1;
+       }
+
        chip = gpiod_chip_open_lookup(device);
        if (!chip)
                return -1;