diff mbox series

[RFC,10/11] bus: introduce accessors

Message ID 20220628144643.1213026-11-david.marchand@redhat.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers show
Series Bus cleanup for 22.11 | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

David Marchand June 28, 2022, 2:46 p.m. UTC
Prepare for making the bus object opaque by adding one accessor.
Update existing users.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 app/test-pmd/config.c                        |  6 ++---
 app/test-pmd/testpmd.c                       |  4 +--
 app/test-pmd/testpmd.h                       |  4 +--
 app/test/test_devargs.c                      |  4 +--
 app/test/test_kni.c                          |  6 ++---
 drivers/common/mlx5/mlx5_common_pci.c        |  2 +-
 drivers/net/failsafe/failsafe.c              |  2 +-
 drivers/net/failsafe/failsafe_eal.c          |  2 +-
 drivers/net/mlx5/linux/mlx5_os.c             |  2 +-
 drivers/net/netvsc/hn_ethdev.c               |  4 +--
 examples/ethtool/lib/rte_ethtool.c           |  3 ++-
 examples/ip_pipeline/kni.c                   |  2 +-
 examples/multi_process/hotplug_mp/commands.c |  4 +--
 lib/eal/common/eal_common_bus.c              | 26 ++++++++++++--------
 lib/eal/common/eal_common_dev.c              |  8 +++---
 lib/eal/common/eal_common_devargs.c          | 12 ++++-----
 lib/eal/common/hotplug_mp.c                  |  8 +++---
 lib/eal/include/rte_bus.h                    | 13 ++++++++++
 lib/eal/version.map                          |  3 +++
 lib/ethdev/rte_ethdev.c                      | 10 ++++----
 lib/pcapng/rte_pcapng.c                      |  2 +-
 21 files changed, 75 insertions(+), 52 deletions(-)
diff mbox series

Patch

diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index 82db14f3a6..3c027701e3 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -612,7 +612,7 @@  device_infos_display(const char *identifier)
 		if (identifier && da.bus != next)
 			continue;
 
-		snprintf(devstr, sizeof(devstr), "bus=%s", next->name);
+		snprintf(devstr, sizeof(devstr), "bus=%s", rte_bus_name(next));
 		RTE_DEV_FOREACH(dev, devstr, &dev_iter) {
 
 			if (!dev->driver)
@@ -623,7 +623,7 @@  device_infos_display(const char *identifier)
 				continue;
 			printf("\n%s Infos for device %s %s\n",
 			       info_border, dev->name, info_border);
-			printf("Bus name: %s", dev->bus->name);
+			printf("Bus name: %s", rte_bus_name(dev->bus));
 			printf("\nDriver name: %s", dev->driver->name);
 			printf("\nDevargs: %s",
 			       dev->devargs ? dev->devargs->args : "");
@@ -1076,7 +1076,7 @@  port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
 	}
 
 	bus = rte_bus_find_by_device(ports[port_id].dev_info.device);
-	if (bus && !strcmp(bus->name, "pci")) {
+	if (bus && !strcmp(rte_bus_name(bus), "pci")) {
 		pci_dev = RTE_DEV_TO_PCI(ports[port_id].dev_info.device);
 	} else {
 		fprintf(stderr, "Not a PCI device\n");
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index addcbcac85..51c2488b45 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -3507,9 +3507,9 @@  detach_devargs(char *identifier)
 		}
 	}
 
-	if (rte_eal_hotplug_remove(da.bus->name, da.name) != 0) {
+	if (rte_eal_hotplug_remove(rte_bus_name(da.bus), da.name) != 0) {
 		TESTPMD_LOG(ERR, "Failed to detach device %s(%s)\n",
-			    da.name, da.bus->name);
+			    da.name, rte_bus_name(da.bus));
 		rte_devargs_reset(&da);
 		return;
 	}
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 34bdccef71..ea242de34c 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -817,7 +817,7 @@  port_pci_reg_read(struct rte_port *port, uint32_t reg_off)
 	}
 
 	bus = rte_bus_find_by_device(port->dev_info.device);
