From: David Marchand <david.marchand@redhat.com>
To: hemant.agrawal@nxp.com, dev@dpdk.org
Cc: Sachin Saxena <sachin.saxena@nxp.com>
Subject: [RFC 06/11] bus/fslmc: simplify device parsing in scan
Date: Thu, 23 Jul 2026 15:53:54 +0200 [thread overview]
Message-ID: <20260723135400.3621271-7-david.marchand@redhat.com> (raw)
In-Reply-To: <20260723135400.3621271-1-david.marchand@redhat.com>
Refactor string manipulations and avoid unneeded allocation.
Signed-off-by: David Marchand <david.marchand@redhat.com>
---
drivers/bus/fslmc/fslmc_bus.c | 78 +++++++++++++----------------------
1 file changed, 28 insertions(+), 50 deletions(-)
diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c
index a7ac59173f..4f6e0bf387 100644
--- a/drivers/bus/fslmc/fslmc_bus.c
+++ b/drivers/bus/fslmc/fslmc_bus.c
@@ -116,18 +116,33 @@ dump_device_list(void)
static int
scan_one_fslmc_device(char *dev_name)
{
- char *dup_dev_name, *t_ptr;
+ enum rte_dpaa2_dev_type dev_type = DPAA2_UNKNOWN;
struct rte_dpaa2_device *dev = NULL;
+ struct {
+ const char *prefix;
+ enum rte_dpaa2_dev_type type;
+ } dev_types[] = {
+ { "dpni.", DPAA2_ETH },
+ { "dpseci.", DPAA2_CRYPTO },
+ { "dpcon.", DPAA2_CON },
+ { "dpbp.", DPAA2_BPOOL },
+ { "dpio.", DPAA2_IO },
+ { "dpci.", DPAA2_CI },
+ { "dpmcp.", DPAA2_MPORTAL },
+ { "dpdmai.", DPAA2_QDMA },
+ { "dpdmux.", DPAA2_MUX },
+ { "dprtc.", DPAA2_DPRTC },
+ { "dprc.", DPAA2_DPRC },
+ };
+ char *dev_id = NULL;
int ret = -1;
- if (!dev_name)
- return ret;
-
- /* Creating a temporary copy to perform cut-parse over string */
- dup_dev_name = strdup(dev_name);
- if (!dup_dev_name) {
- DPAA2_BUS_ERR("Unable to allocate device name memory");
- return -ENOMEM;
+ for (unsigned int i = 0; i < RTE_DIM(dev_types); i++) {
+ if (strncmp(dev_types[i].prefix, dev_name, strlen(dev_types[i].prefix)) != 0)
+ continue;
+ dev_id = dev_name + strlen(dev_types[i].prefix);
+ dev_type = dev_types[i].type;
+ break;
}
/* For all other devices, we allocate rte_dpaa2_device.
@@ -138,11 +153,11 @@ scan_one_fslmc_device(char *dev_name)
dev = calloc(1, sizeof(struct rte_dpaa2_device));
if (!dev) {
DPAA2_BUS_ERR("Unable to allocate device object");
- free(dup_dev_name);
return -ENOMEM;
}
dev->device.numa_node = SOCKET_ID_ANY;
+ dev->dev_type = dev_type;
/* Allocate interrupt instance */
dev->intr_handle =
@@ -153,46 +168,13 @@ scan_one_fslmc_device(char *dev_name)
goto cleanup;
}
- /* Parse the device name and ID */
- t_ptr = strtok(dup_dev_name, ".");
- if (!t_ptr) {
- DPAA2_BUS_ERR("Invalid device found: (%s)", dup_dev_name);
- ret = -EINVAL;
- goto cleanup;
- }
- if (!strncmp("dpni", t_ptr, 4))
- dev->dev_type = DPAA2_ETH;
- else if (!strncmp("dpseci", t_ptr, 6))
- dev->dev_type = DPAA2_CRYPTO;
- else if (!strncmp("dpcon", t_ptr, 5))
- dev->dev_type = DPAA2_CON;
- else if (!strncmp("dpbp", t_ptr, 4))
- dev->dev_type = DPAA2_BPOOL;
- else if (!strncmp("dpio", t_ptr, 4))
- dev->dev_type = DPAA2_IO;
- else if (!strncmp("dpci", t_ptr, 4))
- dev->dev_type = DPAA2_CI;
- else if (!strncmp("dpmcp", t_ptr, 5))
- dev->dev_type = DPAA2_MPORTAL;
- else if (!strncmp("dpdmai", t_ptr, 6))
- dev->dev_type = DPAA2_QDMA;
- else if (!strncmp("dpdmux", t_ptr, 6))
- dev->dev_type = DPAA2_MUX;
- else if (!strncmp("dprtc", t_ptr, 5))
- dev->dev_type = DPAA2_DPRTC;
- else if (!strncmp("dprc", t_ptr, 4))
- dev->dev_type = DPAA2_DPRC;
- else
- dev->dev_type = DPAA2_UNKNOWN;
-
- t_ptr = strtok(NULL, ".");
- if (!t_ptr) {
- DPAA2_BUS_ERR("Skipping invalid device (%s)", dup_dev_name);
+ if (dev_id == NULL) {
+ DPAA2_BUS_ERR("Skipping invalid device (%s)", dev_name);
ret = 0;
goto cleanup;
}
- sscanf(t_ptr, "%hu", &dev->object_id);
+ sscanf(dev_id, "%hu", &dev->object_id);
dev->device.name = strdup(dev_name);
if (!dev->device.name) {
DPAA2_BUS_ERR("Unable to clone device name. Out of memory");
@@ -204,12 +186,8 @@ scan_one_fslmc_device(char *dev_name)
/* Add device in the fslmc device list */
insert_in_device_list(dev);
- /* Don't need the duplicated device filesystem entry anymore */
- free(dup_dev_name);
-
return 0;
cleanup:
- free(dup_dev_name);
if (dev) {
rte_intr_instance_free(dev->intr_handle);
free(dev);
--
2.54.0
next prev parent reply other threads:[~2026-07-23 13:54 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-23 13:53 [RFC 00/11] Device unplug and bus cleanup refactoring for NXP David Marchand
2026-07-23 13:53 ` [RFC 01/11] drivers/bus: cleanup device freeing in NXP bus scan David Marchand
2026-07-23 13:53 ` [RFC 02/11] bus/dpaa: allocate interrupt during probing David Marchand
2026-07-23 13:53 ` [RFC 03/11] bus/dpaa: support unplug and use generic cleanup David Marchand
2026-07-23 13:53 ` [RFC 04/11] bus/fslmc: fix memory leaks in scan David Marchand
2026-07-23 13:53 ` [RFC 05/11] bus/fslmc: fix per type device count David Marchand
2026-07-23 13:53 ` David Marchand [this message]
2026-07-23 13:53 ` [RFC 07/11] bus/fslmc: refactor device filtering for multiprocess David Marchand
2026-07-23 13:53 ` [RFC 08/11] bus/fslmc: move unplug for some device out of VFIO David Marchand
2026-07-23 13:53 ` [RFC 09/11] bus/fslmc: call VFIO setup for some device from bus layer David Marchand
2026-07-23 13:53 ` [RFC 10/11] bus/fslmc: allocate interrupt during probing David Marchand
2026-07-23 13:53 ` [RFC 11/11] bus/fslmc: use generic cleanup David Marchand
2026-07-23 14:11 ` [RFC 00/11] Device unplug and bus cleanup refactoring for NXP Hemant Agrawal
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=20260723135400.3621271-7-david.marchand@redhat.com \
--to=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=hemant.agrawal@nxp.com \
--cc=sachin.saxena@nxp.com \
/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