From: Zev Weiss <zweiss@equinix.com>
To: Joel Stanley <joel@jms.id.au>
Cc: Bartosz Golaszewski <brgl@bgdev.pl>,
"linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>,
Andrew Jeffery <andrew@aj.id.au>,
"openbmc@lists.ozlabs.org" <openbmc@lists.ozlabs.org>
Subject: Re: [libgpiod PATCH 3/7] tools: Add value support to line name lookup
Date: Thu, 3 Feb 2022 08:37:19 +0000 [thread overview]
Message-ID: <20220203083719.GN5754@packtop> (raw)
In-Reply-To: <20220203042134.68425-4-joel@jms.id.au>
On Wed, Feb 02, 2022 at 08:21:30PM PST, Joel Stanley wrote:
>Add support for pasring the values as well as the name in
Nit: typo ("pasring")
>line_names_to_offsets.
>
>Signed-off-by: Joel Stanley <joel@jms.id.au>
>---
> tools/tools-common.c | 51 ++++++++++++++++++++++++++++++++++++++++++--
> tools/tools-common.h | 4 +++-
> 2 files changed, 52 insertions(+), 3 deletions(-)
>
>diff --git a/tools/tools-common.c b/tools/tools-common.c
>index 958933ed6d51..586577566790 100644
>--- a/tools/tools-common.c
>+++ b/tools/tools-common.c
>@@ -204,15 +204,57 @@ struct gpiod_chip *chip_by_line_name(const char *name)
> return NULL;
> }
>
>+char *split_line(const char *line_pair)
>+{
>+ char *name_end;
>+ size_t name_len;
>+ char *line_name;
>+
>+ name_end = strchr(line_pair, '=');
>+ if (!name_end)
>+ die("invalid name/value '%s'", line_pair);
>+
>+ name_len = name_end - line_pair;
>+
>+ if (name_len > 32)
>+ die("line name exceeds maximum length");
For mult-line invocations it might be nice to give some feedback on
which line name we errored out on here; perhaps
die("%s: line name exceeds maximum length", line_pair);
or move the check after the strncpy() below and use line_name if we want
a slightly tidier message without the trailing "=<value>"?
>+
>+ line_name = calloc(1, name_len + 1);
>+ strncpy(line_name, line_pair, name_len);
>+
>+ return line_name;
>+}
>+
> int line_names_to_offsets(struct gpiod_chip *chip, char **lines,
>- unsigned int *offsets, int num_lines)
>+ unsigned int *offsets,
>+ int *values,
>+ int num_lines)
> {
> int i;
>
> for (i = 0; i < num_lines; i++) {
>- const char *line_name = lines[i];
>+ char *line_name;
>+ int value;
> int offset;
>
>+ if (values) {
>+ const char *line_pair = lines[i];
>+ char *name_end;
>+ int rv;
>+
>+ line_name = split_line(line_pair);
>+ name_end = strchr(line_pair, '=');
>+
>+ rv = sscanf(name_end, "=%d", &value);
>+ if (rv != 1)
>+ die("invalid offset<->value mapping: %s", line_pair);
>+
>+ if (value != 0 && value != 1)
>+ die("value must be 0 or 1: %s", line_pair);
>+ } else {
>+ line_name = lines[i];
>+ }
>+
> offset = gpiod_chip_find_line(chip, line_name);
>
> if (offset < 0) {
>@@ -222,6 +264,11 @@ int line_names_to_offsets(struct gpiod_chip *chip, char **lines,
> }
>
> offsets[i] = offset;
>+
>+ if (values) {
>+ values[i] = value;
>+ free(line_name);
>+ }
> }
>
> return 0;
>diff --git a/tools/tools-common.h b/tools/tools-common.h
>index 7affea436a60..723999011733 100644
>--- a/tools/tools-common.h
>+++ b/tools/tools-common.h
>@@ -33,6 +33,8 @@ struct gpiod_chip *chip_open_by_name(const char *name);
> struct gpiod_chip *chip_open_lookup(const char *device);
> struct gpiod_chip *chip_by_line_name(const char *name);
> int line_names_to_offsets(struct gpiod_chip *chip, char **lines,
>- unsigned int *offsets, int num_lines);
>+ unsigned int *offsets, int *values,
>+ int num_lines);
>+char *split_line(const char *line_pair);
>
> #endif /* __GPIOD_TOOLS_COMMON_H__ */
>--
>2.34.1
>
WARNING: multiple messages have this Message-ID (diff)
From: Zev Weiss <zweiss@equinix.com>
To: Joel Stanley <joel@jms.id.au>
Cc: Andrew Jeffery <andrew@aj.id.au>,
"linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>,
Bartosz Golaszewski <brgl@bgdev.pl>,
"openbmc@lists.ozlabs.org" <openbmc@lists.ozlabs.org>
Subject: Re: [libgpiod PATCH 3/7] tools: Add value support to line name lookup
Date: Thu, 3 Feb 2022 08:37:19 +0000 [thread overview]
Message-ID: <20220203083719.GN5754@packtop> (raw)
In-Reply-To: <20220203042134.68425-4-joel@jms.id.au>
On Wed, Feb 02, 2022 at 08:21:30PM PST, Joel Stanley wrote:
>Add support for pasring the values as well as the name in
Nit: typo ("pasring")
>line_names_to_offsets.
>
>Signed-off-by: Joel Stanley <joel@jms.id.au>
>---
> tools/tools-common.c | 51 ++++++++++++++++++++++++++++++++++++++++++--
> tools/tools-common.h | 4 +++-
> 2 files changed, 52 insertions(+), 3 deletions(-)
>
>diff --git a/tools/tools-common.c b/tools/tools-common.c
>index 958933ed6d51..586577566790 100644
>--- a/tools/tools-common.c
>+++ b/tools/tools-common.c
>@@ -204,15 +204,57 @@ struct gpiod_chip *chip_by_line_name(const char *name)
> return NULL;
> }
>
>+char *split_line(const char *line_pair)
>+{
>+ char *name_end;
>+ size_t name_len;
>+ char *line_name;
>+
>+ name_end = strchr(line_pair, '=');
>+ if (!name_end)
>+ die("invalid name/value '%s'", line_pair);
>+
>+ name_len = name_end - line_pair;
>+
>+ if (name_len > 32)
>+ die("line name exceeds maximum length");
For mult-line invocations it might be nice to give some feedback on
which line name we errored out on here; perhaps
die("%s: line name exceeds maximum length", line_pair);
or move the check after the strncpy() below and use line_name if we want
a slightly tidier message without the trailing "=<value>"?
>+
>+ line_name = calloc(1, name_len + 1);
>+ strncpy(line_name, line_pair, name_len);
>+
>+ return line_name;
>+}
>+
> int line_names_to_offsets(struct gpiod_chip *chip, char **lines,
>- unsigned int *offsets, int num_lines)
>+ unsigned int *offsets,
>+ int *values,
>+ int num_lines)
> {
> int i;
>
> for (i = 0; i < num_lines; i++) {
>- const char *line_name = lines[i];
>+ char *line_name;
>+ int value;
> int offset;
>
>+ if (values) {
>+ const char *line_pair = lines[i];
>+ char *name_end;
>+ int rv;
>+
>+ line_name = split_line(line_pair);
>+ name_end = strchr(line_pair, '=');
>+
>+ rv = sscanf(name_end, "=%d", &value);
>+ if (rv != 1)
>+ die("invalid offset<->value mapping: %s", line_pair);
>+
>+ if (value != 0 && value != 1)
>+ die("value must be 0 or 1: %s", line_pair);
>+ } else {
>+ line_name = lines[i];
>+ }
>+
> offset = gpiod_chip_find_line(chip, line_name);
>
> if (offset < 0) {
>@@ -222,6 +264,11 @@ int line_names_to_offsets(struct gpiod_chip *chip, char **lines,
> }
>
> offsets[i] = offset;
>+
>+ if (values) {
>+ values[i] = value;
>+ free(line_name);
>+ }
> }
>
> return 0;
>diff --git a/tools/tools-common.h b/tools/tools-common.h
>index 7affea436a60..723999011733 100644
>--- a/tools/tools-common.h
>+++ b/tools/tools-common.h
>@@ -33,6 +33,8 @@ struct gpiod_chip *chip_open_by_name(const char *name);
> struct gpiod_chip *chip_open_lookup(const char *device);
> struct gpiod_chip *chip_by_line_name(const char *name);
> int line_names_to_offsets(struct gpiod_chip *chip, char **lines,
>- unsigned int *offsets, int num_lines);
>+ unsigned int *offsets, int *values,
>+ int num_lines);
>+char *split_line(const char *line_pair);
>
> #endif /* __GPIOD_TOOLS_COMMON_H__ */
>--
>2.34.1
>
next prev parent reply other threads:[~2022-02-03 8:37 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-03 4:21 [libgpiod PATCH 0/7] tools: Add by-name support Joel Stanley
2022-02-03 4:21 ` Joel Stanley
2022-02-03 4:21 ` [libgpiod PATCH 1/7] tools: Clean up scandir memory allocations Joel Stanley
2022-02-03 4:21 ` Joel Stanley
2022-02-08 11:21 ` Bartosz Golaszewski
2022-02-08 11:21 ` Bartosz Golaszewski
2022-02-03 4:21 ` [libgpiod PATCH 2/7] tools: Add line name to offset lookup helper Joel Stanley
2022-02-03 4:21 ` Joel Stanley
2022-02-03 4:21 ` [libgpiod PATCH 3/7] tools: Add value support to line name lookup Joel Stanley
2022-02-03 4:21 ` Joel Stanley
2022-02-03 8:37 ` Zev Weiss [this message]
2022-02-03 8:37 ` Zev Weiss
2022-02-03 4:21 ` [libgpiod PATCH 4/7] tools: gpioget: Add by-name support Joel Stanley
2022-02-03 4:21 ` Joel Stanley
2022-02-03 8:37 ` Zev Weiss
2022-02-03 8:37 ` Zev Weiss
2022-02-03 4:21 ` [libgpiod PATCH 5/7] tools: gpioset: " Joel Stanley
2022-02-03 4:21 ` Joel Stanley
2022-02-03 8:37 ` Zev Weiss
2022-02-03 8:37 ` Zev Weiss
2022-02-03 4:21 ` [libgpiod PATCH 6/7] gpio-tools-test: Add gpioset --by-name tests Joel Stanley
2022-02-03 4:21 ` Joel Stanley
2022-02-03 4:21 ` [libgpiod PATCH 7/7] gpio-tools-test: Add gpioget " Joel Stanley
2022-02-03 4:21 ` Joel Stanley
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=20220203083719.GN5754@packtop \
--to=zweiss@equinix.com \
--cc=andrew@aj.id.au \
--cc=brgl@bgdev.pl \
--cc=joel@jms.id.au \
--cc=linux-gpio@vger.kernel.org \
--cc=openbmc@lists.ozlabs.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 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.