bulk: drop the limit on the max number of lines
authorBartosz Golaszewski <bgolaszewski@baylibre.com>
Tue, 24 Nov 2020 15:24:08 +0000 (16:24 +0100)
committerBartosz Golaszewski <bgolaszewski@baylibre.com>
Mon, 14 Dec 2020 14:56:40 +0000 (15:56 +0100)
The limit of 64 lines max per bulk object is wrong. We may want to
retrieve all lines from a chip exporting more than 64. We'll be reducing
the role of bulk objects soon so drop this limit now.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
bindings/cxx/line_bulk.cpp
bindings/python/gpiodmodule.c
include/gpiod.h
lib/core.c
tests/tests-bulk.c
tools/gpiomon.c

index 1de90eb806b92734948fb827ab2e1fc9b6693615..6e88d21c892d30934fdd7213a819cfcc28369b0a 100644 (file)
@@ -48,7 +48,7 @@ const ::std::map<::std::bitset<32>, int, bitset_cmp> reqflag_mapping = {
 
 } /* namespace */
 
-const unsigned int line_bulk::MAX_LINES = GPIOD_LINE_BULK_MAX_LINES;
+const unsigned int line_bulk::MAX_LINES = 64;
 
 line_bulk::line_bulk(const ::std::vector<line>& lines)
        : _m_bulk()
index b5e69a5c74082c139622c3d9787a71457769a54d..b9b57703eb256733e29addd10d991f40d33c74eb 100644 (file)
@@ -8,6 +8,8 @@
 #include <Python.h>
 #include <gpiod.h>
 
+#define LINE_REQUEST_MAX_LINES 64
+
 typedef struct {
        PyObject_HEAD
        struct gpiod_chip *chip;
@@ -1138,7 +1140,7 @@ static int gpiod_LineBulk_init(gpiod_LineBulkObject *self,
                                "Argument must be a non-empty sequence");
                return -1;
        }
