From: Kent Gibson <warthog618@gmail.com>
To: linux-gpio@vger.kernel.org, brgl@bgdev.pl
Cc: Kent Gibson <warthog618@gmail.com>
Subject: [libgpiod v2][PATCH 2/6] API: rename gpiod_request_config_get_num_offsets to gpiod_request_config_get_num_lines to match line_request pattern
Date: Fri, 11 Mar 2022 15:39:22 +0800 [thread overview]
Message-ID: <20220311073926.78636-3-warthog618@gmail.com> (raw)
In-Reply-To: <20220311073926.78636-1-warthog618@gmail.com>
Both gpiod_request_config and gpiod_line_request contain a number of
lines, but the former has a get_num_offsets accessor, while the latter
has get_num_lines. Make them consistent by switching request_config to
get_num_lines.
Signed-off-by: Kent Gibson <warthog618@gmail.com>
---
include/gpiod.h | 6 +++---
lib/request-config.c | 22 +++++++++++-----------
tests/tests-line-request.c | 2 +-
tests/tests-request-config.c | 8 ++++----
4 files changed, 19 insertions(+), 19 deletions(-)
diff --git a/include/gpiod.h b/include/gpiod.h
index e6a4645..8fb70ee 100644
--- a/include/gpiod.h
+++ b/include/gpiod.h
@@ -1094,12 +1094,12 @@ void gpiod_request_config_set_offsets(struct gpiod_request_config *config,
const unsigned int *offsets);
/**
- * @brief Get the number of offsets configured in this request config.
+ * @brief Get the number of lines configured in this request config.
* @param config Request config object.
- * @return Number of line offsets in this request config.
+ * @return Number of lines to be requested by this config.
*/
size_t
-gpiod_request_config_get_num_offsets(struct gpiod_request_config *config);
+gpiod_request_config_get_num_lines(struct gpiod_request_config *config);
/**
* @brief Get the hardware offsets of lines in this request config.
diff --git a/lib/request-config.c b/lib/request-config.c
index abcca58..d9ecc8e 100644
--- a/lib/request-config.c
+++ b/lib/request-config.c
@@ -13,7 +13,7 @@
struct gpiod_request_config {
char consumer[GPIO_MAX_NAME_SIZE];
unsigned int offsets[GPIO_V2_LINES_MAX];
- size_t num_offsets;
+ size_t num_lines;
size_t event_buffer_size;
};
@@ -54,22 +54,22 @@ gpiod_request_config_get_consumer(struct gpiod_request_config *config)
GPIOD_API void
gpiod_request_config_set_offsets(struct gpiod_request_config *config,
- size_t num_offsets,
+ size_t num_lines,
const unsigned int *offsets)
{
size_t i;
- config->num_offsets = num_offsets > GPIO_V2_LINES_MAX ?
- GPIO_V2_LINES_MAX : num_offsets;
+ config->num_lines = num_lines > GPIO_V2_LINES_MAX ?
+ GPIO_V2_LINES_MAX : num_lines;
- for (i = 0; i < config->num_offsets; i++)
+ for (i = 0; i < config->num_lines; i++)
config->offsets[i] = offsets[i];
}
GPIOD_API size_t
-gpiod_request_config_get_num_offsets(struct gpiod_request_config *config)
+gpiod_request_config_get_num_lines(struct gpiod_request_config *config)
{
- return config->num_offsets;
+ return config->num_lines;
}
GPIOD_API void
@@ -77,7 +77,7 @@ gpiod_request_config_get_offsets(struct gpiod_request_config *config,
unsigned int *offsets)
{
memcpy(offsets, config->offsets,
- sizeof(*offsets) * config->num_offsets);
+ sizeof(*offsets) * config->num_lines);
}
GPIOD_API void
@@ -98,15 +98,15 @@ int gpiod_request_config_to_kernel(struct gpiod_request_config *config,
{
size_t i;
- if (config->num_offsets == 0) {
+ if (config->num_lines == 0) {
errno = EINVAL;
return -1;
}
- for (i = 0; i < config->num_offsets; i++)
+ for (i = 0; i < config->num_lines; i++)
reqbuf->offsets[i] = config->offsets[i];
- reqbuf->num_lines = config->num_offsets;
+ reqbuf->num_lines = config->num_lines;
strcpy(reqbuf->consumer, config->consumer);
reqbuf->event_buffer_size = config->event_buffer_size;
diff --git a/tests/tests-line-request.c b/tests/tests-line-request.c
index 8ef391d..eb3adee 100644
--- a/tests/tests-line-request.c
+++ b/tests/tests-line-request.c
@@ -21,7 +21,7 @@ GPIOD_TEST_CASE(request_fails_with_no_offsets)
req_cfg = gpiod_test_create_request_config_or_fail();
line_cfg = gpiod_test_create_line_config_or_fail();
- g_assert_cmpuint(gpiod_request_config_get_num_offsets(req_cfg), ==, 0);
+ g_assert_cmpuint(gpiod_request_config_get_num_lines(req_cfg), ==, 0);
chip = gpiod_test_open_chip_or_fail(g_gpiosim_chip_get_dev_path(sim));
request = gpiod_chip_request_lines(chip, req_cfg, line_cfg);
diff --git a/tests/tests-request-config.c b/tests/tests-request-config.c
index becb414..136fe07 100644
--- a/tests/tests-request-config.c
+++ b/tests/tests-request-config.c
@@ -16,7 +16,7 @@ GPIOD_TEST_CASE(default_config)
config = gpiod_test_create_request_config_or_fail();
g_assert_null(gpiod_request_config_get_consumer(config));
- g_assert_cmpuint(gpiod_request_config_get_num_offsets(config), ==, 0);
+ g_assert_cmpuint(gpiod_request_config_get_num_lines(config), ==, 0);
g_assert_cmpuint(gpiod_request_config_get_event_buffer_size(config),
==, 0);
}
@@ -42,7 +42,7 @@ GPIOD_TEST_CASE(offsets)
config = gpiod_test_create_request_config_or_fail();
gpiod_request_config_set_offsets(config, 4, offsets);
- g_assert_cmpuint(gpiod_request_config_get_num_offsets(config), ==, 4);
+ g_assert_cmpuint(gpiod_request_config_get_num_lines(config), ==, 4);
memset(read_back, 0, sizeof(read_back));
gpiod_request_config_get_offsets(config, read_back);
for (i = 0; i < 4; i++)
@@ -71,11 +71,11 @@ GPIOD_TEST_CASE(max_offsets)
config = gpiod_test_create_request_config_or_fail();
gpiod_request_config_set_offsets(config, 64, offsets_good);
- g_assert_cmpuint(gpiod_request_config_get_num_offsets(config), ==, 64);
+ g_assert_cmpuint(gpiod_request_config_get_num_lines(config), ==, 64);
gpiod_request_config_set_offsets(config, 65, offsets_bad);
/* Should get truncated. */
- g_assert_cmpuint(gpiod_request_config_get_num_offsets(config), ==, 64);
+ g_assert_cmpuint(gpiod_request_config_get_num_lines(config), ==, 64);
}
GPIOD_TEST_CASE(event_buffer_size)
--
2.35.1
next prev parent reply other threads:[~2022-03-11 7:40 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-11 7:39 [libgpiod v2][PATCH 0/6] documentation and other minor tweaks Kent Gibson
2022-03-11 7:39 ` [libgpiod v2][PATCH 1/6] treewide: use size_t for loop variable where limit is size_t Kent Gibson
2022-03-11 7:39 ` Kent Gibson [this message]
2022-03-15 10:52 ` [libgpiod v2][PATCH 2/6] API: rename gpiod_request_config_get_num_offsets to gpiod_request_config_get_num_lines to match line_request pattern Bartosz Golaszewski
2022-03-15 11:23 ` Kent Gibson
2022-03-15 11:39 ` Bartosz Golaszewski
2022-03-15 11:59 ` Kent Gibson
2022-03-15 13:43 ` Bartosz Golaszewski
2022-03-15 14:51 ` Kent Gibson
2022-03-11 7:39 ` [libgpiod v2][PATCH 3/6] line-config: rename off to idx Kent Gibson
2022-03-11 7:39 ` [libgpiod v2][PATCH 4/6] line-config: rename num_values to num_lines Kent Gibson
2022-03-15 10:58 ` Bartosz Golaszewski
2022-03-11 7:39 ` [libgpiod v2][PATCH 5/6] line-request: rename wait and read functions Kent Gibson
2022-03-11 7:39 ` [libgpiod v2][PATCH 6/6] doc: API documentation tweaks Kent Gibson
2022-03-15 11:20 ` Bartosz Golaszewski
2022-03-14 8:31 ` [libgpiod v2][PATCH 0/6] documentation and other minor tweaks Bartosz Golaszewski
2022-03-15 1:33 ` Kent Gibson
2022-03-15 11:25 ` Bartosz Golaszewski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220311073926.78636-3-warthog618@gmail.com \
--to=warthog618@gmail.com \
--cc=brgl@bgdev.pl \
--cc=linux-gpio@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).