usb: device_next: use dlist instead of slist for descriptors list

While this does not provide much of an advantage yet,
it will allow us to add descriptors and assign an index
more easily in the next commit.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
diff --git a/include/zephyr/usb/usbd.h b/include/zephyr/usb/usbd.h
index 410fdf9..0caf774 100644
--- a/include/zephyr/usb/usbd.h
+++ b/include/zephyr/usb/usbd.h
@@ -62,7 +62,7 @@
  */
 struct usbd_desc_node {
 	/** slist node struct */
-	sys_snode_t node;
+	sys_dnode_t node;
 	/** Descriptor index, required for string descriptors */
 	unsigned int idx : 8;
 	/** If not set, string descriptor must be converted to UTF16LE */
@@ -156,7 +156,7 @@
 	/** Middle layer runtime data */
 	struct usbd_ch9_data ch9_data;
 	/** slist to manage descriptors like string, bos */
-	sys_slist_t descriptors;
+	sys_dlist_t descriptors;
 	/** slist to manage device configurations */
 	sys_slist_t configs;
 	/** Status of the USB device support */
diff --git a/subsys/usb/device_next/usbd_desc.c b/subsys/usb/device_next/usbd_desc.c
index bea3b05..2f20614 100644
--- a/subsys/usb/device_next/usbd_desc.c
+++ b/subsys/usb/device_next/usbd_desc.c
@@ -110,7 +110,7 @@
 	struct usbd_desc_node *tmp;
 	struct usb_desc_header *dh;
 
-	SYS_SLIST_FOR_EACH_CONTAINER(&uds_ctx->descriptors, tmp, node) {
+	SYS_DLIST_FOR_EACH_CONTAINER(&uds_ctx->descriptors, tmp, node) {
 		dh = tmp->desc;
 		if (tmp->idx == idx && dh->bDescriptorType == type) {
 			return tmp->desc;
@@ -123,9 +123,9 @@
 int usbd_desc_remove_all(struct usbd_contex *const uds_ctx)
 {
 	struct usbd_desc_node *tmp;
-	sys_snode_t *node;
+	sys_dnode_t *node;
 
-	while ((node = sys_slist_get(&uds_ctx->descriptors))) {
+	while ((node = sys_dlist_get(&uds_ctx->descriptors))) {
 		tmp = CONTAINER_OF(node, struct usbd_desc_node, node);
 		LOG_DBG("Remove descriptor node %p", tmp);
 	}
@@ -142,9 +142,15 @@
 
 	usbd_device_lock(uds_ctx);
 
+	/* Check if descriptor list is initialized */
+	if (!sys_dnode_is_linked(&uds_ctx->descriptors)) {
+		LOG_DBG("Initialize descriptors list");
+		sys_dlist_init(&uds_ctx->descriptors);
+	}
+
 	head = desc_nd->desc;
 	type = head->bDescriptorType;
-	if (usbd_get_descriptor(uds_ctx, type, desc_nd->idx)) {
+	if (sys_dnode_is_linked(&desc_nd->node)) {
 		ret = -EALREADY;
 		goto add_descriptor_error;
 	}
@@ -181,7 +187,7 @@
 		}
 	}
 
-	sys_slist_append(&uds_ctx->descriptors, &desc_nd->node);
+	sys_dlist_append(&uds_ctx->descriptors, &desc_nd->node);
 
 add_descriptor_error:
 	usbd_device_unlock(uds_ctx);