[PATCH v3 6/9] drivers/bus: remove duplicate sysfs string helpers
Stephen Hemminger
stephen at networkplumber.org
Mon Sep 14 19:36:19 CEST 2026
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 at 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
More information about the dev
mailing list