All of lore.kernel.org
 help / color / mirror / Atom feed
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>,
	Jack Winch <sunt.un.morcov@gmail.com>,
	Helmut Grohne <helmut.grohne@intenta.de>,
	Ben Hutchings <ben.hutchings@essensium.com>
Cc: linux-gpio@vger.kernel.org, Bartosz Golaszewski <brgl@bgdev.pl>
Subject: [libgpiod v2][PATCH 1/3] chip: provide gpiod_chip_get_path()
Date: Fri, 30 Jul 2021 16:43:54 +0200	[thread overview]
Message-ID: <20210730144356.23079-2-brgl@bgdev.pl> (raw)
In-Reply-To: <20210730144356.23079-1-brgl@bgdev.pl>

Provide a chip getter for retrieving the path to the device file used to
get the GPIO chip handle.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
 include/gpiod.h |  7 +++++++
 lib/chip.c      | 15 ++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/include/gpiod.h b/include/gpiod.h
index 56dc986..d3c327b 100644
--- a/include/gpiod.h
+++ b/include/gpiod.h
@@ -88,6 +88,13 @@ const char *gpiod_chip_get_name(struct gpiod_chip *chip);
  */
 const char *gpiod_chip_get_label(struct gpiod_chip *chip);
 
+/**
+ * @brief Get the path used to open this GPIO chip.
+ * @param chip GPIO chip object.
+ * @return Path to the file passed as argument to ::gpiod_chip_open.
+ */
+const char *gpiod_chip_get_path(struct gpiod_chip *chip);
+
 /**
  * @brief Get the number of GPIO lines exposed by this chip.
  * @param chip GPIO chip object.
diff --git a/lib/chip.c b/lib/chip.c
index a200ef2..6fcada9 100644
--- a/lib/chip.c
+++ b/lib/chip.c
@@ -18,6 +18,7 @@ struct gpiod_chip {
 	unsigned int num_lines;
 	char name[32];
 	char label[32];
+	char *path;
 };
 
 GPIOD_API struct gpiod_chip *gpiod_chip_open(const char *path)
@@ -40,9 +41,13 @@ GPIOD_API struct gpiod_chip *gpiod_chip_open(const char *path)
 	memset(chip, 0, sizeof(*chip));
 	memset(&info, 0, sizeof(info));
 
+	chip->path = strdup(path);
+	if (!chip->path)
+		goto err_free_chip;
+
 	ret = ioctl(fd, GPIO_GET_CHIPINFO_IOCTL, &info);
 	if (ret < 0)
-		goto err_free_chip;
+		goto err_free_path;
 
 	chip->fd = fd;
 	chip->num_lines = info.lines;
@@ -65,6 +70,8 @@ GPIOD_API struct gpiod_chip *gpiod_chip_open(const char *path)
 
 	return chip;
 
+err_free_path:
+	free(chip->path);
 err_free_chip:
 	free(chip);
 err_close_fd:
@@ -79,6 +86,7 @@ GPIOD_API void gpiod_chip_close(struct gpiod_chip *chip)
 		return;
 
 	close(chip->fd);
+	free(chip->path);
 	free(chip);
 }
 
@@ -92,6 +100,11 @@ GPIOD_API const char *gpiod_chip_get_label(struct gpiod_chip *chip)
 	return chip->label;
 }
 
+GPIOD_API const char *gpiod_chip_get_path(struct gpiod_chip *chip)
+{
+	return chip->path;
+}
+
 GPIOD_API unsigned int gpiod_chip_get_num_lines(struct gpiod_chip *chip)
 {
 	return chip->num_lines;
-- 
2.30.1


  reply	other threads:[~2021-07-30 14:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-30 14:43 [libgpiod v2][PATCH 0/3] libgpiod v2: new API improvements Bartosz Golaszewski
2021-07-30 14:43 ` Bartosz Golaszewski [this message]
2021-07-30 14:43 ` [libgpiod v2][PATCH 2/3] line-info: provide gpiod_line_info_get_event_clock() Bartosz Golaszewski
2021-07-31  2:27   ` Kent Gibson
2021-08-02  8:12     ` Bartosz Golaszewski
2021-07-30 14:43 ` [libgpiod v2][PATCH 3/3] treewide: unify the line settings defines 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=20210730144356.23079-2-brgl@bgdev.pl \
    --to=brgl@bgdev.pl \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=ben.hutchings@essensium.com \
    --cc=helmut.grohne@intenta.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=sunt.un.morcov@gmail.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.