if (rte_devargs_parsef(&da, "%s", identifier)) {
printf("cannot parse identifier\n");
- if (da.args)
- free(da.args);
return;
}
}
}
};
+ rte_devargs_reset(&da);
}
void
memset(&da, 0, sizeof(da));
if (rte_devargs_parsef(&da, "%s", identifier)) {
printf("cannot parse identifier\n");
- if (da.args)
- free(da.args);
return;
}
if (ports[port_id].port_status != RTE_PORT_STOPPED) {
printf("Port %u not stopped\n", port_id);
rte_eth_iterator_cleanup(&iterator);
+ rte_devargs_reset(&da);
return;
}
port_flow_flush(port_id);
if (rte_eal_hotplug_remove(da.bus->name, da.name) != 0) {
TESTPMD_LOG(ERR, "Failed to detach device %s(%s)\n",
da.name, da.bus->name);
+ rte_devargs_reset(&da);
return;
}
printf("Device %s is detached\n", identifier);
printf("Now total ports is %d\n", nb_ports);
printf("Done\n");
+ rte_devargs_reset(&da);
}
void
devargs->bus = &rte_vdev_bus;
if (args)
- devargs->args = strdup(args);
+ devargs->data = strdup(args);
else
- devargs->args = strdup("");
+ devargs->data = strdup("");
+ devargs->args = devargs->data;
ret = strlcpy(devargs->name, name, sizeof(devargs->name));
if (ret < 0 || ret >= (int)sizeof(devargs->name)) {
- free(devargs->args);
+ rte_devargs_reset(devargs);
free(devargs);
return NULL;
}
return 0;
fail:
- free(devargs->args);
+ rte_devargs_reset(devargs);
free(devargs);
free(dev);
return ret;
sdev->cmdline = NULL;
free(sdev->fd_str);
sdev->fd_str = NULL;
- free(sdev->devargs.args);
- sdev->devargs.args = NULL;
+ rte_devargs_reset(&sdev->devargs);
}
}
rte_eth_devices[pid].device->devargs;
/* Take control of probed device. */
- free(da->args);
+ rte_devargs_reset(da);
memset(da, 0, sizeof(*da));
if (probed_da != NULL)
snprintf(devstr, sizeof(devstr), "%s,%s",
if (rte_devargs_parsef(&da, "%s", res->devargs)) {
cmdline_printf(cl, "cannot parse devargs\n");
- if (da.args)
- free(da.args);
return;
}
else
cmdline_printf(cl, "failed to attached device %s\n",
da.name);
+ rte_devargs_reset(&da);
}
cmdline_parse_token_string_t cmd_dev_attach_attach =
if (rte_devargs_parsef(&da, "%s", res->devargs)) {
cmdline_printf(cl, "cannot parse devargs\n");
- if (da.args)
- free(da.args);
return;
}
else
cmdline_printf(cl, "failed to dettach device %s\n",
da.name);
+ rte_devargs_reset(&da);
}
cmdline_parse_token_string_t cmd_dev_detach_detach =
return ret;
err_devarg:
- if (rte_devargs_remove(da) != 0) {
- free(da->args);
- free(da);
- }
+ if (rte_devargs_remove(da) != 0)
+ rte_devargs_reset(da);
return ret;
}
it->bus_str = NULL;
it->cls_str = NULL;
- devargs.data = dev_str;
+ /* Setting data field implies no malloc in parsing. */
+ devargs.data = (void *)(intptr_t)dev_str;
if (rte_devargs_layers_parse(&devargs, dev_str))
goto get_out;
* their parsing afterward.
*/
if (devargs->data != devstr) {
- char *s = (void *)(intptr_t)(devargs->data);
+ char *s = devargs->data;
while ((s = strchr(s, '/'))) {
*s = '\0';
da->bus = bus;
/* Parse eventual device arguments */
if (devname[i] == ',')
- da->args = strdup(&devname[i + 1]);
+ da->data = strdup(&devname[i + 1]);
else
- da->args = strdup("");
- if (da->args == NULL) {
+ da->data = strdup("");
+ if (da->data == NULL) {
RTE_LOG(ERR, EAL, "not enough memory to parse arguments\n");
return -ENOMEM;
}
+ da->drv_str = da->data;
return 0;
}
return ret;
}
+void
+rte_devargs_reset(struct rte_devargs *da)
+{
+ if (da == NULL)
+ return;
+ if (da->data)
+ free(da->data);
+ da->data = NULL;
+}
+
int
rte_devargs_insert(struct rte_devargs **da)
{
if (strcmp(listed_da->bus->name, (*da)->bus->name) == 0 &&
strcmp(listed_da->name, (*da)->name) == 0) {
/* device already in devargs list, must be updated */
- listed_da->type = (*da)->type;
- listed_da->policy = (*da)->policy;
- free(listed_da->args);
- listed_da->args = (*da)->args;
- listed_da->bus = (*da)->bus;
- listed_da->cls = (*da)->cls;
- listed_da->bus_str = (*da)->bus_str;
- listed_da->cls_str = (*da)->cls_str;
- listed_da->data = (*da)->data;
+ rte_devargs_reset(listed_da);
+ *listed_da = **da;
/* replace provided devargs with found one */
free(*da);
*da = listed_da;
fail:
if (devargs) {
- free(devargs->args);
+ rte_devargs_reset(devargs);
free(devargs);
}
if (strcmp(d->bus->name, devargs->bus->name) == 0 &&
strcmp(d->name, devargs->name) == 0) {
TAILQ_REMOVE(&devargs_list, d, next);
- free(d->args);
+ rte_devargs_reset(d);
free(d);
return 0;
}
tmp_req = *req;
+ memset(&da, 0, sizeof(da));
if (req->t == EAL_DEV_REQ_TYPE_ATTACH) {
ret = local_dev_probe(req->devargs, &dev);
if (ret != 0) {
ret = rte_devargs_parse(&da, req->devargs);
if (ret != 0)
goto finish;
- free(da.args); /* we don't need those */
- da.args = NULL;
ret = eal_dev_hotplug_request_to_secondary(&tmp_req);
if (ret != 0) {
if (ret)
RTE_LOG(ERR, EAL, "failed to send response to secondary\n");
+ rte_devargs_reset(&da);
free(bundle->peer);
free(bundle);
}
ret = local_dev_remove(dev);
quit:
- free(da->args);
+ rte_devargs_reset(da);
free(da);
break;
default:
char name[RTE_DEV_NAME_MAX_LEN];
RTE_STD_C11
union {
- /** Arguments string as given by user or "" for no argument. */
- char *args;
- const char *drv_str;
+ const char *args; /**< legacy name. */
+ const char *drv_str; /**< driver-related part of device string. */
};
struct rte_bus *bus; /**< bus handle. */
struct rte_class *cls; /**< class handle. */
const char *bus_str; /**< bus-related part of device string. */
const char *cls_str; /**< class-related part of device string. */
- const char *data; /**< Device string storage. */
+ char *data; /**< raw string including bus, class and driver parts. */
};
/**
const char *format, ...)
__rte_format_printf(2, 0);
+/**
+ * Free resources in devargs.
+ *
+ * @param da
+ * The devargs structure holding the device information.
+ */
+__rte_experimental
+void
+rte_devargs_reset(struct rte_devargs *da);
+
/**
* Insert an rte_devargs in the global list.
*
rte_power_pause; # WINDOWS_NO_EXPORT
# added in 21.05
+ rte_devargs_reset;
rte_intr_callback_unregister_sync;
rte_log_list_types;
rte_thread_key_create;
rte_eth_iterator_init(struct rte_dev_iterator *iter, const char *devargs_str)
{
int ret;
- struct rte_devargs devargs = {.args = NULL};
+ struct rte_devargs devargs;
const char *bus_param_key;
char *bus_str = NULL;
char *cls_str = NULL;
int str_size;
memset(iter, 0, sizeof(*iter));
+ memset(&devargs, 0, sizeof(devargs));
/*
* The devargs string may use various syntaxes:
goto error;
}
iter->cls_str = cls_str;
- free(devargs.args); /* allocated by rte_devargs_parse() */
- devargs.args = NULL;
iter->bus = devargs.bus;
if (iter->bus->dev_iterate == NULL) {
end:
iter->cls = rte_class_find_by_name("eth");
+ rte_devargs_reset(&devargs);
return 0;
error:
if (ret == -ENOTSUP)
RTE_ETHDEV_LOG(ERR, "Bus %s does not support iterating.\n",
iter->bus->name);
- free(devargs.args);
+ rte_devargs_reset(&devargs);
free(bus_str);
free(cls_str);
return ret;