From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Kent Gibson <warthog618@gmail.com>,
Linus Walleij <linus.walleij@linaro.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Viresh Kumar <viresh.kumar@linaro.org>
Cc: linux-gpio@vger.kernel.org,
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Subject: [libgpiod][PATCH 1/5] core: provide gpiod_line_request_get_chip_path()
Date: Wed, 19 Jul 2023 21:20:53 +0200 [thread overview]
Message-ID: <20230719192057.172560-2-brgl@bgdev.pl> (raw)
In-Reply-To: <20230719192057.172560-1-brgl@bgdev.pl>
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
While we can get the list of requested offsets from a line-request object,
this information lacks context if we don't provide any data about the GPIO
chip the request was made on. Add a helper allowing users to get the path
to the character device used to create the parent chip.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
include/gpiod.h | 9 +++++++++
lib/chip.c | 2 +-
lib/internal.h | 3 ++-
lib/line-request.c | 20 +++++++++++++++++++-
4 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/include/gpiod.h b/include/gpiod.h
index 3c13783..61f8ef1 100644
--- a/include/gpiod.h
+++ b/include/gpiod.h
@@ -1007,6 +1007,15 @@ gpiod_request_config_get_event_buffer_size(struct gpiod_request_config *config);
*/
void gpiod_line_request_release(struct gpiod_line_request *request);
+/**
+ * @brief Get the path to the chip this request was made on.
+ * @param request Line request object.
+ * @return Path to the GPIO chip device. The returned pointer is valid for the
+ * lifetime of the request object and must not be freed by the caller.
+ */
+const char *
+gpiod_line_request_get_chip_path(struct gpiod_line_request *request);
+
/**
* @brief Get the number of lines in the request.
* @param request Line request object.
diff --git a/lib/chip.c b/lib/chip.c
index 7d4d21e..e94d750 100644
--- a/lib/chip.c
+++ b/lib/chip.c
@@ -237,7 +237,7 @@ gpiod_chip_request_lines(struct gpiod_chip *chip,
if (ret < 0)
return NULL;
- request = gpiod_line_request_from_uapi(&uapi_req);
+ request = gpiod_line_request_from_uapi(&uapi_req, chip->path);
if (!request) {
close(uapi_req.fd);
return NULL;
diff --git a/lib/internal.h b/lib/internal.h
index ef9b17e..e9ada42 100644
--- a/lib/internal.h
+++ b/lib/internal.h
@@ -26,7 +26,8 @@ void gpiod_request_config_to_uapi(struct gpiod_request_config *config,
int gpiod_line_config_to_uapi(struct gpiod_line_config *config,
struct gpio_v2_line_request *uapi_cfg);
struct gpiod_line_request *
-gpiod_line_request_from_uapi(struct gpio_v2_line_request *uapi_req);
+gpiod_line_request_from_uapi(struct gpio_v2_line_request *uapi_req,
+ const char *chip_path);
int gpiod_edge_event_buffer_read_fd(int fd,
struct gpiod_edge_event_buffer *buffer,
size_t max_events);
diff --git a/lib/line-request.c b/lib/line-request.c
index e536355..99cbe2c 100644
--- a/lib/line-request.c
+++ b/lib/line-request.c
@@ -13,13 +13,15 @@
#include "internal.h"
struct gpiod_line_request {
+ char *chip_path;
unsigned int offsets[GPIO_V2_LINES_MAX];
size_t num_lines;
int fd;
};
struct gpiod_line_request *
-gpiod_line_request_from_uapi(struct gpio_v2_line_request *uapi_req)
+gpiod_line_request_from_uapi(struct gpio_v2_line_request *uapi_req,
+ const char *chip_path)
{
struct gpiod_line_request *request;
@@ -28,6 +30,13 @@ gpiod_line_request_from_uapi(struct gpio_v2_line_request *uapi_req)
return NULL;
memset(request, 0, sizeof(*request));
+
+ request->chip_path = strdup(chip_path);
+ if (!request->chip_path) {
+ free(request);
+ return NULL;
+ }
+
request->fd = uapi_req->fd;
request->num_lines = uapi_req->num_lines;
memcpy(request->offsets, uapi_req->offsets,
@@ -42,9 +51,18 @@ GPIOD_API void gpiod_line_request_release(struct gpiod_line_request *request)
return;
close(request->fd);
+ free(request->chip_path);
free(request);
}
+GPIOD_API const char *
+gpiod_line_request_get_chip_path(struct gpiod_line_request *request)
+{
+ assert(request);
+
+ return request->chip_path;
+}
+
GPIOD_API size_t
gpiod_line_request_get_num_requested_lines(struct gpiod_line_request *request)
{
--
2.39.2
next prev parent reply other threads:[~2023-07-19 19:21 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-19 19:20 [libgpiod][PATCH 0/5] core: provide information about the parent chip in line requests Bartosz Golaszewski
2023-07-19 19:20 ` Bartosz Golaszewski [this message]
2023-07-19 19:20 ` [libgpiod][PATCH 2/5] tests: add a test-case for gpiod_line_request_get_chip_path() Bartosz Golaszewski
2023-07-19 19:20 ` [libgpiod][PATCH 3/5] bindings: cxx: provide line_request::chip_path() Bartosz Golaszewski
2023-07-19 19:20 ` [libgpiod][PATCH 4/5] bindings: python: provide the chip_path property in line_request Bartosz Golaszewski
2023-07-19 19:20 ` [libgpiod][PATCH 5/5] bindings: rust: provide LineRequest::chip_path() Bartosz Golaszewski
2023-07-20 5:04 ` Erik Schilling
2023-07-20 8:04 ` Bartosz Golaszewski
2023-07-20 8:10 ` Erik Schilling
2023-07-20 3:27 ` [libgpiod][PATCH 0/5] core: provide information about the parent chip in line requests Kent Gibson
2023-07-20 7:59 ` Bartosz Golaszewski
2023-07-20 8:05 ` Kent Gibson
2023-07-20 8:25 ` Bartosz Golaszewski
2023-07-20 8:39 ` Kent Gibson
2023-07-20 8:49 ` Bartosz Golaszewski
2023-07-20 9:16 ` Kent Gibson
2023-07-20 9:38 ` Bartosz Golaszewski
2023-07-20 9:52 ` Kent Gibson
2023-07-20 12:30 ` Bartosz Golaszewski
2023-07-20 13:37 ` Kent Gibson
2023-07-20 15:01 ` Bartosz Golaszewski
2023-07-21 1:37 ` Kent Gibson
2023-07-20 8:42 ` Andy Shevchenko
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=20230719192057.172560-2-brgl@bgdev.pl \
--to=brgl@bgdev.pl \
--cc=andriy.shevchenko@linux.intel.com \
--cc=bartosz.golaszewski@linaro.org \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=viresh.kumar@linaro.org \
--cc=warthog618@gmail.com \
/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).