From patchwork Fri Feb 2 21:00:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Desnoyers X-Patchwork-Id: 196029 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp699300dyc; Fri, 2 Feb 2024 13:07:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IEXPjvev8u4C6c/0G6g8TnNwQR/iSr/socm37u7j6W9418Mb51Lgof0MJhWzS6ID9wCp5YR X-Received: by 2002:a05:6512:3696:b0:511:cba:cd73 with SMTP id d22-20020a056512369600b005110cbacd73mr4215567lfs.69.1706908039218; Fri, 02 Feb 2024 13:07:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706908039; cv=pass; d=google.com; s=arc-20160816; b=kTKvMGe45ZZe5b5pFQLpNdIgkMT3gvGbaDQHTsCNY87UwZlG76O3KHSio14dQN4ZDN W/LrYs0cZEzY8UumiycPKRp3MNlVZRy5+oT2NwKR1Qa1lmJXJDdieRknBjEbAoqmWLPh Y/GjrdfTxzQ7MNHer5hU4NPNVvOguZWRhLnM16RYvU7b2+rpv5SGx9Vurm2lCtuwGZEI fHjUwxVXBk594ZxkP/R30cSGMKJ/WRJEd4WHtxraj0t24yaemRZdz4nGLbAMWAdrR70w iowc7AQkzfldzVUx0iWNfkFF5JKnbEiocAuTL9uFS6XVsYJKViplFhB/Jf7CqmpPFhJW lfMg== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=TzzyzryuMk/YFmmwdL7/ClcZNi7RCUPErKB9A3hzeXw=; fh=YBjxhJu2fTy1ULVp65NIYUiymXxkpjZZNZELYfPQctg=; b=pzSXR7DwVYXegPMZjo1wN17hwMq3MMvYK/Lzjx6EalOPM6Uo1aqCPc+GzlKX6SxxST j1OaVPCjjgQSVau7wuoAEpfLIGXfba9Nua1jjCAxkgZhKL0dAWNDsIuIHKwXnGgVQ0fh pn9fCmrl/lXIc6KRK2uCLZhU66P+WWYK4JUvWuO6ZNNWIQKbCa7+MsyacfBRmnHWcW6P UWAvTn8lvMLLHDkC5yMEuoZ7Dpdg8TKNmxAd9lvhPa/hivnywn4D38E/O94O5/3gdMyc 7s6Mfu9vXMVdSr9PrgsaV3GJnrA6snzILW1mrS/21xg7XLCjUbH9NEGTEzxsS7cjg7zM KwTA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=olkQ8vHB; arc=pass (i=1 spf=pass spfdomain=efficios.com dkim=pass dkdomain=efficios.com dmarc=pass fromdomain=efficios.com); spf=pass (google.com: domain of linux-kernel+bounces-50578-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50578-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com X-Forwarded-Encrypted: i=1; AJvYcCXSRfUsBzkRfieAGkG+Wzq5CaMAoP1LTzuA9uYaks440Bz48pfrhqYwbvkw95bhSCV2mFi6adFdeGPUuCwzGf/8qI9gJA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id v1-20020a1709064e8100b00a373e3662ddsi128548eju.884.2024.02.02.13.07.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 13:07:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50578-ouuuleilei=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; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=olkQ8vHB; arc=pass (i=1 spf=pass spfdomain=efficios.com dkim=pass dkdomain=efficios.com dmarc=pass fromdomain=efficios.com); spf=pass (google.com: domain of linux-kernel+bounces-50578-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50578-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.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 C8CE21F213CA for ; Fri, 2 Feb 2024 21:07:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 007FA1384BA; Fri, 2 Feb 2024 21:00:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b="olkQ8vHB" Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) (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 943CD12C7EE; Fri, 2 Feb 2024 21:00:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=167.114.26.122 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706907631; cv=none; b=pcmnORtQAzo1sildzuVq6hk7uSXEPUtEyHMYtYBT3g+xnqKt1ONDKbaX8zwlmB1uUR9ZuFCoKSwLi5sbNPWtnxbJQNoJWRG4wRh9xYp/6ZhUjra1DINZwRPlz2PK5fTibjl5ZjYkskc4YcMK64bkl+bc7QBZQQc7nSYz1uu0O0I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706907631; c=relaxed/simple; bh=C9trdHKUBo0wvYK5DBzsNfOU9QCkPyPGO5T7CJRyOKU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Uwvd2uPPyKF3GucR7P7ZZcgNlyMkhr23CnBoUlxFgwPdSyUKhvxdGaV0F1VuZcLtGo2ByNaljBZwviQR6kmApLePLF2ehphAEyMzrPBMBJl2J2g+0QUDXlq1t6u/Jyj9DWqgn9yUDy1+zAdYQnpj5a0XxfOoDDrDCXdgp1GsLm8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com; spf=pass smtp.mailfrom=efficios.com; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b=olkQ8vHB; arc=none smtp.client-ip=167.114.26.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=efficios.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1706907627; bh=C9trdHKUBo0wvYK5DBzsNfOU9QCkPyPGO5T7CJRyOKU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=olkQ8vHBDWpgDSm0PdwKANERNaZOsyNCOuQxCFFGVBsLD7Ag/CgydWr3+PnCboGWb +hIPSsfeUgy6KlyuCCuiuPfERsK/mtMVZeN3F6hj24iXvLlqHKvWVMnhN+ewVfA/AA 9dSCFnRtTxiVUJqwb3fx9CGtZtzDHf3fYXJLNUajd1vzr7dv1k2M3iWpfI25zwFG2Y 1sm0tOKrJZdLKX/2FhGszkqnQD/SyOyzGMpy77l8cbhKZDwxeWGl8+MLyS8GNQ1C4F KSQLZfAtqgBbSQzv5qJelyGnvDGQfHgCKVKnpkAWAutmUaRMOzjk4YKBMbe1yJBvkG KJbJ7UojvG1Ww== 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 4TRSpg0YQmzWvD; Fri, 2 Feb 2024 16:00:27 -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: [RFC PATCH v4 01/12] nvdimm/pmem: Fix leak on dax_add_host() failure Date: Fri, 2 Feb 2024 16:00:08 -0500 Message-Id: <20240202210019.88022-2-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240202210019.88022-1-mathieu.desnoyers@efficios.com> References: <20240202210019.88022-1-mathieu.desnoyers@efficios.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789822804276047448 X-GMAIL-MSGID: 1789822804276047448 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 --- 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;