Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp350370pxb; Wed, 18 Nov 2020 06:15:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJzCSPGH5bAGcqQ5Et3P5N5UM8OgTU3scae+ZX8TinDAPh2e85rSouW9sfCk1KMe9FrwMC3q X-Received: by 2002:aa7:dc58:: with SMTP id g24mr13377228edu.55.1605708953321; Wed, 18 Nov 2020 06:15:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605708953; cv=none; d=google.com; s=arc-20160816; b=ClxbzhrGyEH3Z4+74GGxaULGXlM4Qvv3O5H7xQSBag05OINrv9XD5NwOUwmczQ+LPx PuErzFVBrM8PoFnXBknuT9gaohBFtk16Zng+0OJ+wZgumX8LsAXz2/HfYZj8fnh0uYgD NGvT86tQWt6cwRFSs8skKnQar1g9T/CgcwRXeZ8MkdoO1GpPNBJlHJ5S19RIdsLRiSQV mfLdjXHO0voRyUpyfwjifAoeinxJoCdxcb84lm1ROJamGsXPDoH8J4jtUd70qHZQyBSG AVY0g5RoXsWVJodK8g/1hbckvFKAKFf8wDjYeNoIi8jsp8KyUCYUx5qj6nTw3HHu38LE N2GQ== 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; bh=1R4zy8wrFPwzfnXVsNyfA5ZAb8wOih6alIP06VC1ruE=; b=n1YyDuX3qZkXOxipJ74eukIiDXKQzbSpZXsfGPD1ePgqw8m1u1KS7TNXHx0dRKk8Gb JDpX5F+ocM7TnSyQtq9pWyOiXjfBE8Han8W2gKlFTdHjSRq8reBVtuVGlonMg9BxEapo I5Ezx/bg00Xgqu0tkHY0SllruOedjVQMmp50F/TIYJGbR4u1xQ4p9Rj0Bo1iBAVUidLK /7AQUabjDiCahpCrgdU1GfagSPAffL4/tLk5h5Ku7caDRoowI8copJyd6z2/Ds1Nwrhd T2nvAJLC+aTxQqPQQpiSEAkEBoNUM9aLsDw/IJ1lPjavZDsl/cv3g5nBgtIKc79cL6Et BM0Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r4si3532454edc.537.2020.11.18.06.15.29; Wed, 18 Nov 2020 06:15:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726591AbgKRONU (ORCPT + 99 others); Wed, 18 Nov 2020 09:13:20 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:60063 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726019AbgKRONU (ORCPT ); Wed, 18 Nov 2020 09:13:20 -0500 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kfOCx-0005v8-3O; Wed, 18 Nov 2020 14:13:15 +0000 From: Colin King To: James Smart , Dick Kennedy , "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next] scsi: lpfc: Fix memory leak on lcb_context Date: Wed, 18 Nov 2020 14:13:14 +0000 Message-Id: <20201118141314.462471-1-colin.king@canonical.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King Currently there is an error return path that neglects to free the allocation for lcb_context. Fix this by adding a new error free exit path that kfree's lcb_context before returning. Use this new kfree exit path in another exit error path that also kfree's the same object, allowing a line of code to be removed. Addresses-Coverity: ("Resource leak") Fixes: 4430f7fd09ec ("scsi: lpfc: Rework locations of ndlp reference taking") Signed-off-by: Colin Ian King --- drivers/scsi/lpfc/lpfc_els.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c index 03f47d1b21fe..0d3271b4c130 100644 --- a/drivers/scsi/lpfc/lpfc_els.c +++ b/drivers/scsi/lpfc/lpfc_els.c @@ -6515,18 +6515,20 @@ lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, lcb_context->ndlp = lpfc_nlp_get(ndlp); if (!lcb_context->ndlp) { rjt_err = LSRJT_UNABLE_TPC; - goto rjt; + goto rjt_free; } if (lpfc_sli4_set_beacon(vport, lcb_context, state)) { lpfc_printf_vlog(ndlp->vport, KERN_ERR, LOG_TRACE_EVENT, "0193 failed to send mail box"); - kfree(lcb_context); lpfc_nlp_put(ndlp); rjt_err = LSRJT_UNABLE_TPC; - goto rjt; + goto rjt_free; } return 0; + +rjt_free: + kfree(lcb_context); rjt: memset(&stat, 0, sizeof(stat)); stat.un.b.lsRjtRsnCode = rjt_err; -- 2.28.0