-	if (bus && !strcmp(bus->name, "pci")) {
+	if (bus && !strcmp(rte_bus_name(bus), "pci")) {
 		pci_dev = RTE_DEV_TO_PCI(port->dev_info.device);
 	} else {
 		fprintf(stderr, "Not a PCI device\n");
@@ -845,7 +845,7 @@  port_pci_reg_write(struct rte_port *port, uint32_t reg_off, uint32_t reg_v)
 	}
 
 	bus = rte_bus_find_by_device(port->dev_info.device);
-	if (bus && !strcmp(bus->name, "pci")) {
+	if (bus && !strcmp(rte_bus_name(bus), "pci")) {
 		pci_dev = RTE_DEV_TO_PCI(port->dev_info.device);
 	} else {
 		fprintf(stderr, "Not a PCI device\n");
diff --git a/app/test/test_devargs.c b/app/test/test_devargs.c
index 16621285d2..ac5bc34c18 100644
--- a/app/test/test_devargs.c
+++ b/app/test/test_devargs.c
@@ -98,9 +98,9 @@  test_valid_devargs_cases(const struct devargs_case *list, size_t n)
 			      list[i].bus_kv) != 0)
 			goto fail;
 		if (list[i].bus != NULL &&
-		    strcmp(da.bus->name, list[i].bus) != 0) {
+		    strcmp(rte_bus_name(da.bus), list[i].bus) != 0) {
 			printf("rte_devargs_parse(%s) bus name (%s) not expected (%s)\n",
-			       list[i].devargs, da.bus->name, list[i].bus);
+			       list[i].devargs, rte_bus_name(da.bus), list[i].bus);
 			goto fail;
 		}
 		if ((list[i].class_kv > 0 || list[i].class != NULL) &&
diff --git a/app/test/test_kni.c b/app/test/test_kni.c
index 9d76b6253e..524af31e01 100644
--- a/app/test/test_kni.c
+++ b/app/test/test_kni.c
@@ -446,7 +446,7 @@  test_kni_processing(uint16_t port_id, struct rte_mempool *mp)
 
 	if (info.device)
 		bus = rte_bus_find_by_device(info.device);
-	if (bus && !strcmp(bus->name, "pci")) {
+	if (bus && !strcmp(rte_bus_name(bus), "pci")) {
 		pci_dev = RTE_DEV_TO_PCI(info.device);
 		conf.addr = pci_dev->addr;
 		conf.id = pci_dev->id;
@@ -650,7 +650,7 @@  test_kni(void)
 		bus = rte_bus_find_by_device(info.device);
 	else
 		bus = NULL;
-	if (bus && !strcmp(bus->name, "pci")) {
+	if (bus && !strcmp(rte_bus_name(bus), "pci")) {
 		pci_dev = RTE_DEV_TO_PCI(info.device);
 		conf.addr = pci_dev->addr;
 		conf.id = pci_dev->id;
@@ -694,7 +694,7 @@  test_kni(void)
 		bus = rte_bus_find_by_device(info.device);
 	else
 		bus = NULL;
-	if (bus && !strcmp(bus->name, "pci")) {
+	if (bus && !strcmp(rte_bus_name(bus), "pci")) {
 		pci_dev = RTE_DEV_TO_PCI(info.device);
 		conf.addr = pci_dev->addr;
 		conf.id = pci_dev->id;
diff --git a/drivers/common/mlx5/mlx5_common_pci.c b/drivers/common/mlx5/mlx5_common_pci.c
index e708e23a7f..578bd0a9b5 100644
--- a/drivers/common/mlx5/mlx5_common_pci.c
+++ b/drivers/common/mlx5/mlx5_common_pci.c
@@ -105,7 +105,7 @@  pci_ids_table_update(const struct rte_pci_id *driver_id_table)
 bool
 mlx5_dev_is_pci(const struct rte_device *dev)
 {
-	return strcmp(dev->bus->name, "pci") == 0;
+	return strcmp(rte_bus_name(dev->bus), "pci") == 0;
 }
 
 bool
diff --git a/drivers/net/failsafe/failsafe.c b/drivers/net/failsafe/failsafe.c
index 3eb7d32b76..f69bb42add 100644
--- a/drivers/net/failsafe/failsafe.c
+++ b/drivers/net/failsafe/failsafe.c
@@ -319,7 +319,7 @@  devargs_already_listed(struct rte_devargs *devargs)
 {
 	struct rte_devargs *list_da;
 
-	RTE_EAL_DEVARGS_FOREACH(devargs->bus->name, list_da) {
+	RTE_EAL_DEVARGS_FOREACH(rte_bus_name(devargs->bus), list_da) {
 		if (strcmp(list_da->name, devargs->name) == 0)
 			/* devargs already in the list */
 			return true;
diff --git a/drivers/net/failsafe/failsafe_eal.c b/drivers/net/failsafe/failsafe_eal.c
index 130344dce2..fe5acdc1b6 100644
--- a/drivers/net/failsafe/failsafe_eal.c
+++ b/drivers/net/failsafe/failsafe_eal.c
@@ -46,7 +46,7 @@  fs_bus_init(struct rte_eth_dev *dev)
 		if (fs_ethdev_portid_get(da->name, &pid) != 0) {
 			struct rte_eth_dev_owner pid_owner;
 
-			ret = rte_eal_hotplug_add(da->bus->name,
+			ret = rte_eal_hotplug_add(rte_bus_name(da->bus),
 						  da->name,
 						  da->args);
 			if (ret < 0) {
diff --git a/drivers/net/mlx5/linux/mlx5_os.c b/drivers/net/mlx5/linux/mlx5_os.c
index 04b9614f5c..4baa4c766e 100644
--- a/drivers/net/mlx5/linux/mlx5_os.c
+++ b/drivers/net/mlx5/linux/mlx5_os.c
@@ -1191,7 +1191,7 @@  mlx5_dev_spawn(struct rte_device *dpdk_dev,
 
 	DRV_LOG(DEBUG,
 		"dev_port=%u bus=%s pci=%s master=%d representor=%d pf_bond=%d\n",
-		priv->dev_port, dpdk_dev->bus->name,
+		priv->dev_port, rte_bus_name(dpdk_dev->bus),
 		priv->pci_dev ? priv->pci_dev->name : "NONE",
 		priv->master, priv->representor, priv->pf_bond);
 
diff --git a/drivers/net/netvsc/hn_ethdev.c b/drivers/net/netvsc/hn_ethdev.c
index 93ee4a6e86..8070880c06 100644
--- a/drivers/net/netvsc/hn_ethdev.c
+++ b/drivers/net/netvsc/hn_ethdev.c
@@ -620,7 +620,7 @@  static void netvsc_hotplug_retry(void *args)
 			/* If this device has been hot removed from this
 			 * parent device, restore its args.
 			 */
-			ret = rte_eal_hotplug_add(d->bus->name, d->name,
+			ret = rte_eal_hotplug_add(rte_bus_name(d->bus), d->name,
 						  hv->vf_devargs ?
 						  hv->vf_devargs : "");
 			if (ret) {
@@ -686,7 +686,7 @@  netvsc_hotadd_callback(const char *device_name, enum rte_dev_event_type type,
 			goto free_ctx;
 		}
 
-		if (!strcmp(d->bus->name, "pci")) {
+		if (!strcmp(rte_bus_name(d->bus), "pci")) {
 			/* Start the process of figuring out if this
 			 * PCI device is a VF device
 			 */
diff --git a/examples/ethtool/lib/rte_ethtool.c b/examples/ethtool/lib/rte_ethtool.c
index 62f6de84d5..4034a241aa 100644
--- a/examples/ethtool/lib/rte_ethtool.c
+++ b/examples/ethtool/lib/rte_ethtool.c
@@ -4,6 +4,7 @@ 
 #include <stdio.h>
 #include <string.h>
 #include <stdint.h>
+
 #include <rte_string_fns.h>
 #include <rte_version.h>
 #include <rte_ethdev.h>
@@ -56,7 +57,7 @@  rte_ethtool_get_drvinfo(uint16_t port_id, struct ethtool_drvinfo *drvinfo)
 	/* TODO: replace bus_info by rte_devargs.name */
 	if (dev_info.device)
 		bus = rte_bus_find_by_device(dev_info.device);
-	if (bus && !strcmp(bus->name, "pci")) {
+	if (bus && !strcmp(rte_bus_name(bus), "pci")) {
 		pci_dev = RTE_DEV_TO_PCI(dev_info.device);
 		snprintf(drvinfo->bus_info, sizeof(drvinfo->bus_info),
 			"%04x:%02x:%02x.%x",
diff --git a/examples/ip_pipeline/kni.c b/examples/ip_pipeline/kni.c
index 270b961bba..5778a6440e 100644
--- a/examples/ip_pipeline/kni.c
+++ b/examples/ip_pipeline/kni.c
@@ -137,7 +137,7 @@  kni_create(const char *name, struct kni_params *params)
 	kni_conf.mbuf_size = mempool->buffer_size;
 	if (dev_info.device)
 		bus = rte_bus_find_by_device(dev_info.device);
-	if (bus && !strcmp(bus->name, "pci")) {
+	if (bus && !strcmp(rte_bus_name(bus), "pci")) {
 		pci_dev = RTE_DEV_TO_PCI(dev_info.device);
 		kni_conf.addr = pci_dev->addr;
 		kni_conf.id = pci_dev->id;
diff --git a/examples/multi_process/hotplug_mp/commands.c b/examples/multi_process/hotplug_mp/commands.c
index da8b5e5924..88f44e00a0 100644
--- a/examples/multi_process/hotplug_mp/commands.c
+++ b/examples/multi_process/hotplug_mp/commands.c
@@ -126,7 +126,7 @@  static void cmd_dev_attach_parsed(void *parsed_result,
 		return;
 	}
 
-	if (!rte_eal_hotplug_add(da.bus->name, da.name, da.args))
+	if (!rte_eal_hotplug_add(rte_bus_name(da.bus), da.name, da.args))
 		cmdline_printf(cl, "attached device %s\n", da.name);
 	else
 		cmdline_printf(cl, "failed to attached device %s\n",
@@ -173,7 +173,7 @@  static void cmd_dev_detach_parsed(void *parsed_result,
 	}
 
 	printf("detaching...\n");
-	if (!rte_eal_hotplug_remove(da.bus->name, da.name))
+	if (!rte_eal_hotplug_remove(rte_bus_name(da.bus), da.name))
 		cmdline_printf(cl, "detached device %s\n",
 			da.name);
 	else
diff --git a/lib/eal/common/eal_common_bus.c b/lib/eal/common/eal_common_bus.c
index baa5b532af..cbf382f967 100644
--- a/lib/eal/common/eal_common_bus.c
+++ b/lib/eal/common/eal_common_bus.c
@@ -16,11 +16,17 @@ 
 static struct rte_bus_list rte_bus_list =
 	TAILQ_HEAD_INITIALIZER(rte_bus_list);
 
+const char *
+rte_bus_name(const struct rte_bus *bus)
+{
+	return bus->name;
+}
+
 void
 rte_bus_register(struct rte_bus *bus)
 {
 	RTE_VERIFY(bus);
-	RTE_VERIFY(bus->name && strlen(bus->name));
+	RTE_VERIFY(rte_bus_name(bus) && strlen(rte_bus_name(bus)));
 	/* A bus should mandatorily have the scan implemented */
 	RTE_VERIFY(bus->scan);
 	RTE_VERIFY(bus->probe);
@@ -29,14 +35,14 @@  rte_bus_register(struct rte_bus *bus)
 	RTE_VERIFY(!bus->plug || bus->unplug);
 
 	TAILQ_INSERT_TAIL(&rte_bus_list, bus, next);
-	RTE_LOG(DEBUG, EAL, "Registered [%s] bus.\n", bus->name);
+	RTE_LOG(DEBUG, EAL, "Registered [%s] bus.\n", rte_bus_name(bus));
 }
 
 void
 rte_bus_unregister(struct rte_bus *bus)
 {
 	TAILQ_REMOVE(&rte_bus_list, bus, next);
-	RTE_LOG(DEBUG, EAL, "Unregistered [%s] bus.\n", bus->name);
+	RTE_LOG(DEBUG, EAL, "Unregistered [%s] bus.\n", rte_bus_name(bus));
 }
 
 /* Scan all the buses for registered devices */
@@ -50,7 +56,7 @@  rte_bus_scan(void)
 		ret = bus->scan();
 		if (ret)
 			RTE_LOG(ERR, EAL, "Scan for (%s) bus failed.\n",
-				bus->name);
+				rte_bus_name(bus));
 	}
 
 	return 0;
@@ -64,7 +70,7 @@  rte_bus_probe(void)
 	struct rte_bus *bus, *vbus = NULL;
 
 	TAILQ_FOREACH(bus, &rte_bus_list, next) {
-		if (!strcmp(bus->name, "vdev")) {
+		if (!strcmp(rte_bus_name(bus), "vdev")) {
 			vbus = bus;
 			continue;
 		}
@@ -72,14 +78,14 @@  rte_bus_probe(void)
 		ret = bus->probe();
 		if (ret)
 			RTE_LOG(ERR, EAL, "Bus (%s) probe failed.\n",
-				bus->name);
+				rte_bus_name(bus));
 	}
 
 	if (vbus) {
 		ret = vbus->probe();
 		if (ret)
 			RTE_LOG(ERR, EAL, "Bus (%s) probe failed.\n",
-				vbus->name);
+				rte_bus_name(vbus));
 	}
 
 	return 0;
@@ -92,7 +98,7 @@  bus_dump_one(FILE *f, struct rte_bus *bus)
 	int ret;
 
 	/* For now, dump only the bus name */
-	ret = fprintf(f, " %s\n", bus->name);
+	ret = fprintf(f, " %s\n", rte_bus_name(bus));
 
 	/* Error in case of inability in writing to stream */
 	if (ret < 0)
@@ -163,7 +169,7 @@  cmp_bus_name(const struct rte_bus *bus, const void *_name)
 {
 	const char *name = _name;
 
-	return strcmp(bus->name, name);
+	return strcmp(rte_bus_name(bus), name);
 }
 
 struct rte_bus *
@@ -213,7 +219,7 @@  rte_bus_get_iommu_class(void)
 
 		bus_iova_mode = bus->get_iommu_class();
 		RTE_LOG(DEBUG, EAL, "Bus %s wants IOVA as '%s'\n",
-			bus->name,
+			rte_bus_name(bus),
 			bus_iova_mode == RTE_IOVA_DC ? "DC" :
 			(bus_iova_mode == RTE_IOVA_PA ? "PA" : "VA"));
 		if (bus_iova_mode == RTE_IOVA_PA)
diff --git a/lib/eal/common/eal_common_dev.c b/lib/eal/common/eal_common_dev.c
index b6f0392f30..bbaf518570 100644
--- a/lib/eal/common/eal_common_dev.c
+++ b/lib/eal/common/eal_common_dev.c
@@ -140,7 +140,7 @@  local_dev_probe(const char *devargs, struct rte_device **new_dev)
 
 	if (da->bus->plug == NULL) {
 		RTE_LOG(ERR, EAL, "Function plug not supported by bus (%s)\n",
-			da->bus->name);
+			rte_bus_name(da->bus));
 		ret = -ENOTSUP;
 		goto err_devarg;
 	}
@@ -309,7 +309,7 @@  local_dev_remove(struct rte_device *dev)
 
 	if (dev->bus->unplug == NULL) {
 		RTE_LOG(ERR, EAL, "Function unplug not supported by bus (%s)\n",
-			dev->bus->name);
+			rte_bus_name(dev->bus));
 		return -ENOTSUP;
 	}
 
@@ -335,7 +335,7 @@  rte_dev_remove(struct rte_device *dev)
 		return -ENOENT;
 	}
 
-	ret = build_devargs(dev->bus->name, dev->name, "", &devargs);
+	ret = build_devargs(rte_bus_name(dev->bus), dev->name, "", &devargs);
 	if (ret != 0)
 		return ret;
 
@@ -597,7 +597,7 @@  rte_dev_iterator_init(struct rte_dev_iterator *it,
 		goto get_out;
 	}
 	if (bus != NULL && bus->dev_iterate == NULL) {
-		RTE_LOG(DEBUG, EAL, "Bus %s not supported\n", bus->name);
+		RTE_LOG(DEBUG, EAL, "Bus %s not supported\n", rte_bus_name(bus));
 		rte_errno = ENOTSUP;
 		goto get_out;
 	}
diff --git a/lib/eal/common/eal_common_devargs.c b/lib/eal/common/eal_common_devargs.c
index d5833af373..fa95c52708 100644
--- a/lib/eal/common/eal_common_devargs.c
+++ b/lib/eal/common/eal_common_devargs.c
@@ -176,7 +176,7 @@  rte_devargs_layers_parse(struct rte_devargs *devargs,
 static int
 bus_name_cmp(const struct rte_bus *bus, const void *name)
 {
-	return strncmp(bus->name, name, strlen(bus->name));
+	return strncmp(rte_bus_name(bus), name, strlen(bus->name));
 }
 
 int
@@ -206,7 +206,7 @@  rte_devargs_parse(struct rte_devargs *da, const char *dev)
 		bus = rte_bus_find(bus, bus_name_cmp, dev);
 		if (bus == NULL)
 			break;
-		devname = dev + strlen(bus->name) + 1;
+		devname = dev + strlen(rte_bus_name(bus)) + 1;
 		if (rte_bus_find_by_device_name(devname) == bus)
 			break;
 	} while (1);
@@ -301,7 +301,7 @@  rte_devargs_insert(struct rte_devargs **da)
 		if (listed_da == *da)
 			/* devargs already in the list */
 			return 0;
-		if (strcmp(listed_da->bus->name, (*da)->bus->name) == 0 &&
+		if (strcmp(rte_bus_name(listed_da->bus), (*da)->bus->name) == 0 &&
 				strcmp(listed_da->name, (*da)->name) == 0) {
 			/* device already in devargs list, must be updated */
 			(*da)->next = listed_da->next;
@@ -365,7 +365,7 @@  rte_devargs_remove(struct rte_devargs *devargs)
 		return -1;
 
 	RTE_TAILQ_FOREACH_SAFE(d, &devargs_list, next, tmp) {
-		if (strcmp(d->bus->name, devargs->bus->name) == 0 &&
+		if (strcmp(rte_bus_name(d->bus), devargs->bus->name) == 0 &&
 		    strcmp(d->name, devargs->name) == 0) {
 			TAILQ_REMOVE(&devargs_list, d, next);
 			rte_devargs_reset(d);
@@ -400,7 +400,7 @@  rte_devargs_dump(FILE *f)
 	fprintf(f, "User device list:\n");
 	TAILQ_FOREACH(devargs, &devargs_list, next) {
 		fprintf(f, "  [%s]: %s %s\n",
-			(devargs->bus ? devargs->bus->name : "??"),
+			(devargs->bus ? rte_bus_name(devargs->bus) : "??"),
 			devargs->name, devargs->args);
 	}
 }
@@ -417,7 +417,7 @@  rte_devargs_next(const char *busname, const struct rte_devargs *start)
 		da = TAILQ_FIRST(&devargs_list);
 	while (da != NULL) {
 		if (busname == NULL ||
-		    (strcmp(busname, da->bus->name) == 0))
+		    (strcmp(busname, rte_bus_name(da->bus)) == 0))
 			return da;
 		da = TAILQ_NEXT(da, next);
 	}
diff --git a/lib/eal/common/hotplug_mp.c b/lib/eal/common/hotplug_mp.c
index 1614a57752..252f147b6f 100644
--- a/lib/eal/common/hotplug_mp.c
+++ b/lib/eal/common/hotplug_mp.c
@@ -127,9 +127,9 @@  __handle_secondary_request(void *param)
 			goto rollback;
 		}
 
-		bus = rte_bus_find_by_name(da.bus->name);
+		bus = rte_bus_find_by_name(rte_bus_name(da.bus));
 		if (bus == NULL) {
-			RTE_LOG(ERR, EAL, "Cannot find bus (%s)\n", da.bus->name);
+			RTE_LOG(ERR, EAL, "Cannot find bus (%s)\n", rte_bus_name(da.bus));
 			ret = -ENOENT;
 			goto finish;
 		}
@@ -254,9 +254,9 @@  static void __handle_primary_request(void *param)
 		if (ret != 0)
 			goto quit;
 
-		bus = rte_bus_find_by_name(da->bus->name);
+		bus = rte_bus_find_by_name(rte_bus_name(da->bus));
 		if (bus == NULL) {
-			RTE_LOG(ERR, EAL, "Cannot find bus (%s)\n", da->bus->name);
+			RTE_LOG(ERR, EAL, "Cannot find bus (%s)\n", rte_bus_name(da->bus));
 			ret = -ENOENT;
 			goto quit;
 		}
diff --git a/lib/eal/include/rte_bus.h b/lib/eal/include/rte_bus.h
index 17edaa37c9..9b70f2f7b2 100644
--- a/lib/eal/include/rte_bus.h
+++ b/lib/eal/include/rte_bus.h
@@ -266,6 +266,19 @@  struct rte_bus {
 
 };
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * @param bus
+ *   A pointer to a rte_bus structure describing the bus
+ *   to be registered.
+ * @return
+ *   A pointer to the bus name string.
+ */
+__rte_experimental
+const char *rte_bus_name(const struct rte_bus *bus);
+
 /**
  * Register a Bus handler.
  *
diff --git a/lib/eal/version.map b/lib/eal/version.map
index c2a2cebf69..6f713c987d 100644
--- a/lib/eal/version.map
+++ b/lib/eal/version.map
@@ -424,6 +424,9 @@  EXPERIMENTAL {
 	rte_thread_self;
 	rte_thread_set_affinity_by_id;
 	rte_thread_set_priority;
+
+	# added in 22.11
+	rte_bus_name;
 };
 
 INTERNAL {
diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index ebbe8cca3d..c94d6573d5 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -232,11 +232,11 @@  rte_eth_iterator_init(struct rte_dev_iterator *iter, const char *devargs_str)
 	}
 
 	/* Convert bus args to new syntax for use with new API dev_iterate. */
-	if ((strcmp(iter->bus->name, "vdev") == 0) ||
-		(strcmp(iter->bus->name, "fslmc") == 0) ||
-		(strcmp(iter->bus->name, "dpaa_bus") == 0)) {
+	if ((strcmp(rte_bus_name(iter->bus), "vdev") == 0) ||
+		(strcmp(rte_bus_name(iter->bus), "fslmc") == 0) ||
+		(strcmp(rte_bus_name(iter->bus), "dpaa_bus") == 0)) {
 		bus_param_key = "name";
-	} else if (strcmp(iter->bus->name, "pci") == 0) {
+	} else if (strcmp(rte_bus_name(iter->bus), "pci") == 0) {
 		bus_param_key = "addr";
 	} else {
 		ret = -ENOTSUP;
@@ -264,7 +264,7 @@  rte_eth_iterator_init(struct rte_dev_iterator *iter, const char *devargs_str)
 error:
 	if (ret == -ENOTSUP)
 		RTE_ETHDEV_LOG(ERR, "Bus %s does not support iterating.\n",
-				iter->bus->name);
+				rte_bus_name(iter->bus));
 	rte_devargs_reset(&devargs);
 	free(bus_str);
 	free(cls_str);
diff --git a/lib/pcapng/rte_pcapng.c b/lib/pcapng/rte_pcapng.c
index 5b079cd14a..83d692d095 100644
--- a/lib/pcapng/rte_pcapng.c
+++ b/lib/pcapng/rte_pcapng.c
@@ -211,7 +211,7 @@  pcapng_add_interface(rte_pcapng_t *self, uint16_t port)
 	dev = dev_info.device;
 	if (dev)
 		snprintf(ifhw, sizeof(ifhw),
-			 "%s-%s", dev->bus->name, dev->name);
+			 "%s-%s", rte_bus_name(dev->bus), dev->name);
 
 	/* DPDK reports in units of Mbps */
 	if (rte_eth_link_get(port, &link) == 0 &&