Read the bonding interface indexes with the EAL routine rather than
opening each file and parsing it with fscanf().

The index was read with fscanf("%u") and is now converted with base
0, so a value with a leading zero would parse as octal. The kernel
does not print ifindex with leading zeros.

Signed-off-by: Stephen Hemminger <[email protected]>
---
 drivers/net/mlx5/linux/mlx5_ethdev_os.c | 17 +++++------------
 drivers/net/mlx5/linux/mlx5_os.c        | 13 +++++--------
 2 files changed, 10 insertions(+), 20 deletions(-)

diff --git a/drivers/net/mlx5/linux/mlx5_ethdev_os.c 
b/drivers/net/mlx5/linux/mlx5_ethdev_os.c
index 4bbc590e91..d1c03d66af 100644
--- a/drivers/net/mlx5/linux/mlx5_ethdev_os.c
+++ b/drivers/net/mlx5/linux/mlx5_ethdev_os.c
@@ -36,6 +36,7 @@
 #include <rte_string_fns.h>
 #include <rte_rwlock.h>
 #include <rte_cycles.h>
+#include <rte_sysfs.h>
 
 #include <mlx5_glue.h>
 #include <mlx5_devx_cmds.h>
@@ -1192,27 +1193,19 @@ mlx5_sysfs_bond_info(unsigned int pf_ifindex, unsigned 
int *ifindex,
                     char *ifname)
 {
        char name[IF_NAMESIZE];
-       FILE *file;
        unsigned int index;
-       int ret;
+       unsigned long val;
 
        if (!if_indextoname(pf_ifindex, name) || !strlen(name)) {
                rte_errno = errno;
                return -rte_errno;
        }
-       MKSTR(bond_if, "/sys/class/net/%s/master/ifindex", name);
        /* read bond ifindex */
-       file = fopen(bond_if, "rb");
-       if (file == NULL) {
-               rte_errno = errno;
-               return -rte_errno;
-       }
-       ret = fscanf(file, "%u", &index);
-       fclose(file);
-       if (ret <= 0) {
-               rte_errno = errno;
+       if (rte_sysfs_parse_uint(&val, "/sys/class/net/%s/master/ifindex", 
name) != 0) {
+               rte_errno = ENODEV;
                return -rte_errno;
        }
+       index = val;
        if (ifindex)
                *ifindex = index;
 
diff --git a/drivers/net/mlx5/linux/mlx5_os.c b/drivers/net/mlx5/linux/mlx5_os.c
index adc5878296..203e9339bb 100644
--- a/drivers/net/mlx5/linux/mlx5_os.c
+++ b/drivers/net/mlx5/linux/mlx5_os.c
@@ -29,6 +29,7 @@
 #include <rte_string_fns.h>
 #include <rte_alarm.h>
 #include <rte_eal_paging.h>
+#include <rte_sysfs.h>
 
 #include <mlx5_glue.h>
 #include <mlx5_devx_cmds.h>
@@ -2103,6 +2104,7 @@ mlx5_device_bond_pci_match(const struct ibv_device *ibdev,
                char tmp_str[IF_NAMESIZE + 32];
                struct rte_pci_addr pci_addr;
                struct mlx5_switch_info info;
+               unsigned long val;
                int ret;
 
                /* Process slave interface names in the loop. */
@@ -2140,15 +2142,10 @@ mlx5_device_bond_pci_match(const struct ibv_device 
*ibdev,
                        break;
                }
                /* Get ifindex. */
-               snprintf(tmp_str, sizeof(tmp_str),
-                        "/sys/class/net/%s/ifindex", ifname);
-               file = fopen(tmp_str, "rb");
-               if (!file)
-                       break;
-               ret = fscanf(file, "%u", &ifindex);
-               fclose(file);
-               if (ret != 1)
+               if (rte_sysfs_parse_uint(&val, "/sys/class/net/%s/ifindex",
+                               ifname) != 0)
                        break;
+               ifindex = val;
                /* Save bonding info. */
                snprintf(bond_info->ports[info.port_name].ifname,
                         sizeof(bond_info->ports[0].ifname), "%s", ifname);
-- 
2.53.0

Reply via email to