From patchwork Tue Jul 10 08:56:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kamal Heib X-Patchwork-Id: 10516605 X-Patchwork-Delegate: jgg@ziepe.ca Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8EFE16020F for ; Tue, 10 Jul 2018 08:57:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7BD0828C7A for ; Tue, 10 Jul 2018 08:57:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6F2ED28C7E; Tue, 10 Jul 2018 08:57:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F16B528C7A for ; Tue, 10 Jul 2018 08:57:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751194AbeGJI5U (ORCPT ); Tue, 10 Jul 2018 04:57:20 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:46864 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751182AbeGJI5T (ORCPT ); Tue, 10 Jul 2018 04:57:19 -0400 Received: by mail-wr1-f65.google.com with SMTP id s11-v6so13707172wra.13 for ; Tue, 10 Jul 2018 01:57:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=2EWocGNh5xXyCl5SK06+e7AYLVkez1FkM/2rK3pCUC8=; b=mJpQ+AbgmWCM0O1inblDoniQ0JYvVVU8tPZ7Rr7dQ2zkbPtAs06Gm3vLrpxDXbkCRT R6Dzu0HjZupO1NyEh9j80IRDx24W+/sdbbqNPlMzr6x1FtTupmwOQm/KpNlJh65oZWx5 GyvY7f9V5n9ulzuxU4Y7tLQQtdPJhT1bkfsgpY3zryNBZCbvENGeJYWLqP3pH0A6SwEh RGJzDo92D66kXb1NRsmVh8Da8ZAvehN5lcQq26LLY5V7wl8MZMDoAjm6CxjkeEoIpJxW tvhOgjzJb2O8i/ADiS1xCfYaek2sy53yFFMfck8KH2nknunwc43yN32MKGrCyYALIXXk 0KJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=2EWocGNh5xXyCl5SK06+e7AYLVkez1FkM/2rK3pCUC8=; b=F8NeQQkbLLxt1CKKoX4b2PD/gDbAJLl17gw2D/zB7Uw1bRBCGUyWi/Y7tHX3wOWii7 t+PN4V4RyB4sz0Bg8el5HyibkmdDrXPwCuWqnHPT1yrsse7IBp7onO2ntF5cfvq+Z8o+ MfRT7wfkNEfYLuLUZBtow4vBDUYJq2ntkwfs3UdStqISKKlePKgCRwSFpRIqcbOX2VNW zbG5o3vgDVWhZSdi9T1iLFyDlKl1O4rO1svktnXKdm0jQ9COQgyGWSWGkTz5RSB2ZM8v zhDWyWa0o9/MJGeHhVfRjikkc0saeyOyV97fRa2EP2a7dxkdNVhQKhjaNNkb5CC/11+a otTw== X-Gm-Message-State: APt69E0Kv2cr7sPi8AQL/ZAyUe+WqW5Gif3kOnf6iRDDudq39xVRbw8D AUwECsBAV5ubKF9KwHnPrN4= X-Google-Smtp-Source: AAOMgpc9MukfPOTRCNaWjMDGhalVHPI8IQat09tv1FXjPC22MUcMNzsjWtzCRdihGJbnFJo7l1fR4w== X-Received: by 2002:adf:a6e2:: with SMTP id t89-v6mr18514080wrc.231.1531213038364; Tue, 10 Jul 2018 01:57:18 -0700 (PDT) Received: from localhost.localdomain ([192.116.94.214]) by smtp.gmail.com with ESMTPSA id q18-v6sm6696540wrj.70.2018.07.10.01.57.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Jul 2018 01:57:17 -0700 (PDT) From: Kamal Heib To: Doug Ledford , Jason Gunthorpe , Leon Romanovsky Cc: linux-rdma@vger.kernel.org, Kamal Heib Subject: [PATCH rdma-rc] RDMA/mlx5: Fix memory leak in mlx5_ib_create_srq() error path Date: Tue, 10 Jul 2018 11:56:50 +0300 Message-Id: <20180710085650.24720-1-kamalheib1@gmail.com> X-Mailer: git-send-email 2.14.4 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Fix memory leak in the error path of mlx5_ib_create_srq() by make sure to free the allocated srq. Fixes: c2b37f76485f ('IB/mlx5: Fix integer overflows in mlx5_ib_create_srq') Signed-off-by: Kamal Heib Acked-by: Leon Romanovsky --- drivers/infiniband/hw/mlx5/srq.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/infiniband/hw/mlx5/srq.c b/drivers/infiniband/hw/mlx5/srq.c index 0af7b7905550..f5de5adc9b1a 100644 --- a/drivers/infiniband/hw/mlx5/srq.c +++ b/drivers/infiniband/hw/mlx5/srq.c @@ -266,18 +266,24 @@ struct ib_srq *mlx5_ib_create_srq(struct ib_pd *pd, desc_size = sizeof(struct mlx5_wqe_srq_next_seg) + srq->msrq.max_gs * sizeof(struct mlx5_wqe_data_seg); - if (desc_size == 0 || srq->msrq.max_gs > desc_size) - return ERR_PTR(-EINVAL); + if (desc_size == 0 || srq->msrq.max_gs > desc_size) { + err = -EINVAL; + goto err_srq; + } desc_size = roundup_pow_of_two(desc_size); desc_size = max_t(size_t, 32, desc_size); - if (desc_size < sizeof(struct mlx5_wqe_srq_next_seg)) - return ERR_PTR(-EINVAL); + if (desc_size < sizeof(struct mlx5_wqe_srq_next_seg)) { + err = -EINVAL; + goto err_srq; + } srq->msrq.max_avail_gather = (desc_size - sizeof(struct mlx5_wqe_srq_next_seg)) / sizeof(struct mlx5_wqe_data_seg); srq->msrq.wqe_shift = ilog2(desc_size); buf_size = srq->msrq.max * desc_size; - if (buf_size < desc_size) - return ERR_PTR(-EINVAL); + if (buf_size < desc_size) { + err = -EINVAL; + goto err_srq; + } in.type = init_attr->srq_type; if (pd->uobject)