This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 6b1be7c66c virtio-rng: Register /dev/urandom driver if
CONFIG_DEV_URANDOM=y
6b1be7c66c is described below
commit 6b1be7c66c68493779cecedab29cc6a0939d2269
Author: Tiago Medicci Serrano <[email protected]>
AuthorDate: Thu Jan 2 10:33:43 2025 -0300
virtio-rng: Register /dev/urandom driver if CONFIG_DEV_URANDOM=y
Virtio RNG support (CONFIG_DRIVERS_VIRTIO_RNG=y) selects
CONFIG_ARCH_HAVE_RNG. On the other hand, if CONFIG_DEV_URANDOM=y,
it defaults to CONFIG_DEV_URANDOM_ARCH if CONFIG_ARCH_HAVE_RNG=y.
DEV_URANDOM_ARCH definition states that the implementation of the
/dev/urandom should be provided by the architecture-specifig logic,
including the function devurandom_register(). In this case, the
/dev/urandom may refer to the same driver as /dev/random that is
provided by the Virtio RNG driver, which is implemented by this
commit.
---
drivers/virtio/virtio-rng.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/drivers/virtio/virtio-rng.c b/drivers/virtio/virtio-rng.c
index 9d81dccc3b..276975676a 100644
--- a/drivers/virtio/virtio-rng.c
+++ b/drivers/virtio/virtio-rng.c
@@ -53,6 +53,9 @@ struct virtio_rng_priv_s
{
FAR struct virtio_device *vdev;
char name[NAME_MAX];
+#ifdef CONFIG_DEV_URANDOM
+ char uname[NAME_MAX];
+#endif
spinlock_t lock;
};
@@ -234,10 +237,16 @@ static int virtio_rng_probe(FAR struct virtio_device
*vdev)
if (g_virtio_rng_idx == 0)
{
strlcpy(priv->name, "/dev/random", NAME_MAX);
+#ifdef CONFIG_DEV_URANDOM
+ strlcpy(priv->uname, "/dev/urandom", NAME_MAX);
+#endif
}
else
{
snprintf(priv->name, NAME_MAX, "/dev/random%d", g_virtio_rng_idx);
+#ifdef CONFIG_DEV_URANDOM
+ snprintf(priv->uname, NAME_MAX, "/dev/urandom%d", g_virtio_rng_idx);
+#endif
}
ret = register_driver(priv->name, &g_virtio_rng_ops, 0444, priv);
@@ -247,6 +256,15 @@ static int virtio_rng_probe(FAR struct virtio_device *vdev)
goto err_with_virtqueue;
}
+#ifdef CONFIG_DEV_URANDOM
+ ret = register_driver(priv->uname, &g_virtio_rng_ops, 0444, priv);
+ if (ret < 0)
+ {
+ vrterr("Register NuttX driver failed, ret=%d\n", ret);
+ goto err_with_virtqueue;
+ }
+#endif
+
g_virtio_rng_idx++;
return ret;
@@ -293,6 +311,23 @@ void weak_function devrandom_register(void)
}
#endif
+/****************************************************************************
+ * Name: devurandom_register
+ *
+ * Description:
+ * Initialize the RNG hardware and register the /dev/urandom driver.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_DEV_URANDOM
+void weak_function devurandom_register(void)
+{
+ /* Nothing, implement it here just avoid the compile error, the driver
+ * /dev/urandom will be registered in the virtio rng driver.
+ */
+}
+#endif
+
/****************************************************************************
* Name: virtio_register_rng_driver
****************************************************************************/