From patchwork Mon Feb 12 16:27:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Desnoyers X-Patchwork-Id: 13553449 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05E0EC48297 for ; Mon, 12 Feb 2024 16:27:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 882846B0075; Mon, 12 Feb 2024 11:27:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 833326B0078; Mon, 12 Feb 2024 11:27:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D4076B007D; Mon, 12 Feb 2024 11:27:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 5EDFD6B0075 for ; Mon, 12 Feb 2024 11:27:28 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 2B036160A99 for ; Mon, 12 Feb 2024 16:27:28 +0000 (UTC) X-FDA: 81783682176.03.56754C4 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) by imf22.hostedemail.com (Postfix) with ESMTP id A0098C0009 for ; Mon, 12 Feb 2024 16:27:26 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=efficios.com header.s=smtpout1 header.b=ZZrr1DQ1; spf=pass (imf22.hostedemail.com: domain of mathieu.desnoyers@efficios.com designates 167.114.26.122 as permitted sender) smtp.mailfrom=mathieu.desnoyers@efficios.com; dmarc=pass (policy=none) header.from=efficios.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707755246; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=cnUjxkQdRKYQda8tkGke5Q+UBDn3p3ZjJMMvA4857oM=; b=owwPXTlvTgOdi4zBxR5cAivb1+Qc0ryvijEJJEsniNRY3r+Gdmrv5aw2QoKyRsWw3qrCoC A7CtOZm/3qyw2fNPdFJUG3/YI4/52tdSeWl4XV1ZHzROHCxQaKQ1g0a0dBfTtoBq8+HlNw ReB5lUmbZPHvcqfxC1q2dQ/AXTsKHi8= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=efficios.com header.s=smtpout1 header.b=ZZrr1DQ1; spf=pass (imf22.hostedemail.com: domain of mathieu.desnoyers@efficios.com designates 167.114.26.122 as permitted sender) smtp.mailfrom=mathieu.desnoyers@efficios.com; dmarc=pass (policy=none) header.from=efficios.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707755246; a=rsa-sha256; cv=none; b=y3ItDJwnqlq5XyfmW37fvOo8YduADKrVm3e+24jF+eqd7A8XJpHaPos8f2nrPbE4/Qsitv JJt+4DnF8PC1taVh4fR9aW1oV1rHlaSPwaNaw5DiwbzfY/THQKOOSQSOGWTlEK1ZEaedU6 eMKuFslPBSHx/Q1LDZI7YG7OQoohV0c= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1707755245; bh=k2sz/frCWDb4R4mtAgpiLkGT+g8hxxE7Hdk6DHyuU2A=; h=From:To:Cc:Subject:Date:From; b=ZZrr1DQ1AtimJocfUuWW9YjFO9Ko886wHKEZj/b/t3qVbPBnd3jlc1BxgqEPzBNRz CGLO3sSlYjlGi8OaD+jQWSzCM2lpa0rPlh5j2lfN4pHDTet9YqNN8aPWzIc4BcaGNm VTIWQI+Rlf/jGcB8TKe6i+zqeaBwQ0RuMxVMC85yXi2qOhJGUQMrIgP4Rr0B/4nxWx cOQ0eQGELKalLtEIqY0Ee4UhXQulAQY7bcXrw+oWU4f8IslM/3NK5r9ZDDjYJOeu/b bTK0UrdwmtePTqwwtSKUKQs6QQ2cETWBMpZmShYyehQrckpNvzGInZwhmX9gzAyrCq lrTir9cna9tcg== Received: from thinkos.internal.efficios.com (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4TYVH11GRXzYWC; Mon, 12 Feb 2024 11:27:25 -0500 (EST) From: Mathieu Desnoyers To: Cc: Mathieu Desnoyers , Dan Williams , Alasdair Kergon , Mike Snitzer , Mikulas Patocka , Andrew Morton , Linus Torvalds , Vishal Verma , Dave Jiang , Matthew Wilcox , Arnd Bergmann , Russell King , linux-arch@vger.kernel.org, linux-cxl@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-xfs@vger.kernel.org, dm-devel@lists.linux.dev, nvdimm@lists.linux.dev Subject: [PATCH] nvdimm/pmem: Fix leak on dax_add_host() failure Date: Mon, 12 Feb 2024 11:27:22 -0500 Message-Id: <20240212162722.19080-1-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspamd-Queue-Id: A0098C0009 X-Rspam-User: X-Stat-Signature: dnpxikqoqjbnqd7tcnoqaex94oo666bu X-Rspamd-Server: rspam01 X-HE-Tag: 1707755246-973022 X-HE-Meta: U2FsdGVkX19xY12EXb4lOFmDWpLRX5q9rTrBLKUPUVtgoKS0KLCNWCXN30kKFjxHd+P5f06NegwPyyNyVcaIvjqZkUNAR8Hajv6mhAaTBiD52ProVuQOC2YNYoMc9+5JhOHXSeF4VaQ5DXTIMy5hu2x0eVoYOR8i8JnQrDV56oAVg9iRPZ6wxqUqluzfpK7+sQfB8+r2nJ3Y/nZbGttebv1LBh4PpsrTArgVQcp9ZsfJjxBsaB6eK/vng7EMVXUvslVGgcFIpGFrfGV8nZp8B+SYakAa0D7ZEgmp4poaQhPhbf7eLQHYja0rtGG/tRNXS3zO0I8tt8nm/7OSp3+prczkUQJiRa61hNj+4fLGyafeQIkcj3sqcfD/XaiBnWg1fJOIpI9fESGuFUUUnH3Iv6TRmEePvD1PFcqdCLoLy9E+MOhzirkJgPNDPxFqumjbweJSO7fMF2Z9SO6MH6eMeHJcwA29ORwBmjpTB8tp0Q/uQ4bUt2kHgyFeKW3iDPOcwac6YMGkQ/vaw/rV4hmbLCzSsZs4qxMcxCAaBXfl8SyJ6TuVIEQ1mi78YO06lJzeI82WmpkxLoqVDtiPem8IHusYDCF5OKog2D35/EdLpELASYoSXs6dyNt/5UY6gVW4PWDZqRroO5ryfhrUsoIFgXk2Ut4VZPCJqtTR5lMwTczziSn6tzUEa3UTJFvJOQribdbqwdS4lZNFcwSq8sSUVzliVKFt1VCYV5YBM+fOS614TdBbD/hWGxHEyg1oQeLWMridrKfUiqORAU9z6AdDZsuVbvtZN9dS36ZHJzxYiR3OtENBHrJJNmZAYNkgytob1J32LnRYme3zNMSjhSMVv3cjR94qg3btWBPUYP0dHZ3pP8O+umGuLImTE+Haw4vF+SS7Y9JuGR95bD1W9FP7gPbbVQ+CHXAGwPb41XYgmpO4KgAOlMEGrfBXVibEjHiECl1SOVjGbL5Q5iCzKTM 6gydZvIg 0yEkKKibdpAZrj2c= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Fix a leak on dax_add_host() error, where "goto out_cleanup_dax" is done before setting pmem->dax_dev, which therefore issues the two following calls on NULL pointers: out_cleanup_dax: kill_dax(pmem->dax_dev); put_dax(pmem->dax_dev); Signed-off-by: Mathieu Desnoyers Reviewed-by: Dan Williams Cc: Alasdair Kergon Cc: Mike Snitzer Cc: Mikulas Patocka Cc: Andrew Morton Cc: Linus Torvalds Cc: Dan Williams Cc: Vishal Verma Cc: Dave Jiang Cc: Matthew Wilcox Cc: Arnd Bergmann Cc: Russell King Cc: linux-arch@vger.kernel.org Cc: linux-cxl@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org Cc: linux-mm@kvack.org Cc: linux-xfs@vger.kernel.org Cc: dm-devel@lists.linux.dev Cc: nvdimm@lists.linux.dev Reviewed-by: Dave Jiang Reviewed-by: Fan Ni --- drivers/nvdimm/pmem.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c index 4e8fdcb3f1c8..9fe358090720 100644 --- a/drivers/nvdimm/pmem.c +++ b/drivers/nvdimm/pmem.c @@ -566,12 +566,11 @@ static int pmem_attach_disk(struct device *dev, set_dax_nomc(dax_dev); if (is_nvdimm_sync(nd_region)) set_dax_synchronous(dax_dev); + pmem->dax_dev = dax_dev; rc = dax_add_host(dax_dev, disk); if (rc) goto out_cleanup_dax; dax_write_cache(dax_dev, nvdimm_has_cache(nd_region)); - pmem->dax_dev = dax_dev; - rc = device_add_disk(dev, disk, pmem_attribute_groups); if (rc) goto out_remove_host;