Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4378641ybl; Mon, 9 Dec 2019 09:49:40 -0800 (PST) X-Google-Smtp-Source: APXvYqyLAgzPcWqmv/tAz4uUtPFeF3h9M9cc2hbJmRIPUG5ElWF/0yNCtm++ZWuI3ySDSmht9+CC X-Received: by 2002:aca:ea46:: with SMTP id i67mr168911oih.149.1575913780753; Mon, 09 Dec 2019 09:49:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575913780; cv=none; d=google.com; s=arc-20160816; b=AFF5+Fw7KRy8j609BRHka5QegwV+LB87xshnIiKyrcMaLHvUQvN+sqMks1lBXHtRnB wZJhZ86BZN+u2SzNMMjeF6gUoG135O/TiJvpyOLOpMXPIcc6CV9wvvpR9Bfg1keLLWHz /RIBaCnL0cQUydTVc0dfHJ4k8QBU81rH9+8mLh9bvvKymorLVuRgQELZNUCVFdw2nLjk QdH3PJLtx59IlnOTi9fDUxSRklCSGNkwJZLOGg8wJlOiqYmmIZXzHKdVkqS3zhazucSi VVBFBxTQ4amow8XDCSILrraop7ynpaN4S2aDuiFLrpVeme1g6F00X7rdZwViTZmxoTGP SQyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=X/QxkqoCfNiDwbQBCosbR1xXW2Kn7mUOpxj7Z6Ec4tQ=; b=jyxgglnR/L6WLnHB/jcbZhRq1lWn1AjbUKYcQqj81usBY6JlYP3z22X7uytEzRSECn dCbjVOH0/7HbsNMKjTX1sy9BrF3n+mwgCbhZo9MJCPvjxJuBbr6Rr/6hYSC1uiJvoFvk QEBdMyG4KoRNw6F04ym0wKtl3OEzfAJJ/uVp86CAF354cIRGocoxRpdqsuDHmejO5ZOu Ko9nooPyQ4cyD9tIZ7aCmS6Y7OgkYmBySJ9FTyIJHIv8jLd3rryMf5sb7QGQtrufjeyW yUI8fdBm4CQ9hveAi4aBdYxezVzE+9VnNKz1wGLarl/rWtksdG/r6qeH9aOFMcrzEixf uoDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=FNFsQi1Z; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b133si284681oii.155.2019.12.09.09.49.28; Mon, 09 Dec 2019 09:49:40 -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; dkim=pass header.i=@broadcom.com header.s=google header.b=FNFsQi1Z; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726843AbfLIRs4 (ORCPT + 99 others); Mon, 9 Dec 2019 12:48:56 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:37569 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726678AbfLIRsv (ORCPT ); Mon, 9 Dec 2019 12:48:51 -0500 Received: by mail-wm1-f65.google.com with SMTP id f129so235227wmf.2 for ; Mon, 09 Dec 2019 09:48:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=X/QxkqoCfNiDwbQBCosbR1xXW2Kn7mUOpxj7Z6Ec4tQ=; b=FNFsQi1Ziq/g/TKpDjaB0oQo/xJ2w1yIoCHEIB+IWEbbT4RHkwM++ZkmUJhfYnK/4f DC+M843zmrYieXNJUjLeJFMOhGkF/81Hn4G3BYMZm3Y8F68htLlFurK7quXInOmRpH1u 3I1MeGlEko3ljtZKwhKApuHKK9J2hiRkzk9Iw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=X/QxkqoCfNiDwbQBCosbR1xXW2Kn7mUOpxj7Z6Ec4tQ=; b=Km9jOR4wQ9DABiQTOG46qfMkS1vBxGajVz/iOltOL7S0zVaEiicFLyhe05/l+MUK/6 FmAuZUShlMlP1Feu9hYRINV1/ckAff0Wf2UchNLGfH0nz4L0T/APxn4d2jM9s53bgDHi 3rr2T07MUxBzYI57npyq5UU63mknk3y5tCdVk7JYUxzRGCz0wBKYUNoZ/VwwIvV3tugj iNmpISOw+HUEXpGOGIlEHj32G6uEUCc+XwMxR9zoI12DdXuluePrmLwtlNJgQa4FOMfz 5dOEeu00A5TcUXEBNIYC4rgp2Ess8gKhMAV+VZLEdoJhou1h/8Pn5DbNOXK8PfSoKcEW ACWQ== X-Gm-Message-State: APjAAAWOzZMxyd51pKbdtCDaxHkJ94eeCj7FrkJpff7U2Gzt8gmyUAaZ 0MqJUxC9GOS9Iqjwg6f3VAJJwg== X-Received: by 2002:a7b:c19a:: with SMTP id y26mr242739wmi.152.1575913728145; Mon, 09 Dec 2019 09:48:48 -0800 (PST) Received: from [10.69.49.110] ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id n12sm131452wmd.1.2019.12.09.09.48.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Dec 2019 09:48:47 -0800 (PST) Subject: Re: [PATCH] scsi:lpfc:Fix memory leak on lpfc_bsg_write_ebuf_set func To: "wubo (T)" , "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 References: From: James Smart Message-ID: <4afb52b8-c3ff-8c29-2597-11b8428e75b1@broadcom.com> Date: Mon, 9 Dec 2019 09:48:44 -0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/6/2019 7:22 PM, wubo (T) wrote: > 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); > Looks good! Reviewed-by: James Smart -- james