[PATCH v4 02/25] bus/uacce: set API version during scan
David Marchand
david.marchand at redhat.com
Wed May 27 09:56:26 CEST 2026
Move API version parsing from the match callback to the time where the
device object is allocated and filled, since this property is constant.
This avoids any side effect on the device object when calling the match
callback.
Signed-off-by: David Marchand <david.marchand at redhat.com>
---
drivers/bus/uacce/uacce.c | 53 ++++++++++++++++++---------------------
1 file changed, 25 insertions(+), 28 deletions(-)
diff --git a/drivers/bus/uacce/uacce.c b/drivers/bus/uacce/uacce.c
index ade2452ad5..7633007296 100644
--- a/drivers/bus/uacce/uacce.c
+++ b/drivers/bus/uacce/uacce.c
@@ -148,12 +148,35 @@ uacce_read_attr_u32(const char *dev_root, const char *attr, uint32_t *val)
return 0;
}
+static uint32_t
+uacce_calc_api_ver(const char *api, int *offset)
+{
+ int len = strlen(api);
+ int end = len - 1;
+ unsigned long ver;
+
+ while (end >= 0 && isdigit(api[end]))
+ end--;
+
+ if (end <= 0 || end == len - 1 || api[end] != 'v')
+ return 0;
+
+ ver = strtoul(api + end + 1, NULL, 10);
+ if (ver > UINT32_MAX)
+ return 0;
+
+ if (offset != NULL)
+ *offset = end + 1;
+ return (uint32_t)ver;
+}
+
static int
uacce_read_api(struct rte_uacce_device *dev)
{
int ret = uacce_read_attr(dev->dev_root, "api", dev->api, sizeof(dev->api) - 1);
if (ret < 0)
return ret;
+ dev->api_ver = uacce_calc_api_ver(dev->api, NULL);
return 0;
}
@@ -290,28 +313,6 @@ uacce_scan(void)
return -1;
}
-static uint32_t
-uacce_calc_api_ver(const char *api, int *offset)
-{
- int len = strlen(api);
- int end = len - 1;
- unsigned long ver;
-
- while (end >= 0 && isdigit(api[end]))
- end--;
-
- if (end <= 0 || end == len - 1 || api[end] != 'v')
- return 0;
-
- ver = strtoul(api + end + 1, NULL, 10);
- if (ver > UINT32_MAX)
- return 0;
-
- if (offset != NULL)
- *offset = end + 1;
- return (uint32_t)ver;
-}
-
static bool
uacce_match_api(const struct rte_uacce_device *dev, bool forward_compat,
const struct rte_uacce_id *id_table)
@@ -330,10 +331,9 @@ uacce_match_api(const struct rte_uacce_device *dev, bool forward_compat,
}
static bool
-uacce_match(const struct rte_uacce_driver *dr, struct rte_uacce_device *dev)
+uacce_match(const struct rte_uacce_driver *dr, const struct rte_uacce_device *dev)
{
bool forward_compat = !!(dr->drv_flags & RTE_UACCE_DRV_FORWARD_COMPATIBILITY_DEV);
- uint32_t api_ver = uacce_calc_api_ver(dev->api, NULL);
const struct rte_uacce_id *id_table;
const char *map;
uint32_t len;
@@ -342,10 +342,8 @@ uacce_match(const struct rte_uacce_driver *dr, struct rte_uacce_device *dev)
if (!uacce_match_api(dev, forward_compat, id_table))
continue;
- if (id_table->dev_alg == NULL) {
- dev->api_ver = api_ver;
+ if (id_table->dev_alg == NULL)
return true;
- }
/* The dev->algs's algrothims is separated by new line, for
* example: dev->algs could be: aaa\nbbbb\ncc, which has three
@@ -361,7 +359,6 @@ uacce_match(const struct rte_uacce_driver *dr, struct rte_uacce_device *dev)
if (map[len] != '\0' && map[len] != '\n')
continue;
- dev->api_ver = api_ver;
return true;
}
--
2.53.0
More information about the dev
mailing list