* [PATCH] btrfs: unwind device add when sysfs registration fails
@ 2026-10-03 11:19 Adarsh Das
0 siblings, 0 replies; only message in thread
From: Adarsh Das @ 2026-10-03 11:19 UTC (permalink / raw)
To: linux-btrfs
Cc: dsterba, mason, linux-kernel, syzbot+3bf3e110b2d406b8166c, Adarsh Das
btrfs_init_new_device() ignored the return value of
btrfs_sysfs_add_device(). When sysfs link creation failed (e.g. -EEXIST),
the add path continued, aborted the transaction with the same errno, and
tripped WARN_ON(btrfs_abort_should_print_stack()) while leaving the device
half-registered in memory.
Unwind through error_sysfs when sysfs registration fails, matching other
failure paths after the device lists are updated.
Reported-by: syzbot+3bf3e110b2d406b8166c@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/all/6a791c94.01d0871a.3a0d52.0099.GAE@google.com
Tested-by: syzbot+3bf3e110b2d406b8166c@syzkaller.appspotmail.com
Assisted-by: LLM
Signed-off-by: Adarsh Das <adarshdas950@gmail.com>
---
fs/btrfs/volumes.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 85ea9c5d4536..1517ed3da22c 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -3066,7 +3066,11 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
mutex_unlock(&fs_info->chunk_mutex);
/* Add sysfs device entry */
- btrfs_sysfs_add_device(device);
+ ret = btrfs_sysfs_add_device(device);
+ if (ret) {
+ mutex_unlock(&fs_devices->device_list_mutex);
+ goto error_sysfs;
+ }
mutex_unlock(&fs_devices->device_list_mutex);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-03 11:20 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-03 11:19 [PATCH] btrfs: unwind device add when sysfs registration fails Adarsh Das
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®