[dpdk-dev] [PATCH 39/40] net/virtio: move Vhost-kernel data to its backend
Xia, Chenbo
chenbo.xia at intel.com
Thu Jan 7 07:42:37 CET 2021
Hi Maxime,
> -----Original Message-----
> From: Maxime Coquelin <maxime.coquelin at redhat.com>
> Sent: Monday, December 21, 2020 5:14 AM
> To: dev at dpdk.org; Xia, Chenbo <chenbo.xia at intel.com>; olivier.matz at 6wind.com;
> amorenoz at redhat.com; david.marchand at redhat.com
> Cc: Maxime Coquelin <maxime.coquelin at redhat.com>
> Subject: [PATCH 39/40] net/virtio: move Vhost-kernel data to its backend
>
> As done earlier for Vhost-user, this patch moves the
> Vhost-Kernel specific data to its backend file.
>
> Signed-off-by: Maxime Coquelin <maxime.coquelin at redhat.com>
> ---
> drivers/net/virtio/virtio_user/vhost_kernel.c | 78 +++++++++++++++----
> .../net/virtio/virtio_user/virtio_user_dev.c | 43 ++--------
> .../net/virtio/virtio_user/virtio_user_dev.h | 7 +-
> 3 files changed, 72 insertions(+), 56 deletions(-)
>
<snip>
> @@ -339,19 +353,37 @@ static int
> vhost_kernel_setup(struct virtio_user_dev *dev)
> {
> int vhostfd;
> - uint32_t i;
> + uint32_t q, i;
> + struct vhost_kernel_data *data;
> +
> + data = malloc(sizeof(*data));
> + if (!data) {
> + PMD_INIT_LOG(ERR, "(%s) Failed to allocate Vhost-kernel data",
> dev->path);
> + return -1;
> + }
> +
> + data->vhostfds = malloc(dev->max_queue_pairs * sizeof(int));
> + data->tapfds = malloc(dev->max_queue_pairs * sizeof(int));
> + if (!data->vhostfds || !data->tapfds) {
> + PMD_INIT_LOG(ERR, "(%s) Failed to allocate FDs", dev->path);
> + return -1;
> + }
> +
> + for (q = 0; q < dev->max_queue_pairs; ++q) {
> + data->vhostfds[q] = -1;
> + data->tapfds[q] = -1;
> + }
>
> get_vhost_kernel_max_regions();
>
> for (i = 0; i < dev->max_queue_pairs; ++i) {
> vhostfd = open(dev->path, O_RDWR);
> if (vhostfd < 0) {
> - PMD_DRV_LOG(ERR, "fail to open %s, %s",
> - dev->path, strerror(errno));
> + PMD_DRV_LOG(ERR, "fail to open %s, %s", dev->path,
> strerror(errno));
> return -1;
> }
In this function, should we clean-up malloced resources when error happens?
Thanks,
Chenbo
More information about the dev
mailing list