[PATCH 3/3] dma/idxd: use DPDK basename function

Bruce Richardson bruce.richardson at intel.com
Wed Aug 6 15:38:33 CEST 2025


Even though the idxd_bus.c file is linux-only, we can simplify the code
through using rte_basename rather than just basename. Since rte_basename
does not modify its parameter, we can eliminate the strdup and free, and
since it also handles NULL sanely, we can remove an extra NULL check.

Signed-off-by: Bruce Richardson <bruce.richardson at intel.com>
---
 drivers/dma/idxd/idxd_bus.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/dma/idxd/idxd_bus.c b/drivers/dma/idxd/idxd_bus.c
index ba8076715d..5ae42151e6 100644
--- a/drivers/dma/idxd/idxd_bus.c
+++ b/drivers/dma/idxd/idxd_bus.c
@@ -260,17 +260,14 @@ static int search_devargs(const char *name)
 static int
 is_for_this_process_use(struct rte_dsa_device *dev, const char *name)
 {
-	char *runtime_dir = strdup(rte_eal_get_runtime_dir());
+	char prefix[256];
 	int retval = 0;
-	int prefixlen;
-	char *prefix;
+	size_t prefixlen;
 
-	if (runtime_dir == NULL)
+	prefixlen = rte_basename(rte_eal_get_runtime_dir(), prefix, sizeof(prefix));
+	if (prefixlen >= sizeof(prefix) || strcmp(prefix, ".") == 0)
 		return retval;
 
-	prefix = basename(runtime_dir);
-	prefixlen = strlen(prefix);
-
 	if (strncmp(name, "dpdk_", 5) == 0)
 		retval = 1;
 	if (strncmp(name, prefix, prefixlen) == 0 && name[prefixlen] == '_')
@@ -283,7 +280,6 @@ is_for_this_process_use(struct rte_dsa_device *dev, const char *name)
 			retval = !search_devargs(dev->device.name);
 	}
 
-	free(runtime_dir);
 	return retval;
 }
 
-- 
2.48.1



More information about the dev mailing list