IB/mlx4: Fix leaks in __mlx4_ib_modify_qp

Temporarily allocated struct mlx4_qp_context *context is leaked by
several error paths. The patch takes advantage of the return value
'err' being preinitialized to -EINVAL.

Spotted by Coverity (CID 1768).

Signed-off-by: Florin Malita <fmalita@gmail.com>
Signed-off-by: Roland Dreier <rolandd@cisco.com>

authored by Florin Malita and committed by Roland Dreier f5b40431 c2e68052

+5 -7
+5 -7
drivers/infiniband/hw/mlx4/qp.c
··· 742 if (attr->path_mtu < IB_MTU_256 || attr->path_mtu > IB_MTU_4096) { 743 printk(KERN_ERR "path MTU (%u) is invalid\n", 744 attr->path_mtu); 745 - return -EINVAL; 746 } 747 context->mtu_msgmax = (attr->path_mtu << 5) | 31; 748 } ··· 781 782 if (attr_mask & IB_QP_AV) { 783 if (mlx4_set_path(dev, &attr->ah_attr, &context->pri_path, 784 - attr_mask & IB_QP_PORT ? attr->port_num : qp->port)) { 785 - err = -EINVAL; 786 goto out; 787 - } 788 789 optpar |= (MLX4_QP_OPTPAR_PRIMARY_ADDR_PATH | 790 MLX4_QP_OPTPAR_SCHED_QUEUE); ··· 796 if (attr_mask & IB_QP_ALT_PATH) { 797 if (attr->alt_port_num == 0 || 798 attr->alt_port_num > dev->dev->caps.num_ports) 799 - return -EINVAL; 800 801 if (attr->alt_pkey_index >= 802 dev->dev->caps.pkey_table_len[attr->alt_port_num]) 803 - return -EINVAL; 804 805 if (mlx4_set_path(dev, &attr->alt_ah_attr, &context->alt_path, 806 attr->alt_port_num)) 807 - return -EINVAL; 808 809 context->alt_path.pkey_index = attr->alt_pkey_index; 810 context->alt_path.ackto = attr->alt_timeout << 3;
··· 742 if (attr->path_mtu < IB_MTU_256 || attr->path_mtu > IB_MTU_4096) { 743 printk(KERN_ERR "path MTU (%u) is invalid\n", 744 attr->path_mtu); 745 + goto out; 746 } 747 context->mtu_msgmax = (attr->path_mtu << 5) | 31; 748 } ··· 781 782 if (attr_mask & IB_QP_AV) { 783 if (mlx4_set_path(dev, &attr->ah_attr, &context->pri_path, 784 + attr_mask & IB_QP_PORT ? attr->port_num : qp->port)) 785 goto out; 786 787 optpar |= (MLX4_QP_OPTPAR_PRIMARY_ADDR_PATH | 788 MLX4_QP_OPTPAR_SCHED_QUEUE); ··· 798 if (attr_mask & IB_QP_ALT_PATH) { 799 if (attr->alt_port_num == 0 || 800 attr->alt_port_num > dev->dev->caps.num_ports) 801 + goto out; 802 803 if (attr->alt_pkey_index >= 804 dev->dev->caps.pkey_table_len[attr->alt_port_num]) 805 + goto out; 806 807 if (mlx4_set_path(dev, &attr->alt_ah_attr, &context->alt_path, 808 attr->alt_port_num)) 809 + goto out; 810 811 context->alt_path.pkey_index = attr->alt_pkey_index; 812 context->alt_path.ackto = attr->alt_timeout << 3;