Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

IB/mthca: Fix memory leak on modify_qp error paths

Some error paths after the mthca_alloc_mailbox() call in mthca_modify_qp()
just do a "return -EINVAL" without freeing the mailbox. Convert these
returns to "goto out" to avoid leaking the mailbox storage.

Signed-off-by: Roland Dreier <rolandd@cisco.com>

+6 -6
+6 -6
drivers/infiniband/hw/mthca/mthca_qp.c
··· 534 534 struct mthca_qp_context *qp_context; 535 535 u32 sqd_event = 0; 536 536 u8 status; 537 - int err; 537 + int err = -EINVAL; 538 538 539 539 if (attr_mask & IB_QP_CUR_STATE) { 540 540 cur_state = attr->cur_qp_state; ··· 618 618 if (attr->path_mtu < IB_MTU_256 || attr->path_mtu > IB_MTU_2048) { 619 619 mthca_dbg(dev, "path MTU (%u) is invalid\n", 620 620 attr->path_mtu); 621 - return -EINVAL; 621 + goto out; 622 622 } 623 623 qp_context->mtu_msgmax = (attr->path_mtu << 5) | 31; 624 624 } ··· 672 672 if (attr_mask & IB_QP_AV) { 673 673 if (mthca_path_set(dev, &attr->ah_attr, &qp_context->pri_path, 674 674 attr_mask & IB_QP_PORT ? attr->port_num : qp->port)) 675 - return -EINVAL; 675 + goto out; 676 676 677 677 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_PRIMARY_ADDR_PATH); 678 678 } ··· 686 686 if (attr->alt_pkey_index >= dev->limits.pkey_table_len) { 687 687 mthca_dbg(dev, "Alternate P_Key index (%u) too large. max is %d\n", 688 688 attr->alt_pkey_index, dev->limits.pkey_table_len-1); 689 - return -EINVAL; 689 + goto out; 690 690 } 691 691 692 692 if (attr->alt_port_num == 0 || attr->alt_port_num > dev->limits.num_ports) { 693 693 mthca_dbg(dev, "Alternate port number (%u) is invalid\n", 694 694 attr->alt_port_num); 695 - return -EINVAL; 695 + goto out; 696 696 } 697 697 698 698 if (mthca_path_set(dev, &attr->alt_ah_attr, &qp_context->alt_path, 699 699 attr->alt_ah_attr.port_num)) 700 - return -EINVAL; 700 + goto out; 701 701 702 702 qp_context->alt_path.port_pkey |= cpu_to_be32(attr->alt_pkey_index | 703 703 attr->alt_port_num << 24);