Skip to contentSkip to conversation

api tweaks

PATCH Applied Kent Gibson 2 participants 10 messages Mar 15, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover api tweaks

This series builds on my recent doc tweaks series, picking up a few things I missed there.

The first patch is another constistency renaming. This is the last one of these - this time I checked all the function names in gpiod.h to ensure all the functions follow the pattern.

The second is splitting chip_info out from chip. This is probably something you looked at before and decided against, but it bugs me that the core library is doing more than it should here.

The final one is a variable renaming for clarity. You use a "buf" suffix to indicate the uAPI version of structs. I find that confusing as to me buf implies an array of structs. I used a "u" for uAPI prefix instead, though on reflection "k" for kernel might be more visually distinct. There are other examples of this throughout the core - happy to do a respin including those - this one just fixes line-info.c to bring it into line with the corresponding chip-info.c introduced in the previous patch.

As with all my v2 patches, happy for you to apply them, or not, in whatever way you find appropriate.

Cheers,
Kent.

Kent Gibson (3):
core: rename gpiod_chip_info_event_wait and gpiod_chip_info_event_read
core: split chip_info out of chip
line-info: rename infobuf to uinfo

 include/gpiod.h            | 73 +++++++++++++++++++++++--------
 lib/Makefile.am            |  1 +
 lib/chip-info.c            | 72 ++++++++++++++++++++++++++++++
 lib/chip.c                 | 89 ++++++++++++++++----------------------
 lib/internal.h             |  2 +
 lib/line-info.c            | 38 ++++++++--------
 tests/Makefile.am          |  1 +
 tests/gpiod-test-helpers.h |  3 ++
 tests/tests-chip-info.c    | 54 +++++++++++++++++++++++
 tests/tests-chip.c         | 32 --------------
 tests/tests-info-event.c   | 22 +++++-----
 tools/gpiodetect.c         | 13 ++++--
 tools/gpiofind.c           |  8 +++-
 tools/gpioinfo.c           | 16 ++++---
 14 files changed, 283 insertions(+), 141 deletions(-)
 create mode 100644 lib/chip-info.c
 create mode 100644 tests/tests-chip-info.c

base-commit: 6e15b78d6e9c956c295c755aed793ffd963b1c53
prerequisite-patch-id: 4c18b0ccbdc27f0478078c520fc831c6f8e99cae
prerequisite-patch-id: 9813ae923bac1692f9558db3c09081c3d088ce78
prerequisite-patch-id: ebd388a7c411a6b730f23a6995852e62c07fb369
prerequisite-patch-id: bf291d6ac4300ed0ef6bf09eb187530098a7a338
prerequisite-patch-id: 3af98e60123f5e4b1199a2e0fb06eb6e1cfda18f
prerequisite-patch-id: 26c5fa12c404c09e78b9dfdf7fab5e3e7afcce4e

Signature · 1 line
2.35.1
#1 lore raw

PATCH v2 1/3 core: rename gpiod_chip_info_event_wait and gpiod_chip_info_event_read

Another couple of functions that don't follow the gpiod_<object>_<action>_<object> pattern.
So rename gpiod_chip_info_event_wait to gpiod_chip_wait_info_event and gpiod_chip_info_event_read to gpiod_chip_read_info_event.

---
 include/gpiod.h          |  4 ++--
 lib/chip.c               |  4 ++--
 tests/tests-info-event.c | 22 +++++++++++-----------
 3 files changed, 15 insertions(+), 15 deletions(-)
include/gpiod.h +2 -2
index 2365630..956ee12 100644
@@ -151,7 +151,7 @@ int gpiod_chip_get_fd(struct gpiod_chip *chip);
  * @return 0 if wait timed out, -1 if an error occurred, 1 if an event is
  *	   pending.
  */
-int gpiod_chip_info_event_wait(struct gpiod_chip *chip, uint64_t timeout_ns);
+int gpiod_chip_wait_info_event(struct gpiod_chip *chip, uint64_t timeout_ns);
 
 /**
  * @brief Read a single line status change event from the chip.
@@ -160,7 +160,7 @@ int gpiod_chip_info_event_wait(struct gpiod_chip *chip, uint64_t timeout_ns);
  *	   freed by the caller using ::gpiod_info_event_free.
  * @note If no events are pending, this function will block.
  */
