Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1502865ybl; Fri, 6 Dec 2019 19:26:46 -0800 (PST) X-Google-Smtp-Source: APXvYqyCSFciZkQLdwm9aoghPKAowImn0mLJUop5WzWrsCJNdVGAhFB6zbsanioYodkoCZmucui5 X-Received: by 2002:aca:edd5:: with SMTP id l204mr15938175oih.98.1575689206306; Fri, 06 Dec 2019 19:26:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575689206; cv=none; d=google.com; s=arc-20160816; b=W/NqnnnTDY+CZm1yDNiyfIfopZEXi1EPS1OZFdYaS6iG6JYlGnGEvDbjy3x+ZaNWtE p65f/2uCWZDFwVXTYHGVnKFMuR9nngr3OZq0QjJ71DVsCLGHHPu9MWDbKfsuRdbZgWln cktG7dDciQLSrYBMaJ1hBDh8Oagzhp6dX1DPsOAaYtQNOYQ4gF/s3A+M0+8fdgtAztH1 CVNjaW4tBXhixJpmod8oQhtQ8BujKGOiJeUREHqypjs9nKmDjEO8UT9uHdCBrv8UaguT v2AxC9IYHy3YLtc7OPCrMEIALEqfxWmJLM3feU64p5oiTKeOacrsNtbAs8oDmFucfhAp 7jWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:message-id:date:thread-index :thread-topic:subject:cc:to:from; bh=ly60gvbTlpr2FvcDaalpFAP/K6iNDktK3D2cKTLRqw8=; b=XhNAB55K2mZVsaDaRAQYHFYtQUh0vYM0semqi+PXzdykG8WISsHN4I5BLjABCYiFtF BfombXpAri1z6pxYipWm/xttrgs2BigXMRJawGDZUDHpPcxJTGZnxw67XJulu370S+Rs 0uNTw7pQOazQuEnfdZzmCH3gVplHsGBeWQ2N18C3vNVKy5UZAPY7BQPGrIqLc/B5dgsZ VOSm9BZ9t8622l0kuMbbe09ZTffeD4F7gNzZHRGIIKCktWdAKF0RdiH7pdSgK/T572o/ OSDXRbCAV9D1nAWGKW8lAml9WE8XI3O08Gtoo0La07AaYwE1BXdTeGgkCjMZL+IPr3Fn 8uww== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d4si7476498ote.135.2019.12.06.19.26.34; Fri, 06 Dec 2019 19:26:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726509AbfLGDXA convert rfc822-to-8bit (ORCPT + 99 others); Fri, 6 Dec 2019 22:23:00 -0500 Received: from szxga08-in.huawei.com ([45.249.212.255]:51206 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726375AbfLGDXA (ORCPT ); Fri, 6 Dec 2019 22:23:00 -0500 Received: from DGGEML402-HUB.china.huawei.com (unknown [172.30.72.54]) by Forcepoint Email with ESMTP id ED74ECD816885C6273E8; Sat, 7 Dec 2019 11:22:57 +0800 (CST) Received: from DGGEML525-MBS.china.huawei.com ([169.254.4.251]) by DGGEML402-HUB.china.huawei.com ([fe80::fca6:7568:4ee3:c776%31]) with mapi id 14.03.0439.000; Sat, 7 Dec 2019 11:22:47 +0800 From: "wubo (T)" To: "james.smart@broadcom.com" , "dick.kennedy@broadcom.com" , "jejb@linux.vnet.ibm.com" , "martin.petersen@oracle.com" , "linux-scsi@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: "liuzhiqiang (I)" , Mingfangsen Subject: [PATCH] scsi:lpfc:Fix memory leak on lpfc_bsg_write_ebuf_set func Thread-Topic: [PATCH] scsi:lpfc:Fix memory leak on lpfc_bsg_write_ebuf_set func Thread-Index: AdWsrSWHywN8OEO0QwWyn3DtmiXZsw== Date: Sat, 7 Dec 2019 03:22:46 +0000 Message-ID: Accept-Language: en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.173.221.252] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When phba->mbox_ext_buf_ctx.seqNum != phba->mbox_ext_buf_ctx.numBuf, dd_data should be freed before return SLI_CONFIG_HANDLED. When lpfc_sli_issue_mbox func return fails, pmboxq should be also freed in job_error tag. Signed-off-by:Bo wu Reviewed-by:Zhiqiang Liu --- drivers/scsi/lpfc/lpfc_bsg.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c index 39a736b887b1..6c2b03415a2c 100644 --- a/drivers/scsi/lpfc/lpfc_bsg.c +++ b/drivers/scsi/lpfc/lpfc_bsg.c @@ -4489,12 +4489,6 @@ lpfc_bsg_write_ebuf_set(struct lpfc_hba *phba, struct bsg_job *job, phba->mbox_ext_buf_ctx.seqNum++; nemb_tp = phba->mbox_ext_buf_ctx.nembType; - dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL); - if (!dd_data) { - rc = -ENOMEM; - goto job_error; - } - pbuf = (uint8_t *)dmabuf->virt; size = job->request_payload.payload_len; sg_copy_to_buffer(job->request_payload.sg_list, @@ -4531,6 +4525,13 @@ lpfc_bsg_write_ebuf_set(struct lpfc_hba *phba, struct bsg_job *job, "2968 SLI_CONFIG ext-buffer wr all %d " "ebuffers received\n", phba->mbox_ext_buf_ctx.numBuf); + + dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL); + if (!dd_data) { + rc = -ENOMEM; + goto job_error; + } + /* mailbox command structure for base driver */ pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); if (!pmboxq) { @@ -4579,6 +4580,8 @@ lpfc_bsg_write_ebuf_set(struct lpfc_hba *phba, struct bsg_job *job, return SLI_CONFIG_HANDLED; job_error: + if (pmboxq) + mempool_free(pmboxq, phba->mbox_mem_pool); lpfc_bsg_dma_page_free(phba, dmabuf); kfree(dd_data); -- 2.19.1