mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wentao Liang <vulab@iscas.ac.cn>
To: dave.jiang@intel.com
Cc: djbw@kernel.org, ira.weiny@intel.com,
	linux-kernel@vger.kernel.org, nvdimm@lists.linux.dev,
	vishal.l.verma@intel.com, Wentao Liang <vulab@iscas.ac.cn>,
	stable@vger.kernel.org
Subject: [PATCH] nvdimm/bus: Fix dev double put in nd_async_device_register()
Date: Thu, 17 Sep 2026 12:28:16 +0000	[thread overview]
Message-ID: <20260917122816.2151081-1-vulab@iscas.ac.cn> (raw)

device_add() takes and drops its own reference on every return path, so
the async worker only owns the reference that __nd_device_register()
took with get_device(). The failure branch drops that same reference once
more before the unconditional put_device(), which underflows the refcount
and frees the device while it is still referenced by its creator, as
reported by KASAN for the parent pointer access in this function.

Drop the spurious put_device() from the failure branch.

Fixes: 4d88a97aa9e8c ("libnvdimm, nvdimm: dimm driver and base libnvdimm device-driver infrastructure")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 drivers/nvdimm/bus.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/nvdimm/bus.c b/drivers/nvdimm/bus.c
index 45b7d756e39a..a1f33a03aba8 100644
--- a/drivers/nvdimm/bus.c
+++ b/drivers/nvdimm/bus.c
@@ -488,10 +488,8 @@ static void nd_async_device_register(void *d, async_cookie_t cookie)
 	struct device *dev = d;
 	struct device *parent = dev->parent;
 
-	if (device_add(dev) != 0) {
+	if (device_add(dev) != 0)
 		dev_err(dev, "%s: failed\n", __func__);
-		put_device(dev);
-	}
 	put_device(dev);
 	if (parent)
 		put_device(parent);
-- 
2.34.1


             reply	other threads:[~2026-09-17 12:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-17 12:28 Wentao Liang [this message]
2026-10-10  2:24 ` Alison Schofield

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260917122816.2151081-1-vulab@iscas.ac.cn \
    --to=vulab@iscas.ac.cn \
    --cc=dave.jiang@intel.com \
    --cc=djbw@kernel.org \
    --cc=ira.weiny@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nvdimm@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=vishal.l.verma@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®