-struct gpiod_info_event *gpiod_chip_info_event_read(struct gpiod_chip *chip);
+struct gpiod_info_event *gpiod_chip_read_info_event(struct gpiod_chip *chip);
 
 /**
  * @brief Map a line's name to its offset within the chip.
lib/chip.c +2 -2
index b881be1..50d8312 100644
@@ -164,14 +164,14 @@ GPIOD_API int gpiod_chip_get_fd(struct gpiod_chip *chip)
 	return chip->fd;
 }
 
-GPIOD_API int gpiod_chip_info_event_wait(struct gpiod_chip *chip,
+GPIOD_API int gpiod_chip_wait_info_event(struct gpiod_chip *chip,
 					 uint64_t timeout_ns)
 {
 	return gpiod_poll_fd(chip->fd, timeout_ns);
 }
 
 GPIOD_API struct gpiod_info_event *
-gpiod_chip_info_event_read(struct gpiod_chip *chip)
+gpiod_chip_read_info_event(struct gpiod_chip *chip)
 {
 	return gpiod_info_event_read_fd(chip->fd);
 }
tests/tests-info-event.c +11 -11
index 32ae690..0640d66 100644
@@ -50,7 +50,7 @@ GPIOD_TEST_CASE(event_timeout)
 	g_assert_nonnull(info);
 	gpiod_test_return_if_failed();
 
-	ret = gpiod_chip_info_event_wait(chip, 100000000);
+	ret = gpiod_chip_wait_info_event(chip, 100000000);
 	g_assert_cmpint(ret, ==, 0);
 }
 
@@ -130,11 +130,11 @@ GPIOD_TEST_CASE(request_reconfigure_release_events)
 			      request_reconfigure_release_line, &ctx);
 	g_thread_ref(thread);
 
-	ret = gpiod_chip_info_event_wait(chip, 1000000000);
+	ret = gpiod_chip_wait_info_event(chip, 1000000000);
 	g_assert_cmpint(ret, >, 0);
 	gpiod_test_join_thread_and_return_if_failed(thread);
 
-	request_event = gpiod_chip_info_event_read(chip);
+	request_event = gpiod_chip_read_info_event(chip);
 	g_assert_nonnull(request_event);
 	gpiod_test_join_thread_and_return_if_failed(thread);
 
@@ -148,11 +148,11 @@ GPIOD_TEST_CASE(request_reconfigure_release_events)
 	g_assert_cmpint(gpiod_line_info_get_direction(request_info), ==,
 			GPIOD_LINE_DIRECTION_INPUT);
 
-	ret = gpiod_chip_info_event_wait(chip, 1000000000);
+	ret = gpiod_chip_wait_info_event(chip, 1000000000);
 	g_assert_cmpint(ret, >, 0);
 	gpiod_test_join_thread_and_return_if_failed(thread);
 
-	reconfigure_event = gpiod_chip_info_event_read(chip);
+	reconfigure_event = gpiod_chip_read_info_event(chip);
 	g_assert_nonnull(reconfigure_event);
 	gpiod_test_join_thread_and_return_if_failed(thread);
 
@@ -166,11 +166,11 @@ GPIOD_TEST_CASE(request_reconfigure_release_events)
 	g_assert_cmpint(gpiod_line_info_get_direction(reconfigure_info), ==,
 			GPIOD_LINE_DIRECTION_OUTPUT);
 
-	ret = gpiod_chip_info_event_wait(chip, 1000000000);
+	ret = gpiod_chip_wait_info_event(chip, 1000000000);
 	g_assert_cmpint(ret, >, 0);
 	gpiod_test_join_thread_and_return_if_failed(thread);
 
-	release_event = gpiod_chip_info_event_read(chip);
+	release_event = gpiod_chip_read_info_event(chip);
 	g_assert_nonnull(release_event);
 	gpiod_test_join_thread_and_return_if_failed(thread);
 
@@ -243,7 +243,7 @@ GPIOD_TEST_CASE(chip_fd_can_be_polled)
 	g_assert_cmpint(ret, >, 0);
 	gpiod_test_join_thread_and_return_if_failed(thread);
 
-	event = gpiod_chip_info_event_read(chip);
+	event = gpiod_chip_read_info_event(chip);
 	g_assert_nonnull(event);
 	gpiod_test_join_thread_and_return_if_failed(thread);
 
@@ -283,11 +283,11 @@ GPIOD_TEST_CASE(unwatch_and_check_that_no_events_are_generated)
 
 	request = gpiod_test_request_lines_or_fail(chip, req_cfg, line_cfg);
 
-	ret = gpiod_chip_info_event_wait(chip, 100000000);
+	ret = gpiod_chip_wait_info_event(chip, 100000000);
 	g_assert_cmpint(ret, >, 0);
 	gpiod_test_return_if_failed();
 
-	event = gpiod_chip_info_event_read(chip);
+	event = gpiod_chip_read_info_event(chip);
 	g_assert_nonnull(event);
 	gpiod_test_return_if_failed();
 
@@ -298,6 +298,6 @@ GPIOD_TEST_CASE(unwatch_and_check_that_no_events_are_generated)
 	gpiod_line_request_release(request);
 	request = NULL;
 
-	ret = gpiod_chip_info_event_wait(chip, 100000000);
+	ret = gpiod_chip_wait_info_event(chip, 100000000);
 	g_assert_cmpint(ret, ==, 0);
 }
Signature · 1 line
2.35.1
#2 lore raw

Re: [libgpiod v2][PATCH 1/3] core: rename gpiod_chip_info_event_wait and gpiod_chip_info_event_read

Quoted 7 lines · Kent Gibson

Another couple of functions that don't follow the gpiod_<object>_<action>_<object> pattern.
So rename gpiod_chip_info_event_wait to gpiod_chip_wait_info_event and gpiod_chip_info_event_read to gpiod_chip_read_info_event.

Applied.

Bart

#3 lore raw

PATCH v2 2/3 core: split chip_info out of chip

In reply to Kent Gibson

The core library should be minimalist, only performing the operations required, but gpiod_chip_open() always fetches the chip info, even though the majority of the time the chip will only be used to request a line, so the chip info is not required.

Split the chip_info from the chip, in the same style as line_info, and update methods and tools appropriately.

In the rare occasions that the user requires the chip info they can request it themselves using gpiod_chip_get_info(), as demonstrated in the tool changes.

---
 include/gpiod.h            | 69 +++++++++++++++++++++++--------
 lib/Makefile.am            |  1 +
 lib/chip-info.c            | 72 ++++++++++++++++++++++++++++++++
 lib/chip.c                 | 85 ++++++++++++++++----------------------
 lib/internal.h             |  2 +
 tests/Makefile.am          |  1 +
 tests/gpiod-test-helpers.h |  3 ++
 tests/tests-chip-info.c    | 54 ++++++++++++++++++++++++
 tests/tests-chip.c         | 32 --------------
 tools/gpiodetect.c         | 13 ++++--
 tools/gpiofind.c           |  8 +++-
 tools/gpioinfo.c           | 16 ++++---
 12 files changed, 249 insertions(+), 107 deletions(-)
 create mode 100644 lib/chip-info.c
 create mode 100644 tests/tests-chip-info.c
include/gpiod.h +52 -17
index 956ee12..e099515 100644
@@ -41,6 +41,7 @@ extern "C" {
  */
 
 struct gpiod_chip;
