anchao commented on code in PR #12764:
URL: https://github.com/apache/nuttx/pull/12764#discussion_r1691431053
##########
drivers/virtio/Kconfig:
##########
@@ -74,6 +74,16 @@ if DRIVERS_VIRTIO_SERIAL
config DRIVERS_VIRTIO_SERIAL_BUFSIZE
int "Virtio serial driver buffer size"
default 256
+
+config DRIVERS_VIRTIO_SERIAL_NAME
Review Comment:
```suggestion
config DRIVERS_VIRTIO_SERIAL_NAMES
```
##########
drivers/virtio/virtio-serial.c:
##########
@@ -523,6 +523,52 @@ static void virtio_serial_uninit(FAR struct
virtio_serial_priv_s *priv)
virtio_free_buf(vdev, priv->udev.recv.buffer);
}
+/****************************************************************************
+ * Name: virtio_serial_uart_register
+ ****************************************************************************/
+
+static int virtio_serial_uart_register(FAR struct virtio_serial_priv_s *priv)
+{
+ FAR const char *name = CONFIG_DRIVERS_VIRTIO_SERIAL_NAME;
+ bool found = false;
+ int start = 0;
+ int ret;
+ int i;
+ int j;
+
+ for (i = 0, j = 0; name[start] != '\0'; i++)
+ {
+ if (name[i] == ';' || name[i] == '\0')
+ {
+ if (j++ == g_virtio_serial_idx)
+ {
+ found = true;
+ break;
+ }
+
+ start = i + 1;
+ }
+ }
+
+ if (found)
+ {
+ snprintf(priv->name, NAME_MAX, "/dev/%.*s", i - start, &name[start]);
+ }
+ else
+ {
+ snprintf(priv->name, NAME_MAX, "/dev/ttyV%d", g_virtio_serial_idx);
+ }
+
+ ret = uart_register(priv->name, &priv->udev);
Review Comment:
```suggestion
g_virtio_serial_idx++;
return uart_register(priv->name, &priv->udev);
}
```
increase index before register uart to skip the invalid name
##########
drivers/virtio/virtio-serial.c:
##########
@@ -523,6 +523,52 @@ static void virtio_serial_uninit(FAR struct
virtio_serial_priv_s *priv)
virtio_free_buf(vdev, priv->udev.recv.buffer);
}
+/****************************************************************************
+ * Name: virtio_serial_uart_register
+ ****************************************************************************/
+
+static int virtio_serial_uart_register(FAR struct virtio_serial_priv_s *priv)
+{
+ FAR const char *name = CONFIG_DRIVERS_VIRTIO_SERIAL_NAME;
+ bool found = false;
+ int start = 0;
+ int ret;
+ int i;
+ int j;
+
+ for (i = 0, j = 0; name[start] != '\0'; i++)
+ {
+ if (name[i] == ';' || name[i] == '\0')
+ {
+ if (j++ == g_virtio_serial_idx)
+ {
+ found = true;
+ break;
+ }
+
+ start = i + 1;
+ }
+ }
+
+ if (found)
+ {
+ snprintf(priv->name, NAME_MAX, "/dev/%.*s", i - start, &name[start]);
Review Comment:
```suggestion
snprintf(priv->name, sizeof(priv->name), "/dev/%.*s", i - start,
&name[start]);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]