diff mbox series

[libgpiod,04/14] bulk: drop the limit on the max number of lines

Message ID 20201210132315.5785-5-brgl@bgdev.pl
State New
Headers show
Series treewide: start shaving off cruft for v2.0 | expand

Commit Message

Bartosz Golaszewski Dec. 10, 2020, 1:23 p.m. UTC
From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

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>
---
 bindings/cxx/line_bulk.cpp    |  2 +-
 bindings/python/gpiodmodule.c | 14 ++++++++------
 include/gpiod.h               |  7 -------
 lib/core.c                    |  8 +++++---
 tests/tests-bulk.c            |  9 ---------
 tools/gpiomon.c               |  5 ++++-
 6 files changed, 18 insertions(+), 27 deletions(-)
diff mbox series

Patch

diff --git a/bindings/cxx/line_bulk.cpp b/bindings/cxx/line_bulk.cpp
index 1de90eb..6e88d21 100644
--- a/bindings/cxx/line_bulk.cpp
+++ b/bindings/cxx/line_bulk.cpp
@@ -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()
diff --git a/bindings/python/gpiodmodule.c b/bindings/python/gpiodmodule.c
index b5e69a5..b9b5770 100644
--- a/bindings/python/gpiodmodule.c
+++ b/bindings/python/gpiodmodule.c
@@ -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;
diff --git a/include/gpiod.h b/include/gpiod.h
index 742dfc2..9ffb446 100644
--- a/include/gpiod.h
+++ b/include/gpiod.h
@@ -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;
 
diff --git a/lib/core.c b/lib/core.c
index efba959..d96e6cf 100644
--- a/lib/core.c
+++ b/lib/core.c
@@ -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;
diff --git a/tests/tests-bulk.c b/tests/tests-bulk.c
index e2520fc..22cae84 100644
--- a/tests/tests-bulk.c
+++ b/tests/tests-bulk.c
@@ -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;
diff --git a/tools/gpiomon.c b/tools/gpiomon.c
index 44fb431..c271913 100644
--- a/tools/gpiomon.c
+++ b/tools/gpiomon.c
@@ -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)