+struct gpiod_chip_info;
 struct gpiod_line_info;
 struct gpiod_line_config;
 struct gpiod_request_config;
@@ -75,18 +76,12 @@ struct gpiod_chip *gpiod_chip_open(const char *path);
 void gpiod_chip_close(struct gpiod_chip *chip);
 
 /**
- * @brief Get the name of the chip as represented in the kernel.
+ * @brief Get information about the chip.
  * @param chip GPIO chip object.
- * @return Pointer to a human-readable string containing the chip name.
+ * @return New GPIO chip info object or NULL if an error occurred. The returned
+ *         object must be freed by the caller using ::gpiod_chip_info_free.
  */
-const char *gpiod_chip_get_name(struct gpiod_chip *chip);
-
-/**
- * @brief Get the label of the chip as represented in the kernel.
- * @param chip GPIO chip object.
- * @return Pointer to a human-readable string containing the chip label.
- */
-const char *gpiod_chip_get_label(struct gpiod_chip *chip);
+struct gpiod_chip_info *gpiod_chip_get_info(struct gpiod_chip *chip);
 
 /**
  * @brief Get the path used to open the chip.
@@ -95,13 +90,6 @@ const char *gpiod_chip_get_label(struct gpiod_chip *chip);
  */
 const char *gpiod_chip_get_path(struct gpiod_chip *chip);
 
