Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1655620rwn; Thu, 15 Sep 2022 21:09:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6WCJIaI7Vu2U2A56IVaZH1Y5P5RXtn4tuvGOSoqLRCcIHhCois3AGgel7XuRtbYbVQ2J4H X-Received: by 2002:a05:6402:1f01:b0:445:fbe8:4b2e with SMTP id b1-20020a0564021f0100b00445fbe84b2emr2369835edb.192.1663301355561; Thu, 15 Sep 2022 21:09:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663301355; cv=none; d=google.com; s=arc-20160816; b=DHRkYZm/qPu/uBGjR3g8xrGxFHbhkVSn3PRJF2goXruS6PljMjYZxlOu4/X+2qxzQO sQo79uPVr/xLxvGuY/6L0ICpR3RUM98qoQyXsgbvFODXgufPnaxwZvl/+WE7Vi6Ww3xU iA78DOdTYh37hLf7/nD8p66eoFhut4WE59M2mChb5+q8l1kOv0Y2O8/j4atCGjYvPZio Ch9ezfBlpJYb3s1QuLtPj4X53K4R2WdP7RgwmC1BNvDluWV6MdWh+Nju90k3P3FbYnmU rZI4FmOapcQ/LHIqLYDcNyGHJscQ/fyqBeqjyU33CqH9oB23I7bBv/UPp6EgmGL9GLYC a1KQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=1Q4Q9Drjvqq1OzQpeLiPQrhsLdnCghR5eiThiTgj0LA=; b=V4oJtrH5Zg6cm1cTFGQKLoG+YCGPJoCHRR1/sIjOpwWx3EI3kyDkhGAuWhPglLABpg l1L9TZawEjkYYo2LpizSu279mZqCx0iEQyc5H55xNVa7tzHu7UJcF3z5tpkiBjQ01z/5 JAcXoRlUUfwXWGRv+eWtRQvvrW6NNdPpnJxgNMDm6vYVlks6NdFJplKIK6zsMgnjNDJ/ fCYtmodO1s4VVcZ/L5aijjAilkJQ/GFLMZeE4gtYyLTjnQNH5a1296XFYoClZmxmdCsJ so25u+f3JPJ+8x7Bf82mMcUAB9uATmXRMV7zzuk7IobWVV0tdIRDpxL1OWhuGNXZhGQp Wx2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=OFqboWUm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q11-20020a056402518b00b0044e6cd50e66si1366894edd.282.2022.09.15.21.08.50; Thu, 15 Sep 2022 21:09:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=OFqboWUm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229942AbiIPD7h (ORCPT + 99 others); Thu, 15 Sep 2022 23:59:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229612AbiIPD7f (ORCPT ); Thu, 15 Sep 2022 23:59:35 -0400 Received: from mail-oa1-x31.google.com (mail-oa1-x31.google.com [IPv6:2001:4860:4864:20::31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 442DBC78; Thu, 15 Sep 2022 20:59:28 -0700 (PDT) Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-1280590722dso50464817fac.1; Thu, 15 Sep 2022 20:59:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=1Q4Q9Drjvqq1OzQpeLiPQrhsLdnCghR5eiThiTgj0LA=; b=OFqboWUmjs/WYzHvErueQTrw09F5eFZuMDajiKvEPpDG8FZ35D/lr5vkWi/vYVRsKM 9GK3qIPVvi/B/kkUS+StxyQoxTASuOVhbs5ZsY1qN95e6xaqJOQA9wmZQCx79PMdsh7P kSu1ior1aFxXjTZ6QQOuuK5VWmmt+l+s5M6oh20B26X/Iyo+hqiXY9HMSU2YOVXooHVw gL3r5EAUMxdLCp3DM0Mt8cai0AP9iLixRUb8x25GsTt5oIo/CbXwWbokBh6+s2RpnYVD wIs1WeMCAOTIH1ceVgGOmON/Z8iPjuIgUBm8RcbJXQiMnkbd41NASg/lIitHAnYAHL0x BaKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=1Q4Q9Drjvqq1OzQpeLiPQrhsLdnCghR5eiThiTgj0LA=; b=weSClYkUfSUGlpR4lLxMI5rrH0PWJI27FVACxluArgw6i6iS+DGRaSyQsQYwSGnvuk QjmySDivrpg36MunyZ2f2bRNxZxAA/N79FYlnoZk++Ig6sBAywo8y2oGrl1twLwiP44S EnV45cJyctDEOsSEV43UHZHvuniCVjwXtQ8pSb+VQgafcUYbrdkOKs0Kd5ylXQA3hs28 vqXvIzvFXB8Fupf9t9EOHcbfEnJLOT3lOKpiVv7Hlde4y8irPvRU1OV9MS2TtJTeiVCg rqyfIYMyT5ZhWiA3uAwEPrV0QLvm14NQz2fSwM9eyXHpWhS9B4gAqQouoPjCOq5pLdgH PQ8g== X-Gm-Message-State: ACgBeo2ArmYCWC4sGsh8zGxTQi1Outd9cbyZJfh1fZ4kTMv0rbqbU1dl 257rAcRJQEp8A3/JBxRW4/0= X-Received: by 2002:a05:6870:3116:b0:11d:342a:4419 with SMTP id v22-20020a056870311600b0011d342a4419mr7100187oaa.251.1663300767511; Thu, 15 Sep 2022 20:59:27 -0700 (PDT) Received: from macondo.. ([2804:431:e7cd:8cb3:f8d3:a3e1:53c:3ab3]) by smtp.gmail.com with ESMTPSA id m189-20020aca58c6000000b003450abf4404sm8566200oib.21.2022.09.15.20.59.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Sep 2022 20:59:27 -0700 (PDT) From: Rafael Mendonca To: James Smart , Dick Kennedy , "James E.J. Bottomley" , "Martin K. Petersen" , Gaurav Srivastava , Hannes Reinecke , Muneendra Kumar Cc: Rafael Mendonca , James Smart , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] scsi: lpfc: Fix memory leak in lpfc_create_port() Date: Fri, 16 Sep 2022 00:59:07 -0300 Message-Id: <20220916035908.712799-1-rafaelmendsr@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit 5e633302ace1 ("scsi: lpfc: vmid: Add support for VMID in mailbox command") introduced allocations for the VMID resources in lpfc_create_port() after the call to scsi_host_alloc(). Upon failure on the VMID allocations, the new code would branch to the 'out' label, which returns NULL without unwinding anything, thus skipping the call to scsi_host_put(). Fix the problem by creating a separate label 'out_free_vmid' to unwind the VMID resources and make the 'out_put_shost' label call only scsi_host_put(), as was done before the introduction of allocations for VMID. Fixes: 5e633302ace1 ("scsi: lpfc: vmid: Add support for VMID in mailbox command") Signed-off-by: Rafael Mendonca --- drivers/scsi/lpfc/lpfc_init.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c index 55a1ad6eed03..6f572f0c5c45 100644 --- a/drivers/scsi/lpfc/lpfc_init.c +++ b/drivers/scsi/lpfc/lpfc_init.c @@ -4819,7 +4819,7 @@ lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) rc = lpfc_vmid_res_alloc(phba, vport); if (rc) - goto out; + goto out_put_shost; /* Initialize all internally managed lists. */ INIT_LIST_HEAD(&vport->fc_nodes); @@ -4837,16 +4837,17 @@ lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev); if (error) - goto out_put_shost; + goto out_free_vmid; spin_lock_irq(&phba->port_list_lock); list_add_tail(&vport->listentry, &phba->port_list); spin_unlock_irq(&phba->port_list_lock); return vport; -out_put_shost: +out_free_vmid: kfree(vport->vmid); bitmap_free(vport->vmid_priority_range); +out_put_shost: scsi_host_put(shost); out: return NULL; -- 2.34.1