mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Changyul Lee <lcy8047@gmail.com>
To: Maxim Levitsky <maximlevitsky@gmail.com>,
	Alex Dubov <oakad@yahoo.com>, Ulf Hansson <ulfh@kernel.org>
Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org,
	Changyul Lee <lcy8047@gmail.com>
Subject: [PATCH] memstick: core: Remove the host ID after device_del()
Date: Mon,  9 Nov 2026 12:54:41 -0500	[thread overview]
Message-ID: <20261109175441.1180468-1-lcy8047@gmail.com> (raw)

memstick_remove_host() removes the host ID from memstick_host_idr
before device_del() removes the "memstick<N>" device. A host added in
between, for example by another card reader being probed, can get the
same ID, and its device_add() fails:

  sysfs: cannot create duplicate filename '/class/memstick_host/memstick0'

Remove the ID after device_del(), as the error path of
memstick_add_host() already does.

Fixes: baf8532a147d ("memstick: initial commit for Sony MemoryStick support")
Signed-off-by: Changyul Lee <lcy8047@gmail.com>
---
Found with a static analysis tool we are developing.

Reproduced in QEMU (x86_64) with a test module that runs two kthreads
for 20 seconds. Each kthread allocates, adds, removes and frees a host
in a loop, under its own platform device as the parent. Without this
patch, device_add() failed with the error above 3713 to 4442 times per
run in three runs. With it, it never failed in three runs.
Not tested on MemoryStick hardware.

 drivers/memstick/core/memstick.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/memstick/core/memstick.c b/drivers/memstick/core/memstick.c
index 0d15f48ef51d..98057ffa1bf7 100644
--- a/drivers/memstick/core/memstick.c
+++ b/drivers/memstick/core/memstick.c
@@ -562,10 +562,10 @@ void memstick_remove_host(struct memstick_host *host)
 	host->set_param(host, MEMSTICK_POWER, MEMSTICK_POWER_OFF);
 	mutex_unlock(&host->lock);
 
+	device_del(&host->dev);
 	spin_lock(&memstick_host_lock);
 	idr_remove(&memstick_host_idr, host->id);
 	spin_unlock(&memstick_host_lock);
-	device_del(&host->dev);
 }
 EXPORT_SYMBOL(memstick_remove_host);
 

base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
-- 
2.43.0


                 reply	other threads:[~2026-11-09 17:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261109175441.1180468-1-lcy8047@gmail.com \
    --to=lcy8047@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=maximlevitsky@gmail.com \
    --cc=oakad@yahoo.com \
    --cc=ulfh@kernel.org \
    /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®