virtio: update virtio_alloc_buf() releated APIs usage

new virtio_alloc_buf() return int type, so add virtio_malloc_buf()
for the convenience of use.
And replace all virtio_alloc_buf() to virtio_malloc_buf() in NuttX.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
This commit is contained in:
Bowen Wang
2024-10-29 23:13:03 +08:00
committed by Xiang Xiao
parent 5c77a8c4d5
commit 3b2c04c6a3
2 changed files with 27 additions and 12 deletions
+8 -8
View File
@@ -478,7 +478,7 @@ static int virtio_snd_query_info(FAR struct virtio_snd_s *priv,
req->count = count;
req->size = size;
resp = virtio_alloc_buf(priv->vdev, sizeof(*resp), 16);
resp = virtio_malloc_buf(priv->vdev, sizeof(*resp), 16);
if (resp == NULL)
{
vrterr("virtio audio driver cmd response alloc failed\n");
@@ -562,7 +562,7 @@ static int virtio_snd_set_params(FAR struct virtio_snd_dev_s *sdev,
req->buffer_bytes = req->period_bytes *
CONFIG_DRIVERS_VIRTIO_SND_BUFFER_COUNT;
resp = virtio_alloc_buf(priv->vdev, sizeof(*resp), 16);
resp = virtio_malloc_buf(priv->vdev, sizeof(*resp), 16);
if (resp == NULL)
{
vrterr("zalloc for request error\n");
@@ -609,7 +609,7 @@ static int virtio_snd_send_cmd(FAR struct virtio_snd_dev_s *sdev,
struct virtqueue_buf vb[2];
int ret;
req = virtio_alloc_buf(vdev, sizeof(*req), 16);
req = virtio_malloc_buf(vdev, sizeof(*req), 16);
if (req == NULL)
{
vrterr("zalloc for request error\n");
@@ -619,7 +619,7 @@ static int virtio_snd_send_cmd(FAR struct virtio_snd_dev_s *sdev,
req->hdr.code = cmd;
req->stream_id = sdev->index;
resp = virtio_alloc_buf(vdev, sizeof(*resp), 16);
resp = virtio_malloc_buf(vdev, sizeof(*resp), 16);
if (resp == NULL)
{
vrterr("zalloc for request error\n");
@@ -1112,10 +1112,10 @@ static int virtio_snd_init(FAR struct virtio_snd_s *priv)
vrtinfo("jacks:%"PRIu32" streams:%"PRIu32" chmap:%"PRIu32"\n",
priv->config.jacks, priv->config.streams, priv->config.chmaps);
priv->info = virtio_alloc_buf(priv->vdev,
priv->config.streams *
sizeof(struct virtio_snd_pcm_info),
16);
priv->info = virtio_malloc_buf(priv->vdev,
priv->config.streams *
sizeof(struct virtio_snd_pcm_info),
16);
if (priv->info == NULL)
{
vrterr("virtio audio driver query pcm info alloc failed\n");
+19 -4
View File
@@ -188,17 +188,32 @@ extern "C"
#endif
static inline_function FAR void *
virtio_zalloc_buf(FAR struct virtio_device *vdev, size_t size, size_t align)
virtio_malloc_buf(FAR struct virtio_device *vdev, size_t size, size_t align)
{
FAR void *buf = virtio_alloc_buf(vdev, size, align);
if (buf != NULL)
FAR void *buf;
if (virtio_alloc_buf(vdev, &buf, size, align) < 0)
{
memset(buf, 0, size);
return NULL;
}
return buf;
}
static inline_function FAR void *
virtio_zalloc_buf(FAR struct virtio_device *vdev, size_t size, size_t align)
{
FAR void *buf;
if (virtio_alloc_buf(vdev, &buf, size, align) < 0)
{
return NULL;
}
memset(buf, 0, size);
return buf;
}
/* Driver and device register/unregister function */
int virtio_register_driver(FAR struct virtio_driver *driver);