From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
Tomasz Duszynski <tduszynski@marvell.com>,
Long Li <longli@microsoft.com>, Wei Hu <weh@microsoft.com>
Subject: [PATCH v2 6/9] drivers/bus: remove duplicate sysfs string helpers
Date: Sat, 12 Sep 2026 10:02:18 -0700 [thread overview]
Message-ID: <20260912170338.486978-7-stephen@networkplumber.org> (raw)
In-Reply-To: <20260912170338.486978-1-stephen@networkplumber.org>
get_sysfs_string() in the vmbus bus and read_sysfs_string() in the
platform bus are both open coded copies of what the EAL routine now
provides. Each had a single caller.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
drivers/bus/platform/platform.c | 33 +++---------------------
drivers/bus/vmbus/linux/vmbus_bus.c | 39 +++--------------------------
2 files changed, 8 insertions(+), 64 deletions(-)
diff --git a/drivers/bus/platform/platform.c b/drivers/bus/platform/platform.c
index 9585fb79e9..c511893aab 100644
--- a/drivers/bus/platform/platform.c
+++ b/drivers/bus/platform/platform.c
@@ -187,40 +187,15 @@ device_unmap_resources(struct rte_platform_device *pdev)
pdev->num_resource = 0;
}
-static int
-read_sysfs_string(const char *path, char *buf, size_t size)
-{
- FILE *f;
- char *p;
-
- f = fopen(path, "r");
- if (f == NULL)
- return -errno;
-
- if (fgets(buf, size, f) == NULL) {
- fclose(f);
- return -ENODATA;
- }
-
- fclose(f);
-
- p = strrchr(buf, '\n');
- if (p != NULL)
- *p = '\0';
-
- return 0;
-}
-
static char *
of_resource_name(const char *dev_name, int index)
{
- char path[PATH_MAX], buf[BUFSIZ] = { };
- int num = 0, ret;
+ char buf[BUFSIZ] = { };
+ int num = 0;
char *name;
- snprintf(path, sizeof(path), PLATFORM_BUS_DEVICES_PATH "/%s/of_node/reg-names", dev_name);
- ret = read_sysfs_string(path, buf, sizeof(buf) - 1);
- if (ret)
+ if (rte_sysfs_parse_string(buf, sizeof(buf) - 1,
+ PLATFORM_BUS_DEVICES_PATH "/%s/of_node/reg-names", dev_name) < 0)
return NULL;
for (name = buf; *name != 0; name += strlen(name) + 1) {
diff --git a/drivers/bus/vmbus/linux/vmbus_bus.c b/drivers/bus/vmbus/linux/vmbus_bus.c
index 9ee7983eb6..00f369120f 100644
--- a/drivers/bus/vmbus/linux/vmbus_bus.c
+++ b/drivers/bus/vmbus/linux/vmbus_bus.c
@@ -84,35 +84,6 @@ parse_sysfs_uuid(const char *filename, rte_uuid_t uu)
return 0;
}
-static int
-get_sysfs_string(const char *filename, char *buf, size_t buflen)
-{
- char *cp;
- FILE *f;
-
- f = fopen(filename, "r");
- if (f == NULL) {
- VMBUS_LOG(ERR, "cannot open sysfs value %s:%s",
- filename, strerror(errno));
- return -1;
- }
-
- if (fgets(buf, buflen, f) == NULL) {
- VMBUS_LOG(ERR, "cannot read sysfs value %s",
- filename);
- fclose(f);
- return -1;
- }
- fclose(f);
-
- /* remove trailing newline */
- cp = memchr(buf, '\n', buflen);
- if (cp)
- *cp = '\0';
-
- return 0;
-}
-
static int
vmbus_get_uio_dev(const struct rte_vmbus_device *dev,
char *dstbuf, size_t buflen)
@@ -169,7 +140,7 @@ RTE_EXPORT_SYMBOL(rte_vmbus_map_device)
int
rte_vmbus_map_device(struct rte_vmbus_device *dev)
{
- char uioname[PATH_MAX], filename[PATH_MAX];
+ char uioname[PATH_MAX];
char dirname[PATH_MAX], mapname[64];
int i;
@@ -188,11 +159,9 @@ rte_vmbus_map_device(struct rte_vmbus_device *dev)
snprintf(dirname, sizeof(dirname),
"%s/maps/map%d", uioname, i);
- snprintf(filename, sizeof(filename),
- "%s/name", dirname);
-
- if (get_sysfs_string(filename, mapname, sizeof(mapname)) < 0) {
- VMBUS_LOG(ERR, "could not read %s", filename);
+ if (rte_sysfs_parse_string(mapname, sizeof(mapname),
+ "%s/name", dirname) < 0) {
+ VMBUS_LOG(ERR, "could not read name of %s", dirname);
return -1;
}
--
2.53.0
next prev parent reply other threads:[~2026-09-12 17:04 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-12 6:30 [PATCH 0/9] consolidate sysfs access Stephen Hemminger
2026-09-12 6:30 ` [PATCH 1/9] eal: add common sysfs value routines Stephen Hemminger
2026-09-12 6:30 ` [PATCH 2/9] dma/idxd: use common sysfs routines Stephen Hemminger
2026-09-12 6:30 ` [PATCH 3/9] common/ionic: " Stephen Hemminger
2026-09-12 6:30 ` [PATCH 4/9] bus/vmbus: " Stephen Hemminger
2026-09-12 6:30 ` [PATCH 5/9] power: " Stephen Hemminger
2026-09-12 6:30 ` [PATCH 6/9] drivers/bus: remove duplicate sysfs string helpers Stephen Hemminger
2026-09-12 6:30 ` [PATCH 7/9] common/mlx5: use common sysfs routines Stephen Hemminger
2026-09-12 6:30 ` [PATCH 8/9] net/mlx5: " Stephen Hemminger
2026-09-12 6:30 ` [PATCH 9/9] net/mana: " Stephen Hemminger
2026-09-12 17:02 ` [PATCH v2 0/9] consolidate sysfs access Stephen Hemminger
2026-09-12 17:02 ` [PATCH v2 1/9] eal: add common sysfs value routines Stephen Hemminger
2026-09-12 17:02 ` [PATCH v2 2/9] dma/idxd: use common sysfs routines Stephen Hemminger
2026-09-12 17:02 ` [PATCH v2 3/9] common/ionic: " Stephen Hemminger
2026-09-12 17:02 ` [PATCH v2 4/9] bus/vmbus: " Stephen Hemminger
2026-09-12 17:02 ` [PATCH v2 5/9] power: " Stephen Hemminger
2026-09-12 17:02 ` Stephen Hemminger [this message]
2026-09-12 17:02 ` [PATCH v2 7/9] common/mlx5: " Stephen Hemminger
2026-09-12 17:02 ` [PATCH v2 8/9] net/mlx5: " Stephen Hemminger
2026-09-12 17:02 ` [PATCH v2 9/9] net/mana: " Stephen Hemminger
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=20260912170338.486978-7-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=dev@dpdk.org \
--cc=longli@microsoft.com \
--cc=tduszynski@marvell.com \
--cc=weh@microsoft.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.