From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
Andrew Boyer <andrew.boyer@amd.com>
Subject: [PATCH 3/9] common/ionic: use common sysfs routines
Date: Fri, 11 Sep 2026 23:30:22 -0700 [thread overview]
Message-ID: <20260912063319.4117869-4-stephen@networkplumber.org> (raw)
In-Reply-To: <20260912063319.4117869-1-stephen@networkplumber.org>
The three resource helpers and the UIO name lookup each built a path
with an unchecked sprintf() into a 64 byte buffer and then read the
value with fscanf(). Use the EAL routines instead; base 0 conversion
handles the "0x" prefix these files use.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
drivers/common/ionic/ionic_common_uio.c | 63 +++++--------------------
1 file changed, 12 insertions(+), 51 deletions(-)
diff --git a/drivers/common/ionic/ionic_common_uio.c b/drivers/common/ionic/ionic_common_uio.c
index aaefab918c..a796281bdd 100644
--- a/drivers/common/ionic/ionic_common_uio.c
+++ b/drivers/common/ionic/ionic_common_uio.c
@@ -19,6 +19,7 @@
#include <rte_common.h>
#include <rte_eal.h>
#include <rte_string_fns.h>
+#include <rte_sysfs.h>
#include "ionic_common.h"
@@ -63,30 +64,17 @@ struct uio_name {
static void
uio_fill_name_cache(struct uio_name *name_cache, const char *pfx)
{
- char file[64];
- FILE *fp;
- char *ret;
int name_idx = 0;
int i;
for (i = 0; i < IONIC_UIO_MAX_TRIES &&
name_idx < IONIC_MAX_DEVICES; i++) {
- sprintf(file, "/sys/class/uio/uio%d/name", i);
-
- fp = fopen(file, "r");
- if (fp == NULL)
- continue;
-
- ret = fgets(name_cache[name_idx].name, IONIC_MAX_NAME_LEN, fp);
- if (ret == NULL) {
- fclose(fp);
+ if (rte_sysfs_parse_string(name_cache[name_idx].name, IONIC_MAX_NAME_LEN,
+ "/sys/class/uio/uio%d/name", i) < 0)
continue;
- }
name_cache[name_idx].idx = i;
- fclose(fp);
-
if (strncmp(name_cache[name_idx].name, pfx, strlen(pfx)) == 0)
name_idx++;
}
@@ -215,21 +203,12 @@ static unsigned long
uio_get_res_size(int uio_idx, int res_idx)
{
unsigned long size;
- char file[64];
- FILE *fp;
-
- sprintf(file, "/sys/class/uio/uio%d/maps/map%d/size",
- uio_idx, res_idx);
- fp = fopen(file, "r");
- if (fp == NULL)
+ /* zero is the error value for all of these */
+ if (rte_sysfs_parse_uint(&size, "/sys/class/uio/uio%d/maps/map%d/size",
+ uio_idx, res_idx) < 0)
return 0;
- if (fscanf(fp, "0x%lx", &size) != 1)
- size = 0;
-
- fclose(fp);
-
return size;
}
@@ -237,21 +216,12 @@ static unsigned long
uio_get_res_phy_addr_offs(int uio_idx, int res_idx)
{
unsigned long offset;
- char file[64];
- FILE *fp;
-
- sprintf(file, "/sys/class/uio/uio%d/maps/map%d/offset",
- uio_idx, res_idx);
- fp = fopen(file, "r");
- if (fp == NULL)
+ /* zero is the error value for all of these */
+ if (rte_sysfs_parse_uint(&offset, "/sys/class/uio/uio%d/maps/map%d/offset",
+ uio_idx, res_idx) < 0)
return 0;
- if (fscanf(fp, "0x%lx", &offset) != 1)
- offset = 0;
-
- fclose(fp);
-
return offset;
}
@@ -259,21 +229,12 @@ static unsigned long
uio_get_res_phy_addr(int uio_idx, int res_idx)
{
unsigned long addr;
- char file[64];
- FILE *fp;
- sprintf(file, "/sys/class/uio/uio%d/maps/map%d/addr",
- uio_idx, res_idx);
-
- fp = fopen(file, "r");
- if (fp == NULL)
+ /* zero is the error value for all of these */
+ if (rte_sysfs_parse_uint(&addr, "/sys/class/uio/uio%d/maps/map%d/addr",
+ uio_idx, res_idx) < 0)
return 0;
- if (fscanf(fp, "0x%lx", &addr) != 1)
- addr = 0;
-
- fclose(fp);
-
return addr;
}
--
2.53.0
next prev parent reply other threads:[~2026-09-12 6:34 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 ` Stephen Hemminger [this message]
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 ` [PATCH v2 6/9] drivers/bus: remove duplicate sysfs string helpers Stephen Hemminger
2026-09-12 17:02 ` [PATCH v2 7/9] common/mlx5: use common sysfs routines 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=20260912063319.4117869-4-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=andrew.boyer@amd.com \
--cc=dev@dpdk.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