From: Bartosz Golaszewski Date: Tue, 17 Jan 2017 08:42:55 +0000 (+0100) Subject: core: new error number X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=17970104b59bb578af2d9032ab3bc26c75150959;p=qemu-gpiodev%2Flibgpiod.git core: new error number 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 --- diff --git a/include/gpiod.h b/include/gpiod.h index 59f0b22..ca0e81d 100644 --- a/include/gpiod.h +++ b/include/gpiod.h @@ -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. */ }; diff --git a/src/lib/core.c b/src/lib/core.c index 9ec925f..e3e5f74 100644 --- a/src/lib/core.c +++ b/src/lib/core.c @@ -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;