From patchwork Thu Feb 15 14:43:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Desnoyers X-Patchwork-Id: 13558529 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 7892FC4829E for ; Thu, 15 Feb 2024 14:43:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B16FD8D0006; Thu, 15 Feb 2024 09:43:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A9F588D0001; Thu, 15 Feb 2024 09:43:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9403A8D0006; Thu, 15 Feb 2024 09:43:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 808828D0001 for ; Thu, 15 Feb 2024 09:43:41 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 3C69180971 for ; Thu, 15 Feb 2024 14:43:41 +0000 (UTC) X-FDA: 81794307042.20.CC7E6AA Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) by imf28.hostedemail.com (Postfix) with ESMTP id 89AB2C0021 for ; Thu, 15 Feb 2024 14:43:38 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=efficios.com header.s=smtpout1 header.b=mFnMCnWW; spf=pass (imf28.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=1708008218; 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=RXhefjGMji9ARYAFGZLif9TyEMTX/6Fg8U/eiYk/wMc=; b=1WlnNxrUkfirrNk7ulFtzZ/ljAct0oO5A7wdk2p4TAERnyUZEynLNAl/v9inb2SQTv3jOc bY6y7nN4ihkpiGeoTwYn7+bm7qqyYZY7I2AOHzcJ0rv/+2Hg1q6t8+AF1cKwKcYsNklula eTwFJL8B2rnuf3yYZlxpdxVuFMZUtWU= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=efficios.com header.s=smtpout1 header.b=mFnMCnWW; spf=pass (imf28.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=1708008218; a=rsa-sha256; cv=none; b=fwvbD5yql5WqupHiLKuX+X7tbb3umCh/LIDx6gus+2IDtf6TUoD/OIgrtSZEfFJvKyXCTO BUQPUKWczcAmXkxrJEUTW+WuM4u5Cf52BBnXr0mDu1VgX1uaL2Qw7RUuqw+Mjq2how/GYd JaCoMEmf/VxWKL5leBYrDhWEjhCOfOk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1708008217; bh=ln3eEO71W6a/HB4BpqVFvAzjOL06V7sQyyqCuiIm4o8=; h=From:To:Cc:Subject:Date:From; b=mFnMCnWWSY/oz3cfgAglZzFkfce2dfZOYQ36NDRHuc70+Pbjjz2mWVQ6nWjD+rPZ1 WnE4nMw6J5orU72fJQAg/GCstx2ZUapfZLe/PMqhyMNtmgHWX0clQFg34C+3CaNZyU 1ly9rs6uD/lKyBlOHw6VZLJ05n39hjoOnRBll8RamfKOswbZWOhR28yN9vBd3pb8Vj hAoDrvplCH3rEk/qakzkdJgoqBMHOgnUMi8nxxYB9SB4+g81R+ABljrhLqNo17Tk/K wyk1n6kXqRHB/uXMNwYIuDE3W3Aj7ZZxG3nVplBs4j48GYzaE1PzLbw2SKxoFY1M/z YKY+fj3hAQcJQ== 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 4TbHqs08r0zZD5; Thu, 15 Feb 2024 09:43:37 -0500 (EST) From: Mathieu Desnoyers To: Dan Williams , Arnd Bergmann , Dave Chinner Cc: Mathieu Desnoyers , Dave Jiang , Fan Ni , Alasdair Kergon , Mike Snitzer , Mikulas Patocka , Andrew Morton , Linus Torvalds , Vishal Verma , Matthew Wilcox , 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 v2] nvdimm/pmem: Fix leak on dax_add_host() failure Date: Thu, 15 Feb 2024 09:43:24 -0500 Message-Id: <20240215144324.95436-1-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspamd-Queue-Id: 89AB2C0021 X-Rspam-User: X-Stat-Signature: pe4hp1pi69kspwo6k78qzax1kspmqgmu X-Rspamd-Server: rspam01 X-HE-Tag: 1708008218-701452 X-HE-Meta: U2FsdGVkX1+HA2Xd10Sl4RZ+12g2CzeNa5mp5K5GQlta92l+eE2rT5gm5XIsDE8AIxpUXBtxQmLh2+RBOoBREZZ2X6vkkKbDzLbtPH6uEqz77JIyCsN7ANdAdy64VWZHfsu5sYOAIk3hBPCkoNZPzL2m747wuEtcpf3ihGTO4A7Jdz7JWvnjYQx+VbAneKEUILYIW9zn8FO/u/pzJasJ6VZBKIBejfprr/zwBeZizX7URbwY5tJGSCRgRjZWGjEUkSnuOPhCfkP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q0rzuF2ecKmfZZRvNFug8ua/gy0o480zKJwwy2c52Bv1z/MNxKWzw+WXIvrXFEp8yz2UdhKLzNAgvodrvmkOTJnRmGmfQFQEtierEiLfUna3JqY8PUoTsY0uOBgDTrEYc4XkyRk4ZB73rjo+oqtRsmKbxdv8T61K2HB/sub9RNL/GPbxgBIbrzORFnfOcdQkoIvjWGbvSyVTRcWGw6yrHxSazcNVTE7zirySqr10lgzqnArJdXO8KrVoQxW6OQujK700ByiX+bfZ6uFmYbxAXf4xZsE76rxxBRauFzdAmXd2mQePAv4eOYew6cGiKdecPdrIsa 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 Reviewed-by: Dave Jiang Reviewed-by: Fan Ni 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 --- Changes since v1: - Add Reviewed-by tags. --- 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;