Commit 0c60458b authored by Jiri Pirko's avatar Jiri Pirko Committed by Michael S. Tsirkin

virtio_blk: convert to use virtio_find_vqs_info()

Instead of passing separate names and callbacks arrays
to virtio_find_vqs(), allocate one of virtual_queue_info structs and
pass it to virtio_find_vqs_info().
Suggested-by: default avatarXuan Zhuo <xuanzhuo@linux.alibaba.com>
Signed-off-by: default avatarJiri Pirko <jiri@nvidia.com>
Message-Id: <20240708074814.1739223-11-jiri@resnulli.us>
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
parent b49503ea
...@@ -964,8 +964,7 @@ static int init_vq(struct virtio_blk *vblk) ...@@ -964,8 +964,7 @@ static int init_vq(struct virtio_blk *vblk)
{ {
int err; int err;
unsigned short i; unsigned short i;
vq_callback_t **callbacks; struct virtqueue_info *vqs_info;
const char **names;
struct virtqueue **vqs; struct virtqueue **vqs;
unsigned short num_vqs; unsigned short num_vqs;
unsigned short num_poll_vqs; unsigned short num_poll_vqs;
...@@ -1002,28 +1001,26 @@ static int init_vq(struct virtio_blk *vblk) ...@@ -1002,28 +1001,26 @@ static int init_vq(struct virtio_blk *vblk)
if (!vblk->vqs) if (!vblk->vqs)
return -ENOMEM; return -ENOMEM;
names = kmalloc_array(num_vqs, sizeof(*names), GFP_KERNEL); vqs_info = kcalloc(num_vqs, sizeof(*vqs_info), GFP_KERNEL);
callbacks = kmalloc_array(num_vqs, sizeof(*callbacks), GFP_KERNEL);
vqs = kmalloc_array(num_vqs, sizeof(*vqs), GFP_KERNEL); vqs = kmalloc_array(num_vqs, sizeof(*vqs), GFP_KERNEL);
if (!names || !callbacks || !vqs) { if (!vqs_info || !vqs) {
err = -ENOMEM; err = -ENOMEM;
goto out; goto out;
} }
for (i = 0; i < num_vqs - num_poll_vqs; i++) { for (i = 0; i < num_vqs - num_poll_vqs; i++) {
callbacks[i] = virtblk_done; vqs_info[i].callback = virtblk_done;
snprintf(vblk->vqs[i].name, VQ_NAME_LEN, "req.%u", i); snprintf(vblk->vqs[i].name, VQ_NAME_LEN, "req.%u", i);
names[i] = vblk->vqs[i].name; vqs_info[i].name = vblk->vqs[i].name;
} }
for (; i < num_vqs; i++) { for (; i < num_vqs; i++) {
callbacks[i] = NULL;
snprintf(vblk->vqs[i].name, VQ_NAME_LEN, "req_poll.%u", i); snprintf(vblk->vqs[i].name, VQ_NAME_LEN, "req_poll.%u", i);
names[i] = vblk->vqs[i].name; vqs_info[i].name = vblk->vqs[i].name;
} }
/* Discover virtqueues and write information to configuration. */ /* Discover virtqueues and write information to configuration. */
err = virtio_find_vqs(vdev, num_vqs, vqs, callbacks, names, &desc); err = virtio_find_vqs_info(vdev, num_vqs, vqs, vqs_info, &desc);
if (err) if (err)
goto out; goto out;
...@@ -1035,8 +1032,7 @@ static int init_vq(struct virtio_blk *vblk) ...@@ -1035,8 +1032,7 @@ static int init_vq(struct virtio_blk *vblk)
out: out:
kfree(vqs); kfree(vqs);
kfree(callbacks); kfree(vqs_info);
kfree(names);
if (err) if (err)
kfree(vblk->vqs); kfree(vblk->vqs);
return err; return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment