Commit 299eafee authored by Gustavo A. R. Silva's avatar Gustavo A. R. Silva Committed by Jason Gunthorpe

IB/mlx5: Fix memory leak in mlx5_ib_create_flow

In case memory resources for *ucmd* were allocated, release them
before return.

Addresses-Coverity-ID: 1469857 ("Resource leak")
Fixes: 3b3233fb ("IB/mlx5: Add flow counters binding support")
Signed-off-by: default avatarGustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent 828d8105
...@@ -3546,29 +3546,35 @@ static struct ib_flow *mlx5_ib_create_flow(struct ib_qp *qp, ...@@ -3546,29 +3546,35 @@ static struct ib_flow *mlx5_ib_create_flow(struct ib_qp *qp,
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
err = ib_copy_from_udata(ucmd, udata, required_ucmd_sz); err = ib_copy_from_udata(ucmd, udata, required_ucmd_sz);
if (err) { if (err)
kfree(ucmd); goto free_ucmd;
return ERR_PTR(err);
}
} }
if (flow_attr->priority > MLX5_IB_FLOW_LAST_PRIO) if (flow_attr->priority > MLX5_IB_FLOW_LAST_PRIO) {
return ERR_PTR(-ENOMEM); err = -ENOMEM;
goto free_ucmd;
}
if (domain != IB_FLOW_DOMAIN_USER || if (domain != IB_FLOW_DOMAIN_USER ||
flow_attr->port > dev->num_ports || flow_attr->port > dev->num_ports ||
(flow_attr->flags & ~(IB_FLOW_ATTR_FLAGS_DONT_TRAP | (flow_attr->flags & ~(IB_FLOW_ATTR_FLAGS_DONT_TRAP |
IB_FLOW_ATTR_FLAGS_EGRESS))) IB_FLOW_ATTR_FLAGS_EGRESS))) {
return ERR_PTR(-EINVAL); err = -EINVAL;
goto free_ucmd;
}
if (is_egress && if (is_egress &&
(flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT ||
flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT)) flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT)) {
return ERR_PTR(-EINVAL); err = -EINVAL;
goto free_ucmd;
}
dst = kzalloc(sizeof(*dst), GFP_KERNEL); dst = kzalloc(sizeof(*dst), GFP_KERNEL);
if (!dst) if (!dst) {
return ERR_PTR(-ENOMEM); err = -ENOMEM;
goto free_ucmd;
}
mutex_lock(&dev->flow_db->lock); mutex_lock(&dev->flow_db->lock);
...@@ -3637,8 +3643,8 @@ static struct ib_flow *mlx5_ib_create_flow(struct ib_qp *qp, ...@@ -3637,8 +3643,8 @@ static struct ib_flow *mlx5_ib_create_flow(struct ib_qp *qp,
unlock: unlock:
mutex_unlock(&dev->flow_db->lock); mutex_unlock(&dev->flow_db->lock);
kfree(dst); kfree(dst);
free_ucmd:
kfree(ucmd); kfree(ucmd);
kfree(handler);
return ERR_PTR(err); return ERR_PTR(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