Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp2167357lqa; Tue, 30 Apr 2024 09:45:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUQ+tOifyUpnq1n/wdD87Vo6xeOTsHx8zBkuORU+ypnVkbi8E74SrU2X6d+aJ/cTYSPCQiG/6oz1aA3tBQ09QfctIk1cto3iramVK90sg== X-Google-Smtp-Source: AGHT+IEaWI2fbC4q+l6Cs9pTokbN7f0ygyY4vKiHdylHrFxWiXt7htjxkn0F2GZRYH3iwOm0jUbK X-Received: by 2002:a50:d5c2:0:b0:572:719f:b430 with SMTP id g2-20020a50d5c2000000b00572719fb430mr227107edj.32.1714495555456; Tue, 30 Apr 2024 09:45:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714495555; cv=pass; d=google.com; s=arc-20160816; b=ElUJGLZ3QsmN7zbgGeaGVAYCRqlV1rn8jdJ/O7p/ttm13zWcXJfiRTHT1zV6IR97XY Hdc43zgW4P/1XotCppjUNzpJSNPXa9WFb5X8hIoVawv6cRND4amBe74i5M1uiKR0sUqv Z7pzw2VGOTvYtMGxUdtO2S6uvFo34Ldkm6AMPaDNcAkqRsjPIAIl2zwiI1QxTzJdJ506 JT881eNUvcdpQsLDq2PSintfqVahtGNck4L77Ljsf/VLnn9390lHpGJme/Dg+wAJSYvu qdlK8PL2uyXEHLN/I9xgFYobnpvKTIo18TxHJWkv4WUG1jqZa0/4olHhr/2JSMcIDgP4 NrBw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:organization:references :in-reply-to:message-id:subject:cc:to:from:date; bh=AZIuXliFIb8FlTq+wD2X2kpSy6YZcOlYqtYfdzBYiIA=; fh=EudHniEUVrTWforHRSPFS323WuwlxWY+vhbhwfTuRmg=; b=jkbtsW0N1bXTUdvwkDkSImYkg1ETByfG5nzv8JRUx+EVC/wqpEsYfXQNR/WC8jG7lY EkkpxS5XW0JP1wKZmQ29KTPK2L0i8G8UbMt2EJHcfPVyShH+0IlpVc+CN3D7Tr139g/2 NEu0rhEZsk+VyxDVOKTahtDfUXJ7LD7p4DS6V6Ih2VY4RzVBvDAQkTALa0yFsZbuyFay W2clvu3PcXr2pdRkjau0+pQZtxl/wDf0PyJyfU87a1PvVzceFOZdnZGlfsZPZFcuiTcI RnBtI4lLUpTpGzUvOS8ATd5xomcksFx8zPxuH+n8v9KvU3nW9EVe37cWU6p4CgFfdqQ8 jKFg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-164413-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164413-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id b4-20020a509f04000000b0057225ad6164si8653605edf.25.2024.04.30.09.45.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 09:45:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-164413-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-164413-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164413-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 34A281F22E1C for ; Tue, 30 Apr 2024 16:45:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 94363176FC3; Tue, 30 Apr 2024 16:45:48 +0000 (UTC) Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2AB8112C7FA; Tue, 30 Apr 2024 16:45:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714495548; cv=none; b=KvNjd+4kuSbvpj/8WKGqH6W212v80hakT2XIQHGEtXyD2CcMArPhXEkrvkhPT1oV0PZWi9jGR4rkgPtPawGNjELCxSRXsVEe5xvRWloyEX14Ju6Ze6onh6zrL7e1JmIHd21rXzC4dG2wcDDYdLNm9NZkDAOTyMigs8RD4dtgeg4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714495548; c=relaxed/simple; bh=mfIY6Gne2tgJLNjHJkomMG8UMLhVXGCkif1Z7JBkoBs=; h=Date:From:To:CC:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WtHymQVfPZw5Mo4cois1PmIUfaz2srDAX8lhe/n9MclncN/NCunbOJvGpZqmjqL/NVi95inHUFjz1WqsppVWG80op+XavLKWtWIOy6TWizCs4kwuYcL211o26pha2iK012zrAUEXb2fUof8YTjddWeQf2Vx3JIfLe1Y6WkxAIqs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=Huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=Huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4VTQx11kDYz6J6dN; Wed, 1 May 2024 00:43:01 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id 5CF17140CF4; Wed, 1 May 2024 00:45:42 +0800 (CST) Received: from localhost (10.202.227.76) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Tue, 30 Apr 2024 17:45:41 +0100 Date: Tue, 30 Apr 2024 17:45:40 +0100 From: Jonathan Cameron To: Li Zhijian CC: , , , , , , , Subject: Re: [PATCH] cxl/region: Fix cxlr_pmem leaks Message-ID: <20240430174540.000039ce@Huawei.com> In-Reply-To: <20240428030748.318985-1-lizhijian@fujitsu.com> References: <20240428030748.318985-1-lizhijian@fujitsu.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: lhrpeml500004.china.huawei.com (7.191.163.9) To lhrpeml500005.china.huawei.com (7.191.163.240) On Sun, 28 Apr 2024 11:07:48 +0800 Li Zhijian wrote: > Before this error path, cxlr_pmem pointed to a kzalloc() memory, free > it to avoid this memory leaking. > > Fixes: f17b558d6663 ("cxl/pmem: Refactor nvdimm device registration, delete the workqueue") > Signed-off-by: Li Zhijian Fix is good, but this looks like nice case for conversion to cleanup.h stuff perhaps better to just do that? Would need a small amount of dancing on the final return to return cxlr->cxlr_pmem + pointer steal when setting cxlr->cxlr_pmem a few lines up. Also guard for the rwsem. Dave, Dan, worth doing or take this minimal fix and spin around later? If you think this is the way to go. Reviewed-by: Jonathan Cameron > --- > drivers/cxl/core/region.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c > index 5c186e0a39b9..812b2948b6c6 100644 > --- a/drivers/cxl/core/region.c > +++ b/drivers/cxl/core/region.c > @@ -2719,6 +2719,7 @@ static struct cxl_pmem_region *cxl_pmem_region_alloc(struct cxl_region *cxlr) > if (i == 0) { > cxl_nvb = cxl_find_nvdimm_bridge(cxlmd); > if (!cxl_nvb) { > + kfree(cxlr_pmem); > cxlr_pmem = ERR_PTR(-ENODEV); > goto out; > }