-/**
- * @brief Get the number of lines exposed by the chip.
- * @param chip GPIO chip object.
- * @return Number of GPIO lines.
- */
-size_t gpiod_chip_get_num_lines(struct gpiod_chip *chip);
-
 /**
  * @brief Get a snapshot of information about a line.
  * @param chip GPIO chip object.
@@ -187,6 +175,53 @@ gpiod_chip_request_lines(struct gpiod_chip *chip,
 			 struct gpiod_request_config *req_cfg,
 			 struct gpiod_line_config *line_cfg);
 
+/**
+ * @}
+ *
+ * @defgroup chip_info Chip info
+ * @{
+ *
+ * Functions for retrieving kernel information about chips.
+ *
+ * Line info object contains an immutable snapshot of a chip's status.
+ *
+ * The chip info contains all the publicly available information about a
+ * chip.
+ *
+ * Some accessor methods return pointers.  Those pointers refer to internal
+ * fields.  The lifetimes of those fields are tied to the lifetime of the
+ * containing chip info object.
+ * Such pointers remain valid until ::gpiod_chip_info_free is called on the
+ * containing chip info object. They must not be freed by the caller.
+ */
+
+/**
+ * @brief Free a chip info object and release all associated resources.
+ * @param info GPIO chip info object to free.
+ */
+void gpiod_chip_info_free(struct gpiod_chip_info *info);
+
+/**
+ * @brief Get the name of the chip as represented in the kernel.
+ * @param info GPIO chip info object.
+ * @return Pointer to a human-readable string containing the chip name.
+ */
+const char *gpiod_chip_info_get_name(struct gpiod_chip_info *info);
+
+/**
+ * @brief Get the label of the chip as represented in the kernel.
+ * @param info GPIO chip info object.
+ * @return Pointer to a human-readable string containing the chip label.
+ */
+const char *gpiod_chip_info_get_label(struct gpiod_chip_info *info);
+
+/**
+ * @brief Get the number of lines exposed by the chip.
+ * @param info GPIO chip info object.
+ * @return Number of GPIO lines.
+ */
+size_t gpiod_chip_info_get_num_lines(struct gpiod_chip_info *info);
+
 /**
  * @}
  *
lib/Makefile.am +1 -0
index b6854d9..1bd2b2e 100644
@@ -3,6 +3,7 @@
 
 lib_LTLIBRARIES = libgpiod.la
 libgpiod_la_SOURCES =	chip.c \
+			chip-info.c \
 			edge-event.c \
 			info-event.c \
 			internal.h \
lib/chip-info.c new file +72 -0

72 lines not on this page · raw message

lib/chip.c +36 -49

159 lines not on this page · raw message

lib/internal.h +2 -0
index 9af2cda..ffef578 100644
@@ -18,6 +18,8 @@
 
 #define GPIOD_BIT(nr)	(1UL << (nr))
 
+struct gpiod_chip_info *
+gpiod_chip_info_from_kernel(struct gpiochip_info *infobuf);
 struct gpiod_line_info *
 gpiod_line_info_from_kernel(struct gpio_v2_line_info *infobuf);
 int gpiod_request_config_to_kernel(struct gpiod_request_config *config,
tests/Makefile.am +1 -0
index 89bf868..f37dc03 100644
@@ -23,6 +23,7 @@ gpiod_test_SOURCES =			\
 		gpiod-test-sim.c	\
 		gpiod-test-sim.h	\
 		tests-chip.c		\
+		tests-chip-info.c	\
 		tests-edge-event.c	\
 		tests-info-event.c	\
 		tests-line-config.c	\
tests/gpiod-test-helpers.h +3 -0
index 4aa4202..acba686 100644
@@ -18,6 +18,9 @@
 typedef struct gpiod_chip struct_gpiod_chip;
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(struct_gpiod_chip, gpiod_chip_close);
 
+typedef struct gpiod_chip_info struct_gpiod_chip_info;
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(struct_gpiod_chip_info, gpiod_chip_info_free);
+
 typedef struct gpiod_line_info struct_gpiod_line_info;
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(struct_gpiod_line_info, gpiod_line_info_free);
 
tests/tests-chip-info.c new file +54 -0

54 lines not on this page · raw message

tests/tests-chip.c +0 -32
index 09906e3..3fad16d 100644
@@ -47,28 +47,6 @@ GPIOD_TEST_CASE(open_chip_not_a_gpio_device)
 	gpiod_test_expect_errno(ENODEV);
 }
 
-GPIOD_TEST_CASE(get_chip_name)
-{
-	g_autoptr(GPIOSimChip) sim = g_gpiosim_chip_new(NULL);
-	g_autoptr(struct_gpiod_chip) chip = NULL;
-
-	chip = gpiod_test_open_chip_or_fail(g_gpiosim_chip_get_dev_path(sim));
-
-	g_assert_cmpstr(gpiod_chip_get_name(chip), ==,
-			g_gpiosim_chip_get_name(sim));
-}
-
-GPIOD_TEST_CASE(get_chip_label)
-{
-	g_autoptr(GPIOSimChip) sim = g_gpiosim_chip_new("label", "foobar",
-							NULL);
-	g_autoptr(struct_gpiod_chip) chip = NULL;
-
-	chip = gpiod_test_open_chip_or_fail(g_gpiosim_chip_get_dev_path(sim));
-
-	g_assert_cmpstr(gpiod_chip_get_label(chip), ==, "foobar");
-}
-
 GPIOD_TEST_CASE(get_chip_path)
 {
 	g_autoptr(GPIOSimChip) sim = g_gpiosim_chip_new(NULL);
@@ -80,16 +58,6 @@ GPIOD_TEST_CASE(get_chip_path)
 	g_assert_cmpstr(gpiod_chip_get_path(chip), ==, path);
 }
 
-GPIOD_TEST_CASE(get_num_lines)
-{
-	g_autoptr(GPIOSimChip) sim = g_gpiosim_chip_new("num-lines", 16, NULL);
-	g_autoptr(struct_gpiod_chip) chip = NULL;
-
-	chip = gpiod_test_open_chip_or_fail(g_gpiosim_chip_get_dev_path(sim));
-
-	g_assert_cmpuint(gpiod_chip_get_num_lines(chip), ==, 16);
-}
-
 GPIOD_TEST_CASE(get_fd)
 {
 	g_autoptr(GPIOSimChip) sim = g_gpiosim_chip_new(NULL);
tools/gpiodetect.c +10 -3
index 6ce3cb8..8f6e8b3 100644
@@ -34,6 +34,7 @@ int main(int argc, char **argv)
 {
 	int optc, opti, num_chips, i;
 	struct gpiod_chip *chip;
+	struct gpiod_chip_info *info;
 	struct dirent **entries;
 
 	for (;;) {
@@ -70,11 +71,17 @@ int main(int argc, char **argv)
 		if (!chip)
 			die_perror("unable to open %s", entries[i]->d_name);
 
+		info = gpiod_chip_get_info(chip);
+		if (!info)
+			die_perror("unable to get info for %s", entries[i]->d_name);
+
+
 		printf("%s [%s] (%zu lines)\n",
-		       gpiod_chip_get_name(chip),
-		       gpiod_chip_get_label(chip),
-		       gpiod_chip_get_num_lines(chip));
+		       gpiod_chip_info_get_name(info),
+		       gpiod_chip_info_get_label(info),
+		       gpiod_chip_info_get_num_lines(info));
 
+		gpiod_chip_info_free(info);
 		gpiod_chip_close(chip);
 		free(entries[i]);
 	}
tools/gpiofind.c +7 -1
index 910cb8b..36eba86 100644
@@ -34,6 +34,7 @@ int main(int argc, char **argv)
 {
 	int i, num_chips, optc, opti, offset;
 	struct gpiod_chip *chip;
+	struct gpiod_chip_info *info;
 	struct dirent **entries;
 
 	for (;;) {
@@ -76,8 +77,13 @@ int main(int argc, char **argv)
 
 		offset = gpiod_chip_find_line(chip, argv[0]);
 		if (offset >= 0) {
+			info = gpiod_chip_get_info(chip);
+			if (!info)
+				die_perror("unable to get info for %s", entries[i]->d_name);
+
 			printf("%s %u\n",
-			       gpiod_chip_get_name(chip), offset);
+			       gpiod_chip_info_get_name(info), offset);
+			gpiod_chip_info_free(info);
 			gpiod_chip_close(chip);
 			return EXIT_SUCCESS;
 		}
tools/gpioinfo.c +11 -5
index c852b36..fbe2a13 100644
@@ -125,19 +125,24 @@ static PRINTF(3, 4) void prinfo(bool *of,
 static void list_lines(struct gpiod_chip *chip)
 {
 	bool flag_printed, of, active_low;
+	struct gpiod_chip_info *chip_info;
 	struct gpiod_line_info *info;
 	const char *name, *consumer;
-	size_t i, offset;
+	size_t i, offset, num_lines;
 	int direction;
 
+	chip_info = gpiod_chip_get_info(chip);
+	if (!chip_info)
+		die_perror("unable to retrieve the chip info from chip");
+
+	num_lines = gpiod_chip_info_get_num_lines(chip_info);
 	printf("%s - %zu lines:\n",
-	       gpiod_chip_get_name(chip), gpiod_chip_get_num_lines(chip));
+	       gpiod_chip_info_get_name(chip_info), num_lines);
 
-	for (offset = 0; offset < gpiod_chip_get_num_lines(chip); offset++) {
+	for (offset = 0; offset < num_lines; offset++) {
 		info = gpiod_chip_get_line_info(chip, offset);
 		if (!info)
-			die_perror("unable to retrieve the line object from chip");
-
+			die_perror("unable to retrieve the line info from chip");
 		name = gpiod_line_info_get_name(info);
 		consumer = gpiod_line_info_get_consumer(info);
 		direction = gpiod_line_info_get_direction(info);
@@ -184,6 +189,7 @@ static void list_lines(struct gpiod_chip *chip)
 
 		gpiod_line_info_free(info);
 	}
+	gpiod_chip_info_free(chip_info);
 }
 
 int main(int argc, char **argv)
Signature · 1 line
2.35.1
#4 lore raw

Re: [libgpiod v2][PATCH 2/3] core: split chip_info out of chip

Quoted 6 lines · Kent Gibson

The core library should be minimalist, only performing the operations required, but gpiod_chip_open() always fetches the chip info, even though the majority of the time the chip will only be used to request a line, so the chip info is not required.

Quoted 8 lines

Split the chip_info from the chip, in the same style as line_info, and update methods and tools appropriately.

In the rare occasions that the user requires the chip info they can request it themselves using gpiod_chip_get_info(), as demonstrated in the tool changes.

Ha! Interesting take. Makes sense. I queued this but tweaked a couple things (some bad copy-paste and stray newlines).

Bart

#5 lore raw

Re: [libgpiod v2][PATCH 2/3] core: split chip_info out of chip

Quoted 10 lines · Bartosz Golaszewski
Quoted 9 lines · Kent Gibson

The core library should be minimalist, only performing the operations required, but gpiod_chip_open() always fetches the chip info, even though the majority of the time the chip will only be used to request a line, so the chip info is not required.

Split the chip_info from the chip, in the same style as line_info, and update methods and tools appropriately.

Quoted 9 lines
Quoted 5 lines

In the rare occasions that the user requires the chip info they can request it themselves using gpiod_chip_get_info(), as demonstrated in the tool changes.

Ha! Interesting take. Makes sense. I queued this but tweaked a couple things (some bad copy-paste and stray newlines).

I've been flip-flopping on this one, but wanted to float it as we're getting close to finalising the API.
In some ways hiding the chip info is simpler, and gpiod_chip_open() already does a whole lot in gpiod_is_gpiochip_device(), so an extra ioctl call isn't going to make much difference...
But it does reduce the gpiod_chip size a fair bit as well. As I said - flip-flopping.

Cheers,
Kent.

#6 lore raw

Re: [libgpiod v2][PATCH 2/3] core: split chip_info out of chip

Quoted 22 lines · Kent Gibson
Quoted 10 lines · Bartosz Golaszewski
Quoted 9 lines · Kent Gibson

The core library should be minimalist, only performing the operations required, but gpiod_chip_open() always fetches the chip info, even though the majority of the time the chip will only be used to request a line, so the chip info is not required.

Split the chip_info from the chip, in the same style as line_info, and update methods and tools appropriately.

Quoted 9 lines
Quoted 5 lines

In the rare occasions that the user requires the chip info they can request it themselves using gpiod_chip_get_info(), as demonstrated in the tool changes.

Ha! Interesting take. Makes sense. I queued this but tweaked a couple things (some bad copy-paste and stray newlines).

Quoted 8 lines

I've been flip-flopping on this one, but wanted to float it as we're getting close to finalising the API.
In some ways hiding the chip info is simpler, and gpiod_chip_open() already does a whole lot in gpiod_is_gpiochip_device(), so an extra ioctl call isn't going to make much difference...
But it does reduce the gpiod_chip size a fair bit as well. As I said - flip-flopping.

No, it's good. I like to idea of limiting the responsiblities of each structure.

Bart

#7 lore raw

PATCH v2 3/3 line-info: rename infobuf to uinfo

In reply to Kent Gibson

The infobuf variable in gpiod_line_info_from_kernel() refers to the uAPI version of the info, and the "buf" suffix doesn't really emphasise that, so rename it to uinfo.

---
 lib/line-info.c | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)
lib/line-info.c +19 -19
index fc656f9..168fc86 100644
@@ -106,7 +106,7 @@ gpiod_line_info_get_debounce_period_us(struct gpiod_line_info *info)
 }
 
 struct gpiod_line_info *
-gpiod_line_info_from_kernel(struct gpio_v2_line_info *infobuf)
+gpiod_line_info_from_kernel(struct gpio_v2_line_info *uinfo)
 {
 	struct gpio_v2_line_attribute *attr;
 	struct gpiod_line_info *info;
@@ -118,47 +118,47 @@ gpiod_line_info_from_kernel(struct gpio_v2_line_info *infobuf)
 
 	memset(info, 0, sizeof(*info));
 
-	info->offset = infobuf->offset;
-	strncpy(info->name, infobuf->name, GPIO_MAX_NAME_SIZE);
+	info->offset = uinfo->offset;
+	strncpy(info->name, uinfo->name, GPIO_MAX_NAME_SIZE);
 
-	info->used = !!(infobuf->flags & GPIO_V2_LINE_FLAG_USED);
-	strncpy(info->consumer, infobuf->consumer, GPIO_MAX_NAME_SIZE);
+	info->used = !!(uinfo->flags & GPIO_V2_LINE_FLAG_USED);
+	strncpy(info->consumer, uinfo->consumer, GPIO_MAX_NAME_SIZE);
 
-	if (infobuf->flags & GPIO_V2_LINE_FLAG_OUTPUT)
+	if (uinfo->flags & GPIO_V2_LINE_FLAG_OUTPUT)
 		info->direction = GPIOD_LINE_DIRECTION_OUTPUT;
 	else
 		info->direction = GPIOD_LINE_DIRECTION_INPUT;
 
-	if (infobuf->flags & GPIO_V2_LINE_FLAG_ACTIVE_LOW)
+	if (uinfo->flags & GPIO_V2_LINE_FLAG_ACTIVE_LOW)
 		info->active_low = true;
 
-	if (infobuf->flags & GPIO_V2_LINE_FLAG_BIAS_PULL_UP)
+	if (uinfo->flags & GPIO_V2_LINE_FLAG_BIAS_PULL_UP)
 		info->bias = GPIOD_LINE_BIAS_PULL_UP;
-	else if (infobuf->flags & GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN)
+	else if (uinfo->flags & GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN)
 		info->bias = GPIOD_LINE_BIAS_PULL_DOWN;
-	else if (infobuf->flags & GPIO_V2_LINE_FLAG_BIAS_DISABLED)
+	else if (uinfo->flags & GPIO_V2_LINE_FLAG_BIAS_DISABLED)
 		info->bias = GPIOD_LINE_BIAS_DISABLED;
 	else
 		info->bias = GPIOD_LINE_BIAS_UNKNOWN;
 
-	if (infobuf->flags & GPIO_V2_LINE_FLAG_OPEN_DRAIN)
+	if (uinfo->flags & GPIO_V2_LINE_FLAG_OPEN_DRAIN)
 		info->drive = GPIOD_LINE_DRIVE_OPEN_DRAIN;
-	else if (infobuf->flags & GPIO_V2_LINE_FLAG_OPEN_SOURCE)
+	else if (uinfo->flags & GPIO_V2_LINE_FLAG_OPEN_SOURCE)
 		info->drive = GPIOD_LINE_DRIVE_OPEN_SOURCE;
 	else
 		info->drive = GPIOD_LINE_DRIVE_PUSH_PULL;
 
-	if ((infobuf->flags & GPIO_V2_LINE_FLAG_EDGE_RISING) &&
-	    (infobuf->flags & GPIO_V2_LINE_FLAG_EDGE_FALLING))
+	if ((uinfo->flags & GPIO_V2_LINE_FLAG_EDGE_RISING) &&
+	    (uinfo->flags & GPIO_V2_LINE_FLAG_EDGE_FALLING))
 		info->edge = GPIOD_LINE_EDGE_BOTH;
-	else if (infobuf->flags & GPIO_V2_LINE_FLAG_EDGE_RISING)
+	else if (uinfo->flags & GPIO_V2_LINE_FLAG_EDGE_RISING)
 		info->edge = GPIOD_LINE_EDGE_RISING;
-	else if (infobuf->flags & GPIO_V2_LINE_FLAG_EDGE_FALLING)
+	else if (uinfo->flags & GPIO_V2_LINE_FLAG_EDGE_FALLING)
 		info->edge = GPIOD_LINE_EDGE_FALLING;
 	else
 		info->edge = GPIOD_LINE_EDGE_NONE;
 
-	if (infobuf->flags & GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME)
+	if (uinfo->flags & GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME)
 		info->event_clock = GPIOD_LINE_EVENT_CLOCK_REALTIME;
 	else
 		info->event_clock = GPIOD_LINE_EVENT_CLOCK_MONOTONIC;
@@ -167,8 +167,8 @@ gpiod_line_info_from_kernel(struct gpio_v2_line_info *infobuf)
 	 * We assume that the kernel returns correct configuration and that no
 	 * attributes repeat.
 	 */
