Commit 71ab6a7c authored by Eli Cohen's avatar Eli Cohen Committed by Michael S. Tsirkin

vdpa/mlx5: Fix possible failure in umem size calculation

umem size is a 32 bit unsigned value so assigning it to an int could
cause false failures. Set the calculated value inside the function and
modify function name to reflect the fact it updates the size.

This bug was found during code review but never had real impact to this
date.

Fixes: 1a86b377 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")
Signed-off-by: default avatarEli Cohen <elic@nvidia.com>
Link: https://lore.kernel.org/r/20210530090349.8360-1-elic@nvidia.comSigned-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
Acked-by: default avatarJason Wang <jasowang@redhat.com>
parent e3011776
...@@ -611,7 +611,7 @@ static void cq_destroy(struct mlx5_vdpa_net *ndev, u16 idx) ...@@ -611,7 +611,7 @@ static void cq_destroy(struct mlx5_vdpa_net *ndev, u16 idx)
mlx5_db_free(ndev->mvdev.mdev, &vcq->db); mlx5_db_free(ndev->mvdev.mdev, &vcq->db);
} }
static int umem_size(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq, int num, static void set_umem_size(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq, int num,
struct mlx5_vdpa_umem **umemp) struct mlx5_vdpa_umem **umemp)
{ {
struct mlx5_core_dev *mdev = ndev->mvdev.mdev; struct mlx5_core_dev *mdev = ndev->mvdev.mdev;
...@@ -635,7 +635,7 @@ static int umem_size(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq ...@@ -635,7 +635,7 @@ static int umem_size(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq
*umemp = &mvq->umem3; *umemp = &mvq->umem3;
break; break;
} }
return p_a * mvq->num_ent + p_b; (*umemp)->size = p_a * mvq->num_ent + p_b;
} }
static void umem_frag_buf_free(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_umem *umem) static void umem_frag_buf_free(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_umem *umem)
...@@ -651,15 +651,10 @@ static int create_umem(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *m ...@@ -651,15 +651,10 @@ static int create_umem(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *m
void *in; void *in;
int err; int err;
__be64 *pas; __be64 *pas;
int size;
struct mlx5_vdpa_umem *umem; struct mlx5_vdpa_umem *umem;
size = umem_size(ndev, mvq, num, &umem); set_umem_size(ndev, mvq, num, &umem);
if (size < 0) err = umem_frag_buf_alloc(ndev, umem, umem->size);
return size;
umem->size = size;
err = umem_frag_buf_alloc(ndev, umem, size);
if (err) if (err)
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