From: Parav Pandit <parav@nvidia.com>
To: <dsahern@gmail.com>, <stephen@networkplumber.org>,
<netdev@vger.kernel.org>
Cc: Parav Pandit <parav@nvidia.com>, Jiri Pirko <jiri@nvidia.com>
Subject: [PATCH iproute2-next 1/4] devlink: Use library provided string processing APIs
Date: Mon, 1 Mar 2021 12:56:51 +0200 [thread overview]
Message-ID: <20210301105654.291949-2-parav@nvidia.com> (raw)
In-Reply-To: <20210301105654.291949-1-parav@nvidia.com>
User helper routines provided by library for counting slash and
splitting string on delimiter.
Signed-off-by: Parav Pandit <parav@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
---
devlink/devlink.c | 43 +++++++++----------------------------------
1 file changed, 9 insertions(+), 34 deletions(-)
diff --git a/devlink/devlink.c b/devlink/devlink.c
index c6e85ff9..85f90baf 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -866,31 +866,6 @@ static int ifname_map_rev_lookup(struct dl *dl, const char *bus_name,
return -ENOENT;
}
-static unsigned int strslashcount(char *str)
-{
- unsigned int count = 0;
- char *pos = str;
-
- while ((pos = strchr(pos, '/'))) {
- count++;
- pos++;
- }
- return count;
-}
-
-static int strslashrsplit(char *str, char **before, char **after)
-{
- char *slash;
-
- slash = strrchr(str, '/');
- if (!slash)
- return -EINVAL;
- *slash = '\0';
- *before = str;
- *after = slash + 1;
- return 0;
-}
-
static int strtouint64_t(const char *str, uint64_t *p_val)
{
char *endptr;
@@ -965,7 +940,7 @@ static int strtobool(const char *str, bool *p_val)
static int __dl_argv_handle(char *str, char **p_bus_name, char **p_dev_name)
{
- strslashrsplit(str, p_bus_name, p_dev_name);
+ str_split_by_char(str, p_bus_name, p_dev_name, '/');
return 0;
}
@@ -977,7 +952,7 @@ static int dl_argv_handle(struct dl *dl, char **p_bus_name, char **p_dev_name)
pr_err("Devlink identification (\"bus_name/dev_name\") expected\n");
return -EINVAL;
}
- if (strslashcount(str) != 1) {
+ if (get_str_char_count(str, '/') != 1) {
pr_err("Wrong devlink identification string format.\n");
pr_err("Expected \"bus_name/dev_name\".\n");
return -EINVAL;
@@ -993,7 +968,7 @@ static int __dl_argv_handle_port(char *str,
char *portstr;
int err;
- err = strslashrsplit(str, &handlestr, &portstr);
+ err = str_split_by_char(str, &handlestr, &portstr, '/');
if (err) {
pr_err("Port identification \"%s\" is invalid\n", str);
return err;
@@ -1004,7 +979,7 @@ static int __dl_argv_handle_port(char *str,
portstr);
return err;
}
- err = strslashrsplit(handlestr, p_bus_name, p_dev_name);
+ err = str_split_by_char(handlestr, p_bus_name, p_dev_name, '/');
if (err) {
pr_err("Port identification \"%s\" is invalid\n", str);
return err;
@@ -1037,7 +1012,7 @@ static int dl_argv_handle_port(struct dl *dl, char **p_bus_name,
pr_err("Port identification (\"bus_name/dev_name/port_index\" or \"netdev ifname\") expected.\n");
return -EINVAL;
}
- slash_count = strslashcount(str);
+ slash_count = get_str_char_count(str, '/');
switch (slash_count) {
case 0:
return __dl_argv_handle_port_ifname(dl, str, p_bus_name,
@@ -1066,7 +1041,7 @@ static int dl_argv_handle_both(struct dl *dl, char **p_bus_name,
"Port identification (\"bus_name/dev_name/port_index\" or \"netdev ifname\")\n");
return -EINVAL;
}
- slash_count = strslashcount(str);
+ slash_count = get_str_char_count(str, '/');
if (slash_count == 1) {
err = __dl_argv_handle(str, p_bus_name, p_dev_name);
if (err)
@@ -1098,12 +1073,12 @@ static int __dl_argv_handle_region(char *str, char **p_bus_name,
char *handlestr;
int err;
- err = strslashrsplit(str, &handlestr, p_region);
+ err = str_split_by_char(str, &handlestr, p_region, '/');
if (err) {
pr_err("Region identification \"%s\" is invalid\n", str);
return err;
}
- err = strslashrsplit(handlestr, p_bus_name, p_dev_name);
+ err = str_split_by_char(handlestr, p_bus_name, p_dev_name, '/');
if (err) {
pr_err("Region identification \"%s\" is invalid\n", str);
return err;
@@ -1122,7 +1097,7 @@ static int dl_argv_handle_region(struct dl *dl, char **p_bus_name,
return -EINVAL;
}
- slash_count = strslashcount(str);
+ slash_count = get_str_char_count(str, '/');
if (slash_count != 2) {
pr_err("Wrong region identification string format.\n");
pr_err("Expected \"bus_name/dev_name/region\" identification.\n"".\n");
--
2.26.2
next prev parent reply other threads:[~2021-03-01 10:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-01 10:56 [PATCH iproute2-next 0/4] devlink: Use utils helpers Parav Pandit
2021-03-01 10:56 ` Parav Pandit [this message]
2021-03-01 10:56 ` [PATCH iproute2-next 2/4] utils: Introduce helper routines for generic socket recv Parav Pandit
2021-03-01 10:56 ` [PATCH iproute2-next 3/4] devlink: Use generic socket helpers from library Parav Pandit
2021-03-01 10:56 ` [PATCH iproute2-next 4/4] devlink: Add error print when unknown values specified Parav Pandit
2021-03-03 4:02 ` [PATCH iproute2-next 0/4] devlink: Use utils helpers David Ahern
2021-03-03 4:10 ` patchwork-bot+netdevbpf
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=20210301105654.291949-2-parav@nvidia.com \
--to=parav@nvidia.com \
--cc=dsahern@gmail.com \
--cc=jiri@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.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).