DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	Andrew Boyer <andrew.boyer@amd.com>
Subject: [PATCH v2 3/9] common/ionic: use common sysfs routines
Date: Sat, 12 Sep 2026 10:02:15 -0700	[thread overview]
Message-ID: <20260912170338.486978-4-stephen@networkplumber.org> (raw)
In-Reply-To: <20260912170338.486978-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.

The scan walks /sys/class/uio, so it only ever found anything on
Linux. Build the implementation there only, and keep no-op stubs
for the rest so that the vdev probe in net/ionic and crypto/ionic
still links where it did before.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/common/ionic/ionic_common_uio.c | 102 ++++++++++++------------
 1 file changed, 51 insertions(+), 51 deletions(-)

diff --git a/drivers/common/ionic/ionic_common_uio.c b/drivers/common/ionic/ionic_common_uio.c
index aaefab918c..04c184c2ee 100644
--- a/drivers/common/ionic/ionic_common_uio.c
+++ b/drivers/common/ionic/ionic_common_uio.c
@@ -22,6 +22,16 @@
 
 #include "ionic_common.h"
 
+/*
+ * The mnic and mcrypt devices are found by walking /sys/class/uio,
+ * so this only ever does anything on Linux. The stubs at the end of
+ * the file keep the vdev probe in net/ionic and crypto/ionic linking
+ * on other systems, where the scan would have found nothing anyway.
+ */
+#ifdef RTE_EXEC_ENV_LINUX
+
+#include <rte_sysfs.h>
+
 #define IONIC_MDEV_UNK      "mdev_unknown"
 #define IONIC_MNIC          "cpu_mnic"
 #define IONIC_MCRYPT        "cpu_mcrypt"
@@ -63,30 +73,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)
+		if (rte_sysfs_parse_string(name_cache[name_idx].name, IONIC_MAX_NAME_LEN,
+				"/sys/class/uio/uio%d/name", i) < 0)
 			continue;
 
-		ret = fgets(name_cache[name_idx].name, IONIC_MAX_NAME_LEN, fp);
-		if (ret == NULL) {
-			fclose(fp);
-			continue;
-		}
-
 		name_cache[name_idx].idx = i;
 
-		fclose(fp);
-
 		if (strncmp(name_cache[name_idx].name, pfx, strlen(pfx)) == 0)
 			name_idx++;
 	}
@@ -215,21 +212,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 +225,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 +238,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;
 }
 
@@ -338,3 +308,33 @@ ionic_uio_rel_rsrc(const char *name, int idx, struct ionic_dev_bar *bar)
 	offs = uio_get_res_phy_addr_offs(num, idx);
 	munmap(((char *)bar->vaddr) - offs, bar->len);
 }
+
+#else /* !RTE_EXEC_ENV_LINUX */
+
+RTE_EXPORT_INTERNAL_SYMBOL(ionic_uio_scan_mnet_devices)
+void
+ionic_uio_scan_mnet_devices(void)
+{
+}
+
+RTE_EXPORT_INTERNAL_SYMBOL(ionic_uio_scan_mcrypt_devices)
+void
+ionic_uio_scan_mcrypt_devices(void)
+{
+}
+
+RTE_EXPORT_INTERNAL_SYMBOL(ionic_uio_get_rsrc)
+void
+ionic_uio_get_rsrc(const char *name __rte_unused, int idx __rte_unused,
+		struct ionic_dev_bar *bar __rte_unused)
+{
+}
+
+RTE_EXPORT_INTERNAL_SYMBOL(ionic_uio_rel_rsrc)
+void
+ionic_uio_rel_rsrc(const char *name __rte_unused, int idx __rte_unused,
+		struct ionic_dev_bar *bar __rte_unused)
+{
+}
+
+#endif /* RTE_EXEC_ENV_LINUX */
-- 
2.53.0


  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   ` Stephen Hemminger [this message]
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=20260912170338.486978-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