From patchwork Thu May 18 08:10:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Selvin Xavier X-Patchwork-Id: 13246289 X-Patchwork-Delegate: jgg@ziepe.ca Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7DB33C7EE22 for ; Thu, 18 May 2023 08:23:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229586AbjERIXt (ORCPT ); Thu, 18 May 2023 04:23:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230031AbjERIXq (ORCPT ); Thu, 18 May 2023 04:23:46 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87BE21721 for ; Thu, 18 May 2023 01:23:24 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-643846c006fso1739477b3a.0 for ; Thu, 18 May 2023 01:23:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1684398183; x=1686990183; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=hQO3YqDiaYc/NCO7Loq4Lrw91GQemKMuZ2x3OieiTgg=; b=XpQ2SvV7HZVVsipmCTiErpOXvbHN1Ru8lePIPaiIspwbIOUL+XAtsKMPb3TpLsEmV5 Cm5237KnZt4yDPbVGQZf37gDjyHYOGvThhW7WeTgJsWRr0fHojS/svaqlB/XiTX6EO7G Y3SoPnlg7jvhuGGQuOGLBETftGO21Jt5erEeU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684398183; x=1686990183; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hQO3YqDiaYc/NCO7Loq4Lrw91GQemKMuZ2x3OieiTgg=; b=N84EeX3CF2dvQChJsl+3hZsBe6YV5dYQ4asIrmrb2G5cfD4RzGP0hFfjuQKpxEaXVA EOz81SSIkl7/zrTnVFgaea5Zt+p20f/mUqZow6MHRjv8rb0RUwAqZV0A6dvgOzLqofxy L5Hd45B6McVxq0cDDiVuW/Fe4vGs69Q76kWx8J4fyUtHY6lmVFS0Y3b3gvHfS5LjyvnG AHZ1cNTWh8/VCx/ZD8fzVE1AYtZGrKXi4Q7EGMuMgN3/BzZSDR35smxKUcP4cVYzaz2e atmuOBsiF1tN162260sdzDH/9SR6Ap/XjKbAd3BP4UDh+EFSfPoNqXv2AKMzPcPxKK/N UyoQ== X-Gm-Message-State: AC+VfDwVF9OxXj69+WV+MyZ5/5um95KiBYsSLjRbHYFH6Moa2eScLK36 oqLBxOAphrGs0m4NvqyORoSgOQ== X-Google-Smtp-Source: ACHHUZ7wbXvhqtYw1jzHl+UCyjz1OQmVzLLh8OgQV6kvNBJD+UavYOAF7T9SNkO8anJf23EOZr0YzA== X-Received: by 2002:a05:6a00:238e:b0:647:3de:c0ff with SMTP id f14-20020a056a00238e00b0064703dec0ffmr2934596pfc.30.1684398182415; Thu, 18 May 2023 01:23:02 -0700 (PDT) Received: from dhcp-10-192-206-197.iig.avagotech.net.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id b24-20020aa78718000000b0062dd9a8c1b8sm806922pfo.100.2023.05.18.01.22.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 May 2023 01:23:01 -0700 (PDT) From: Selvin Xavier To: jgg@ziepe.ca, leon@kernel.org Cc: linux-rdma@vger.kernel.org, andrew.gospodarek@broadcom.com, Kalesh AP , Selvin Xavier Subject: [PATCH v2 for-rc 1/3] RDMA/bnxt_re: Fix a possible memory leak Date: Thu, 18 May 2023 01:10:59 -0700 Message-Id: <1684397461-23082-2-git-send-email-selvin.xavier@broadcom.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1684397461-23082-1-git-send-email-selvin.xavier@broadcom.com> References: <1684397461-23082-1-git-send-email-selvin.xavier@broadcom.com> Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Kalesh AP Inside bnxt_qplib_create_cq(), when the check for NULL DPI fails, driver returns directly without freeing the memory allocated inside bnxt_qplib_alloc_init_hwq() routine. Fixed this by moving the check for NULL DPI before invoking bnxt_qplib_alloc_init_hwq(). Fixes: 1ac5a4047975 ("RDMA/bnxt_re: Add bnxt_re RoCE driver") Reviewed-by: Kashyap Desai Signed-off-by: Kalesh AP Signed-off-by: Selvin Xavier --- drivers/infiniband/hw/bnxt_re/qplib_fp.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/infiniband/hw/bnxt_re/qplib_fp.c b/drivers/infiniband/hw/bnxt_re/qplib_fp.c index f139d4c..8974f62 100644 --- a/drivers/infiniband/hw/bnxt_re/qplib_fp.c +++ b/drivers/infiniband/hw/bnxt_re/qplib_fp.c @@ -2056,6 +2056,12 @@ int bnxt_qplib_create_cq(struct bnxt_qplib_res *res, struct bnxt_qplib_cq *cq) u32 pg_sz_lvl; int rc; + if (!cq->dpi) { + dev_err(&rcfw->pdev->dev, + "FP: CREATE_CQ failed due to NULL DPI\n"); + return -EINVAL; + } + hwq_attr.res = res; hwq_attr.depth = cq->max_wqe; hwq_attr.stride = sizeof(struct cq_base); @@ -2069,11 +2075,6 @@ int bnxt_qplib_create_cq(struct bnxt_qplib_res *res, struct bnxt_qplib_cq *cq) CMDQ_BASE_OPCODE_CREATE_CQ, sizeof(req)); - if (!cq->dpi) { - dev_err(&rcfw->pdev->dev, - "FP: CREATE_CQ failed due to NULL DPI\n"); - return -EINVAL; - } req.dpi = cpu_to_le32(cq->dpi->dpi); req.cq_handle = cpu_to_le64(cq->cq_handle); req.cq_size = cpu_to_le32(cq->hwq.max_elements);