-       if (self->num_lines > GPIOD_LINE_BULK_MAX_LINES) {
+       if (self->num_lines > LINE_REQUEST_MAX_LINES) {
                PyErr_SetString(PyExc_TypeError,
                                "Too many objects in the sequence");
                return -1;
@@ -1334,7 +1336,7 @@ static PyObject *gpiod_LineBulk_request(gpiod_LineBulkObject *self,
                                  NULL };
 
        int rv, type = gpiod_LINE_REQ_DIR_AS_IS, flags = 0,
-           default_vals[GPIOD_LINE_BULK_MAX_LINES], val;
+           default_vals[LINE_REQUEST_MAX_LINES], val;
        PyObject *def_vals_obj = NULL, *iter, *next;
        struct gpiod_line_request_config conf;
        struct gpiod_line_bulk *bulk;
@@ -1413,7 +1415,7 @@ PyDoc_STRVAR(gpiod_LineBulk_get_values_doc,
 static PyObject *gpiod_LineBulk_get_values(gpiod_LineBulkObject *self,
                                           PyObject *Py_UNUSED(ignored))
 {
-       int rv, vals[GPIOD_LINE_BULK_MAX_LINES];
+       int rv, vals[LINE_REQUEST_MAX_LINES];
        struct gpiod_line_bulk *bulk;
        PyObject *val_list, *val;
        Py_ssize_t i;
@@ -1506,7 +1508,7 @@ PyDoc_STRVAR(gpiod_LineBulk_set_values_doc,
 static PyObject *gpiod_LineBulk_set_values(gpiod_LineBulkObject *self,
                                           PyObject *args)
 {
-       int rv, vals[GPIOD_LINE_BULK_MAX_LINES];
+       int rv, vals[LINE_REQUEST_MAX_LINES];
        struct gpiod_line_bulk *bulk;
        PyObject *val_list;
 
@@ -1556,7 +1558,7 @@ PyDoc_STRVAR(gpiod_LineBulk_set_config_doc,
 static PyObject *gpiod_LineBulk_set_config(gpiod_LineBulkObject *self,
                                           PyObject *args)
 {
-       int rv, vals[GPIOD_LINE_BULK_MAX_LINES];
+       int rv, vals[LINE_REQUEST_MAX_LINES];
        struct gpiod_line_bulk *bulk;
        PyObject *val_list;
        const int *valp;
@@ -1672,7 +1674,7 @@ static PyObject *gpiod_LineBulk_set_direction_output(
                                gpiod_LineBulkObject *self,
                                PyObject *args)
 {
-       int rv, vals[GPIOD_LINE_BULK_MAX_LINES];
+       int rv, vals[LINE_REQUEST_MAX_LINES];
        struct gpiod_line_bulk *bulk;
        PyObject *val_list;
        const int *valp;
index 742dfc250e699456a92ff49c924d01b65c653e9c..9ffb446b45f8cc0420a9f561e01824d924a0804b 100644 (file)
@@ -225,17 +225,10 @@ gpiod_chip_find_lines(struct gpiod_chip *chip, const char **names) GPIOD_API;
  * on multiple lines at once.
  */
 
-/**
- * @brief Maximum number of GPIO lines that can be requested at once or stored
- *        in a line bulk object at the same time.
- */
-#define GPIOD_LINE_BULK_MAX_LINES      64
-
 /**
  * @brief Allocate and initialize a new line bulk object.
  * @param max_lines Maximum number of lines this object can hold.
  * @return New line bulk object or NULL on error.
- * @note max_lines must not exceed ::GPIOD_LINE_BULK_MAX_LINES.
  */
 struct gpiod_line_bulk *gpiod_line_bulk_new(unsigned int max_lines) GPIOD_API;
 
index efba959b27fead83dbe4a8c9bed66bdf4b014a8e..d96e6cfb5ece62fcf199089cf9bf64c7b07149e6 100644 (file)
@@ -22,6 +22,8 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#define LINE_REQUEST_MAX_LINES 64
+
 enum {
        LINE_FREE = 0,
        LINE_REQUESTED_VALUES,
@@ -94,7 +96,7 @@ struct gpiod_line_bulk *gpiod_line_bulk_new(unsigned int max_lines)
        struct gpiod_line_bulk *bulk;
        size_t size;
 
-       if (max_lines < 1 || max_lines > GPIOD_LINE_BULK_MAX_LINES) {
+       if (max_lines == 0) {
                errno = EINVAL;
                return NULL;
        }
@@ -1066,7 +1068,7 @@ int gpiod_line_set_flags(struct gpiod_line *line, int flags)
 int gpiod_line_set_flags_bulk(struct gpiod_line_bulk *bulk, int flags)
 {
        struct gpiod_line *line;
-       int values[GPIOD_LINE_BULK_MAX_LINES];
+       int values[LINE_REQUEST_MAX_LINES];
        unsigned int i;
        int direction;
 
@@ -1129,7 +1131,7 @@ int gpiod_line_event_wait_bulk(struct gpiod_line_bulk *bulk,
                               const struct timespec *timeout,
                               struct gpiod_line_bulk *event_bulk)
 {
-       struct pollfd fds[GPIOD_LINE_BULK_MAX_LINES];
+       struct pollfd fds[LINE_REQUEST_MAX_LINES];
        unsigned int off, num_lines;
        struct gpiod_line *line;
        int rv;
index e2520fc8942a6ad541c3078a9378865b13458c7d..22cae8414a624d1d0d81adefdb41a34be981c205 100644 (file)
@@ -20,15 +20,6 @@ GPIOD_TEST_CASE(alloc_zero_lines, 0, { 1 })
        g_assert_cmpint(errno, ==, EINVAL);
 }
 
-GPIOD_TEST_CASE(alloc_too_many_lines, 0, { 1 })
-{
-       struct gpiod_line_bulk *bulk;
-
-       bulk = gpiod_line_bulk_new(GPIOD_LINE_BULK_MAX_LINES + 1);
-       g_assert_null(bulk);
-       g_assert_cmpint(errno, ==, EINVAL);
-}
-
 GPIOD_TEST_CASE(add_too_many_lines, 0, { 8 })
 {
        g_autoptr(gpiod_line_bulk_struct) bulk = NULL;
index 44fb431264587624ebece79d604d3c0d3175b98c..c271913d68eea04b57f89a51388969b9a0b511d0 100644 (file)
@@ -157,7 +157,7 @@ static void handle_signal(int signum UNUSED)
 
 int main(int argc, char **argv)
 {
-       unsigned int offsets[GPIOD_LINE_BULK_MAX_LINES], num_lines = 0, offset,
+       unsigned int offsets[64], num_lines = 0, offset,
                     events_wanted = 0, events_done = 0, x;
        bool watch_rising = false, watch_falling = false;
        int flags = 0;
@@ -241,6 +241,9 @@ int main(int argc, char **argv)
        if (argc < 2)
                die("at least one GPIO line offset must be specified");
 
+       if (argc > 65)
+               die("too many offsets given");
+
        for (i = 1; i < argc; i++) {
                offset = strtoul(argv[i], &end, 10);
                if (*end != '\0' || offset > INT_MAX)