From patchwork Thu Feb 8 18:49:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Desnoyers X-Patchwork-Id: 13550319 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 85A77C48260 for ; Thu, 8 Feb 2024 18:49:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 55ED66B0081; Thu, 8 Feb 2024 13:49:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 510786B0082; Thu, 8 Feb 2024 13:49:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D7526B0083; Thu, 8 Feb 2024 13:49:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 301796B0081 for ; Thu, 8 Feb 2024 13:49:26 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C6BE4C0CD1 for ; Thu, 8 Feb 2024 18:49:25 +0000 (UTC) X-FDA: 81769524690.27.F8CD76D Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) by imf13.hostedemail.com (Postfix) with ESMTP id 3C96F20021 for ; Thu, 8 Feb 2024 18:49:24 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=efficios.com header.s=smtpout1 header.b=p981bkJM; spf=pass (imf13.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=1707418164; a=rsa-sha256; cv=none; b=42csL06sPjr0a4N1aLxS1JpQjw7ijxpkGxIzpSfCr0CvcwHQHVzQnzjsofl6hIOUNORRrL ra4i9bH/E6JZuAnr+DtCWZhu21aNTCHOcstmGJr44GPgUeGWSUq8dt3/HpCZPoPTBqBkW1 9N5YKjJfisWNr6nT3ug5o9EScsnfpq4= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=efficios.com header.s=smtpout1 header.b=p981bkJM; spf=pass (imf13.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=1707418164; 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:in-reply-to:references:references:dkim-signature; bh=TzzyzryuMk/YFmmwdL7/ClcZNi7RCUPErKB9A3hzeXw=; b=Y2ShU6P6LjLHQibWyZ/w1xhkUqNy1EEyXCdoeUKjlbyqr3nrtRqgFZbvs6EEdDbKDje0zF Srkv/7B5sAxIiJl2sUfOp4C0QrhY7+bMhl7h9bSOLlAJilG1YrqKztMg42i8eSqdVDPd95 OROgCbibYHPQB2drd55yEjO+Qo5d/PM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1707418163; bh=C9trdHKUBo0wvYK5DBzsNfOU9QCkPyPGO5T7CJRyOKU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p981bkJMDqSSou5rOlzOfJadbQ5Y29NotpQj8i1nf+2MvVgxD1FBmL+l4Xm7YmzdU pVOSVM/g3dAlLka98d2D7RwQsxmwG0ztt/y7tiwbLnCbBg1xIMfMZO94OwRGQcJSPb oCvXA7vGn5txoQucNNDP9tTcibZl6yUWk91V3wI4h34U+qdeKKwoaP4EMRaCV9XKgF S42nnYMRLuRYjp1ifApVRqANDFYDEM92NpD/EJeqN1d+yPvkJOrTEc6AotGzGZx2U+ 6+NLjtZJNGG8sAZom+Btw0vTtF6/O0vjyrrF0zmTTKf6S58kysA1oIjzBQgjHVR/w7 0MBHTWE0Z4ToQ== 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 4TW5cf5cnczXwf; Thu, 8 Feb 2024 13:49:22 -0500 (EST) From: Mathieu Desnoyers To: Dan Williams , Arnd Bergmann , Dave Chinner Cc: linux-kernel@vger.kernel.org, Mathieu Desnoyers , Andrew Morton , Linus Torvalds , Vishal Verma , Dave Jiang , 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, linux-s390@vger.kernel.org, Alasdair Kergon , Mike Snitzer , Mikulas Patocka Subject: [PATCH v4 01/12] nvdimm/pmem: Fix leak on dax_add_host() failure Date: Thu, 8 Feb 2024 13:49:02 -0500 Message-Id: <20240208184913.484340-2-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240208184913.484340-1-mathieu.desnoyers@efficios.com> References: <20240208184913.484340-1-mathieu.desnoyers@efficios.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 3C96F20021 X-Stat-Signature: cso837hfzauu5p5dfjeqzmcwnf4gi3zr X-Rspam-User: X-HE-Tag: 1707418164-5568 X-HE-Meta: U2FsdGVkX18vg9yHBrjEWqcV3EX1RQB1fVEM40PIKlx4y92nQ8diRebdbaVCm5ga0gaNRLAc7u21KKDWwKnCDPwabkoY1DDnKyjLxWxihbfsR1z3Gy+3sgblPPmEcIx6dnsQqK0mB4wRpkOenqdds4JXzLk8cpAB7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6xjW9ylKP5TqpcZlzelBSITlFkFy5Vjc+W+mtcE8gZxkFCUE2l5nT35RiqE8VKDG1q5CIv0FFGDKA799gm97JOF7D2DOKJjXXR+9Ds2ZQLTcFrVYUuxxE+4j05ZZmDNPgJyl3PoFK3xEpxoBZIqtkI9WWcPwUJ3/cimUpFHPJYdTDky0qGxLmT+u4SwWVEpQn91j70bYzKlN1aEuEEwGlKYaKb8ulFLiw0YGLeUo1R4cOUbEgF6dWl+oW7HAV9n3XnPP7ymQsmcewMIo3Bhjz/pfAI+7fNDN98rPeEHS9fV+fxmE6zDIFUaOsIbsXXCvURaagTBlFMmelGm0yXANrDd0j1PGjvlshML08hRoPu7DRGTg3Hx/z8XVtetsu6UNbouoSGAwCv9qGCEW9LBKIdfbQNdemWlZCpurQ= 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 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: Dan Williams --- 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;