-	for (i = 0; i < infobuf->num_attrs; i++) {
-		attr = &infobuf->attrs[i];
+	for (i = 0; i < uinfo->num_attrs; i++) {
+		attr = &uinfo->attrs[i];
 
 		if (attr->id == GPIO_V2_LINE_ATTR_ID_DEBOUNCE) {
 			info->debounced = true;
Signature · 1 line
2.35.1
#8 lore raw

Re: [libgpiod v2][PATCH 3/3] line-info: rename infobuf to uinfo

Quoted 7 lines · Kent Gibson

The infobuf variable in gpiod_line_info_from_kernel() refers to the uAPI version of the info, and the "buf" suffix doesn't really emphasise that, so rename it to uinfo.

---

I don't entirely disagree with infobuf not being the best name but uinfo is even less so. The 'u' prefix doesn't mean anything on its own. If anything I would think it has something to do with udev, udisks, upower etc. Or "mili" like useconds. How about info_kernel? kernel_info? uapi_info?

Bart

#9 lore raw

Re: [libgpiod v2][PATCH 3/3] line-info: rename infobuf to uinfo

Quoted 6 lines · Bartosz Golaszewski
Quoted 5 lines · Kent Gibson

The infobuf variable in gpiod_line_info_from_kernel() refers to the uAPI version of the info, and the "buf" suffix doesn't really emphasise that, so rename it to uinfo.

Quoted 9 lines
Quoted 2 lines

---

I don't entirely disagree with infobuf not being the best name but uinfo is even less so. The 'u' prefix doesn't mean anything on its own. If anything I would think it has something to do with udev, udisks, upower etc. Or "mili" like useconds. How about info_kernel? kernel_info? uapi_info?

uapi_info works for me.

Cheers,
Kent.