Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

virtio-rng: Register /dev/urandom driver if CONFIG_DEV_URANDOM=y #15410

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions drivers/virtio/virtio-rng.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down Expand Up @@ -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);
Expand All @@ -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;

Expand Down Expand Up @@ -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
****************************************************************************/
Expand Down
Loading