Skip to contentSkip to conversation

memory leak in hub_event (4)

syzbot In review syzbot 6 participants 23 messages Apr 25 – Apr 30

Subsystems (3)
lore
Share & tools
lore

syzbot

author syzbot
#0 lore raw

Hello,

syzbot found the following issue on:

HEAD commit:    dd6c438c3e64 Merge tag 'vfs-7.1-rc1.fixes' of git://git.ke..
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=15cf7702580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=ac5083db84233db3
dashboard link: https://syzkaller.appspot.com/bug?extid=2afd7e71155c7e241560
compiler:       gcc (Debian 14.2.0-19) 14.2.0, GNU ld (GNU Binutils for Debian) 2.44
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=13cf7702580000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=17941c36580000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/dea6ab846ab3/disk-dd6c438c.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/acebe380aa03/vmlinux-dd6c438c.xz
kernel image: https://storage.googleapis.com/syzbot-assets/2cdbd012d0d3/bzImage-dd6c438c.xz

IMPORTANT: if you fix the issue, please add the following tag to the commit:

Reported-by [email protected]
BUG: memory leak
unreferenced object 0xffff8881277dc000 (size 2048):
  comm "kworker/0:2", pid 1783, jiffies 4294946784
  hex dump (first 32 bytes):
    ff ff ff ff 31 00 00 00 00 00 00 00 00 00 00 00  ....1...........
    00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00  ................
  backtrace (crc 20105372):
    kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
    slab_post_alloc_hook mm/slub.c:4574 [inline]
    slab_alloc_node mm/slub.c:4898 [inline]
    __kmalloc_cache_noprof+0x371/0x480 mm/slub.c:5410
    kmalloc_noprof include/linux/slab.h:950 [inline]
    kzalloc_noprof include/linux/slab.h:1188 [inline]
    usb_alloc_dev+0x36/0x4e0 drivers/usb/core/usb.c:651
    hub_port_connect drivers/usb/core/hub.c:5470 [inline]
    hub_port_connect_change drivers/usb/core/hub.c:5707 [inline]
    port_event drivers/usb/core/hub.c:5871 [inline]
    hub_event+0x14d0/0x2180 drivers/usb/core/hub.c:5953
    process_one_work+0x277/0x5b0 kernel/workqueue.c:3302
    process_scheduled_works kernel/workqueue.c:3385 [inline]
    worker_thread+0x255/0x4a0 kernel/workqueue.c:3466
    kthread+0x14e/0x1a0 kernel/kthread.c:436
    ret_from_fork+0x219/0x490 arch/x86/kernel/process.c:158
    ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245

BUG: memory leak
unreferenced object 0xffff888128b06c00 (size 1024):
  comm "kworker/0:2", pid 1783, jiffies 4294946815
  hex dump (first 32 bytes):
    09 02 49 00 02 01 00 10 40 00 00 00 00 00 00 00  ..I.....@.......
    00 00 00 00 00 00 00 00 89 b8 69 09 81 88 ff ff  ..........i.....
  backtrace (crc b43c3ef8):
    kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
    slab_post_alloc_hook mm/slub.c:4574 [inline]
    slab_alloc_node mm/slub.c:4898 [inline]
    __do_kmalloc_node mm/slub.c:5294 [inline]
    __kmalloc_noprof+0x3b7/0x550 mm/slub.c:5307
    kmalloc_noprof include/linux/slab.h:954 [inline]
    kzalloc_noprof include/linux/slab.h:1188 [inline]
    usb_get_configuration+0xeb/0x2110 drivers/usb/core/config.c:940
    usb_enumerate_device drivers/usb/core/hub.c:2527 [inline]
    usb_new_device+0x1b4/0x300 drivers/usb/core/hub.c:2665
    hub_port_connect drivers/usb/core/hub.c:5567 [inline]
    hub_port_connect_change drivers/usb/core/hub.c:5707 [inline]
    port_event drivers/usb/core/hub.c:5871 [inline]
    hub_event+0x1723/0x2180 drivers/usb/core/hub.c:5953
    process_one_work+0x277/0x5b0 kernel/workqueue.c:3302
    process_scheduled_works kernel/workqueue.c:3385 [inline]
    worker_thread+0x255/0x4a0 kernel/workqueue.c:3466
    kthread+0x14e/0x1a0 kernel/kthread.c:436
    ret_from_fork+0x219/0x490 arch/x86/kernel/process.c:158
    ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245

BUG: memory leak
unreferenced object 0xffff88810c3d5a50 (size 8):
  comm "kworker/0:2", pid 1783, jiffies 4294946815
  hex dump (first 8 bytes):
    80 b8 69 09 81 88 ff ff                          ..i.....
  backtrace (crc 66af3167):
    kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
    slab_post_alloc_hook mm/slub.c:4574 [inline]
    slab_alloc_node mm/slub.c:4898 [inline]
    __do_kmalloc_node mm/slub.c:5294 [inline]
    __kmalloc_noprof+0x3b7/0x550 mm/slub.c:5307
    kmalloc_noprof include/linux/slab.h:954 [inline]
    kzalloc_noprof include/linux/slab.h:1188 [inline]
    usb_get_configuration+0x11d/0x2110 drivers/usb/core/config.c:945
    usb_enumerate_device drivers/usb/core/hub.c:2527 [inline]
    usb_new_device+0x1b4/0x300 drivers/usb/core/hub.c:2665
    hub_port_connect drivers/usb/core/hub.c:5567 [inline]
    hub_port_connect_change drivers/usb/core/hub.c:5707 [inline]
    port_event drivers/usb/core/hub.c:5871 [inline]
    hub_event+0x1723/0x2180 drivers/usb/core/hub.c:5953
    process_one_work+0x277/0x5b0 kernel/workqueue.c:3302
    process_scheduled_works kernel/workqueue.c:3385 [inline]
    worker_thread+0x255/0x4a0 kernel/workqueue.c:3466
    kthread+0x14e/0x1a0 kernel/kthread.c:436
    ret_from_fork+0x219/0x490 arch/x86/kernel/process.c:158
    ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245

BUG: memory leak
unreferenced object 0xffff888113c25840 (size 64):
  comm "kworker/0:2", pid 1783, jiffies 4294946817
  hex dump (first 32 bytes):
    01 00 00 00 01 00 00 00 09 04 00 00 00 01 01 30  ...............0
    00 00 00 00 0a 00 00 00 9a b8 69 09 81 88 ff ff  ..........i.....
  backtrace (crc a90fa323):
    kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
    slab_post_alloc_hook mm/slub.c:4574 [inline]
    slab_alloc_node mm/slub.c:4898 [inline]
    __do_kmalloc_node mm/slub.c:5294 [inline]
    __kmalloc_noprof+0x3b7/0x550 mm/slub.c:5307
    kmalloc_noprof include/linux/slab.h:954 [inline]
    kzalloc_noprof include/linux/slab.h:1188 [inline]
    usb_parse_configuration drivers/usb/core/config.c:826 [inline]
    usb_get_configuration+0x88f/0x2110 drivers/usb/core/config.c:1002
    usb_enumerate_device drivers/usb/core/hub.c:2527 [inline]
    usb_new_device+0x1b4/0x300 drivers/usb/core/hub.c:2665
    hub_port_connect drivers/usb/core/hub.c:5567 [inline]
    hub_port_connect_change drivers/usb/core/hub.c:5707 [inline]
    port_event drivers/usb/core/hub.c:5871 [inline]
    hub_event+0x1723/0x2180 drivers/usb/core/hub.c:5953
    process_one_work+0x277/0x5b0 kernel/workqueue.c:3302
    process_scheduled_works kernel/workqueue.c:3385 [inline]
    worker_thread+0x255/0x4a0 kernel/workqueue.c:3466
    kthread+0x14e/0x1a0 kernel/kthread.c:436
    ret_from_fork+0x219/0x490 arch/x86/kernel/process.c:158
    ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245

BUG: memory leak
unreferenced object 0xffff88811d54a500 (size 256):
  comm "kworker/0:2", pid 1783, jiffies 4294946821
  hex dump (first 32 bytes):
    00 00 00 00 00 00 00 00 08 a5 54 1d 81 88 ff ff  ..........T.....
    08 a5 54 1d 81 88 ff ff 20 e7 41 83 ff ff ff ff  ..T..... .A.....
  backtrace (crc 85d09f91):
    kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
    slab_post_alloc_hook mm/slub.c:4574 [inline]
    slab_alloc_node mm/slub.c:4898 [inline]
    __kmalloc_cache_noprof+0x371/0x480 mm/slub.c:5410
    kmalloc_noprof include/linux/slab.h:950 [inline]
    kzalloc_noprof include/linux/slab.h:1188 [inline]
    device_private_init drivers/base/core.c:3536 [inline]
    device_add+0x73c/0xc70 drivers/base/core.c:3587
    usb_new_device.cold+0x115/0x626 drivers/usb/core/hub.c:2695
    hub_port_connect drivers/usb/core/hub.c:5567 [inline]
    hub_port_connect_change drivers/usb/core/hub.c:5707 [inline]
    port_event drivers/usb/core/hub.c:5871 [inline]
    hub_event+0x1723/0x2180 drivers/usb/core/hub.c:5953
    process_one_work+0x277/0x5b0 kernel/workqueue.c:3302
    process_scheduled_works kernel/workqueue.c:3385 [inline]
    worker_thread+0x255/0x4a0 kernel/workqueue.c:3466
    kthread+0x14e/0x1a0 kernel/kthread.c:436
    ret_from_fork+0x219/0x490 arch/x86/kernel/process.c:158
    ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245

connection error: failed to recv *flatrpc.ExecutorMessageRawT: EOF

---
This report is generated by a bot. It may contain errors. See https://goo.gl/tpsmEJ for more information about syzbot. syzbot engineers can be reached at [email protected].

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.

If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title

If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.

If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)

If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report

If you want to undo deduplication, reply with:
#syz undup

author syzbot
#1 lore raw

Forwarded: [PATCH] usb: core: fix memory leak in usb_new_device() error path

For archival purposes, forwarding an incoming command email to [email protected], [email protected].

For archival purposes, forwarding an incoming command email to [email protected], [email protected].

***

Subject: [PATCH] usb: core: fix memory leak in usb_new_device() error path
Author: [email protected]

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master

When usb_new_device() fails, it jumps to the 'fail' label which calls pm_runtime_disable() but never balances the earlier pm_runtime_get_noresume() call made at the top of the function.

This leaves the PM runtime usage count elevated, preventing usb_put_dev() in hub_port_connect() from dropping the refcount to zero. As a result, usb_release_dev() never fires and usb_destroy_configuration() is never called, leaking all memory allocated during enumeration:

  - struct usb_device          (2048 bytes) via usb_alloc_dev()
  - raw config descriptor      (1024 bytes) via usb_get_configuration()
  - config metadata            (   8 bytes) via usb_get_configuration()
  - interface descriptor       (  64 bytes) via usb_parse_configuration()
  - struct device_private      ( 256 bytes) via device_private_init()

Fix this by adding pm_runtime_put_noidle() on the fail path to balance the pm_runtime_get_noresume() at the top of the function. pm_runtime_put_noidle() is correct here rather than pm_runtime_put() because we are in a teardown path and must not trigger autosuspend scheduling.

---
 drivers/usb/core/hub.c | 1 +
 1 file changed, 1 insertion(+)
drivers/usb/core/hub.c +1 -0
index 24960ba9caa9..148fadfbc30b 100644
@@ -2733,6 +2733,7 @@ int usb_new_device(struct usb_device *udev)
 	usb_set_device_state(udev, USB_STATE_NOTATTACHED);
 	pm_runtime_disable(&udev->dev);
 	pm_runtime_set_suspended(&udev->dev);
+	pm_runtime_put_noidle(&udev->dev);
 	return err;
 }
 
Signature · 1 line
2.43.0
author syzbot
#2 lore raw

Forwarded: [PATCH] ALSA: caiaq: fix usb_dev refcount leak on probe failure

In reply to syzbot
For archival purposes, forwarding an incoming command email to [email protected], [email protected].

For archival purposes, forwarding an incoming command email to [email protected], [email protected].

***

Subject: [PATCH] ALSA: caiaq: fix usb_dev refcount leak on probe failure
Author: [email protected]

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master

create_card() takes a reference on the USB device with usb_get_dev() and stores the matching usb_put_dev() in card_free(), which is installed as the snd_card's ->private_free destructor.

However, ->private_free is only assigned near the end of init_card(), after several failure points (usb_set_interface(), EP type checks, usb_submit_urb(), the EP1_CMD_GET_DEVICE_INFO exchange, and its timeout). When any of those fail, init_card() returns an error to snd_probe(), which calls snd_card_free(card). Because ->private_free is still NULL, card_free() never runs, the usb_get_dev() reference is not dropped, and the struct usb_device leaks along with its descriptor allocations and device_private.

syzbot reproduces this with a malformed UAC3 device whose only valid altsetting is 0; init_card()'s usb_set_interface(usb_dev, 0, 1) call fails with -EIO and triggers the leak.

Move the ->private_free assignment into create_card(), immediately after usb_get_dev(), so that every error path reaching snd_card_free() balances the reference. card_free()'s callees (snd_usb_caiaq_input_free, free_urbs, kfree) already tolerate the partially-initialized state because the chip private area is zero-initialized by snd_card_new().

---
 sound/usb/caiaq/device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/usb/caiaq/device.c +1 -1
index 51177ebfb8c6..f084a0f782ad 100644
@@ -411,6 +411,7 @@ static int create_card(struct usb_device *usb_dev,
 
 	cdev = caiaqdev(card);
 	cdev->chip.dev = usb_get_dev(usb_dev);
+	card->private_free = card_free;
 	cdev->chip.card = card;
 	cdev->chip.usb_id = USB_ID(le16_to_cpu(usb_dev->descriptor.idVendor),
 				  le16_to_cpu(usb_dev->descriptor.idProduct));
@@ -500,7 +501,6 @@ static int init_card(struct snd_usb_caiaqdev *cdev)
 		       cdev->vendor_name, cdev->product_name, usbpath);
 
 	setup_card(cdev);
-	card->private_free = card_free;
 	return 0;
 
  err_kill_urb:
Signature · 1 line
2.43.0
author syzbot
#3 lore raw

Forwarded: [PATCH] usb: core: hub: fix memory leak in hub_port_connect

In reply to syzbot
For archival purposes, forwarding an incoming command email to [email protected], [email protected].

For archival purposes, forwarding an incoming command email to [email protected], [email protected].

***

Subject: [PATCH] usb: core: hub: fix memory leak in hub_port_connect
Author: [email protected]

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
master

drivers/usb/core/hub.c +0 -0
index 24960ba9caa9..2924ce770066 100644
@@ -5405,6 +5405,7 @@ static void hub_port_connect(struct usb_hub *hub, int

port1, u16 portstatus,

                if (hcd->usb_phy && !hdev->parent)
                        usb_phy_notify_disconnect(hcd->usb_phy,
udev->speed);
                usb_disconnect(&port_dev->child);
+               udev = NULL;
        }

        /* We can forget about a "removed" device when there's a physical
@@ -5582,6 +5583,7 @@ static void hub_port_connect(struct usb_hub *hub, int
port1, u16 portstatus,
                        goto loop_disable;

                status = hub_power_remaining(hub);
+               udev = NULL;
                if (status)
                        dev_dbg(hub->intfdev, "%dmA power budget left\n",

status);

@@ -5624,6 +5626,8 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,

                if (status != -ENOTCONN && status != -ENODEV)
                        hcd->driver->relinquish_port(hcd, port1);
        }

+ if (udev)
+ usb_put_dev(udev);
}

/* Handle physical or logical connection change events.

author syzbot
#4 lore raw

Forwarded: [PATCH] usb: core: hub: fix memory leak in hub_port_connect

In reply to syzbot
For archival purposes, forwarding an incoming command email to [email protected], [email protected].

For archival purposes, forwarding an incoming command email to [email protected], [email protected].

***

Subject: [PATCH] usb: core: hub: fix memory leak in hub_port_connect
Author: [email protected]

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master

---
 drivers/usb/core/hub.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/usb/core/hub.c +4 -0
index 24960ba9caa9..2924ce770066 100644
@@ -5405,6 +5405,7 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
 		if (hcd->usb_phy && !hdev->parent)
 			usb_phy_notify_disconnect(hcd->usb_phy, udev->speed);
 		usb_disconnect(&port_dev->child);
+		udev = NULL;
 	}
 
 	/* We can forget about a "removed" device when there's a physical
@@ -5582,6 +5583,7 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
 			goto loop_disable;
 
 		status = hub_power_remaining(hub);
+		udev = NULL;
 		if (status)
 			dev_dbg(hub->intfdev, "%dmA power budget left\n", status);
 
@@ -5624,6 +5626,8 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
 		if (status != -ENOTCONN && status != -ENODEV)
 			hcd->driver->relinquish_port(hcd, port1);
 	}
+	if (udev)
+    		usb_put_dev(udev);
 }
 
 /* Handle physical or logical connection change events.
Signature · 1 line
2.52.0
author syzbot
#5 lore raw

Forwarded: [PATCH] ALSA: caiaq: fix usb_dev refcount leak on probe failure

In reply to syzbot
For archival purposes, forwarding an incoming command email to [email protected], [email protected].

For archival purposes, forwarding an incoming command email to [email protected], [email protected].

***

Subject: [PATCH] ALSA: caiaq: fix usb_dev refcount leak on probe failure
Author: [email protected]

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master

create_card() takes a reference on the USB device with usb_get_dev() and stores the matching usb_put_dev() in card_free(), which is installed as the snd_card's ->private_free destructor.

However, ->private_free is only assigned near the end of init_card(), after several failure points (usb_set_interface(), EP type checks, usb_submit_urb(), the EP1_CMD_GET_DEVICE_INFO exchange, and its timeout). When any of those fail, init_card() returns an error to snd_probe(), which calls snd_card_free(card). Because ->private_free is still NULL, card_free() never runs, the usb_get_dev() reference is not dropped, and the struct usb_device leaks along with its descriptor allocations and device_private.

syzbot reproduces this with a malformed UAC3 device whose only valid altsetting is 0; init_card()'s usb_set_interface(usb_dev, 0, 1) call fails with -EIO and triggers the leak.

Move the ->private_free assignment into create_card(), immediately after usb_get_dev(), so that every error path reaching snd_card_free() balances the reference. card_free()'s callees (snd_usb_caiaq_input_free, free_urbs, kfree) already tolerate the partially-initialized state because the chip private area is zero-initialized by snd_card_new().

---
 sound/usb/caiaq/device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/usb/caiaq/device.c +1 -1
index 51177ebfb8c6..f084a0f782ad 100644
@@ -411,6 +411,7 @@ static int create_card(struct usb_device *usb_dev,
 
 	cdev = caiaqdev(card);
 	cdev->chip.dev = usb_get_dev(usb_dev);
+	card->private_free = card_free;
 	cdev->chip.card = card;
 	cdev->chip.usb_id = USB_ID(le16_to_cpu(usb_dev->descriptor.idVendor),
 				  le16_to_cpu(usb_dev->descriptor.idProduct));
@@ -500,7 +501,6 @@ static int init_card(struct snd_usb_caiaqdev *cdev)
 		       cdev->vendor_name, cdev->product_name, usbpath);
 
 	setup_card(cdev);
-	card->private_free = card_free;
 	return 0;
 
  err_kill_urb:
Signature · 1 line
2.43.0
author syzbot
#6 lore raw

Forwarded: [PATCH] ALSA: caiaq: fix usb_dev refcount leak on probe failure

In reply to syzbot
For archival purposes, forwarding an incoming command email to [email protected], [email protected].

For archival purposes, forwarding an incoming command email to [email protected], [email protected].

***

Subject: [PATCH] ALSA: caiaq: fix usb_dev refcount leak on probe failure
Author: [email protected]

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master

create_card() takes a reference on the USB device with usb_get_dev() and stores the matching usb_put_dev() in card_free(), which is installed as the snd_card's ->private_free destructor.

However, ->private_free is only assigned near the end of init_card(), after several failure points (usb_set_interface(), EP type checks, usb_submit_urb(), the EP1_CMD_GET_DEVICE_INFO exchange, and its timeout). When any of those fail, init_card() returns an error to snd_probe(), which calls snd_card_free(card). Because ->private_free is still NULL, card_free() never runs, the usb_get_dev() reference is not dropped, and the struct usb_device leaks along with its descriptor allocations and device_private.

syzbot reproduces this with a malformed UAC3 device whose only valid altsetting is 0; init_card()'s usb_set_interface(usb_dev, 0, 1) call fails with -EIO and triggers the leak.

Move the ->private_free assignment into create_card(), immediately after usb_get_dev(), so that every error path reaching snd_card_free() balances the reference. card_free()'s callees (snd_usb_caiaq_input_free, free_urbs, kfree) already tolerate the partially-initialized state because the chip private area is zero-initialized by snd_card_new().

---
 sound/usb/caiaq/device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/usb/caiaq/device.c +1 -1
index 8af0c04041ee..ad9f744b496b 100644
@@ -423,6 +423,7 @@ static int create_card(struct usb_device *usb_dev,
 
 	cdev = caiaqdev(card);
 	cdev->chip.dev = usb_get_dev(usb_dev);
+	card->private_free = card_free;
 	cdev->chip.card = card;
 	cdev->chip.usb_id = USB_ID(le16_to_cpu(usb_dev->descriptor.idVendor),
 				  le16_to_cpu(usb_dev->descriptor.idProduct));
@@ -511,7 +512,6 @@ static int init_card(struct snd_usb_caiaqdev *cdev)
 	scnprintf(card->longname, sizeof(card->longname), "%s %s (%s)",
 		       cdev->vendor_name, cdev->product_name, usbpath);
 
-	card->private_free = card_free;
 	err = setup_card(cdev);
 	if (err < 0)
 		return err;
Signature · 1 line
2.43.0
#7 lore raw

Re: Forwarded: [PATCH] ALSA: caiaq: fix usb_dev refcount leak on probe failure

Quoted 9 lines

Date: Sat, 25 Apr 2026 07:43:17 -0700
For archival purposes, forwarding an incoming command email to [email protected], [email protected].

***

Subject: [PATCH] ALSA: caiaq: fix usb_dev refcount leak on probe failure
Author: [email protected]

Deepanshu, can you please correctly fill your Cc list as required to avoid this forwarded message which is a waste of net bandwidth?

Quoted 56 lines

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master

create_card() takes a reference on the USB device with usb_get_dev() and stores the matching usb_put_dev() in card_free(), which is installed as the snd_card's ->private_free destructor.

However, ->private_free is only assigned near the end of init_card(), after several failure points (usb_set_interface(), EP type checks, usb_submit_urb(), the EP1_CMD_GET_DEVICE_INFO exchange, and its timeout). When any of those fail, init_card() returns an error to snd_probe(), which calls snd_card_free(card). Because ->private_free is still NULL, card_free() never runs, the usb_get_dev() reference is not dropped, and the struct usb_device leaks along with its descriptor allocations and device_private.

syzbot reproduces this with a malformed UAC3 device whose only valid altsetting is 0; init_card()'s usb_set_interface(usb_dev, 0, 1) call fails with -EIO and triggers the leak.

Move the ->private_free assignment into create_card(), immediately after usb_get_dev(), so that every error path reaching snd_card_free() balances the reference. card_free()'s callees (snd_usb_caiaq_input_free, free_urbs, kfree) already tolerate the partially-initialized state because the chip private area is zero-initialized by snd_card_new().

---
 sound/usb/caiaq/device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/usb/caiaq/device.c +1 -1
index 8af0c04041ee..ad9f744b496b 100644
@@ -423,6 +423,7 @@ static int create_card(struct usb_device *usb_dev,
 
 	cdev = caiaqdev(card);
 	cdev->chip.dev = usb_get_dev(usb_dev);
+	card->private_free = card_free;
 	cdev->chip.card = card;
 	cdev->chip.usb_id = USB_ID(le16_to_cpu(usb_dev->descriptor.idVendor),
 				  le16_to_cpu(usb_dev->descriptor.idProduct));
@@ -511,7 +512,6 @@ static int init_card(struct snd_usb_caiaqdev *cdev)
 	scnprintf(card->longname, sizeof(card->longname), "%s %s (%s)",
 		       cdev->vendor_name, cdev->product_name, usbpath);
 
-	card->private_free = card_free;
 	err = setup_card(cdev);
 	if (err < 0)
 		return err;
Signature · 1 line
2.43.0
#8 lore raw
In reply to syzbot

On 25.04.26 04:12, syzbot wrote:

#syz test: git://repo/address.git dd6c438c3e64

From 001175f4d2e1c2ceac98b4af2521fc4d0253d0c8 Mon Sep 17 00:00:00 2001
From: Oliver Neukum <[email protected]>
Date: Mon, 27 Apr 2026 13:35:38 +0200
Subject: [PATCH] usb: core: fix memory of error case in usb_get_configuration

Prior allocations need to be reversed if subsequent allocations fail.

Fixes dd2057e544dc9 ("USB: core: drop OOM message")
Reported-by [email protected]
---
 drivers/usb/core/config.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/usb/core/config.c +11 -2
index 417140b012bb..67475ff81641 100644
@@ -944,11 +944,11 @@ int usb_get_configuration(struct usb_device *dev)
 	length = ncfg * sizeof(char *);
 	dev->rawdescriptors = kzalloc(length, GFP_KERNEL);
 	if (!dev->rawdescriptors)
-		return -ENOMEM;
+		goto bailout2;
 
 	desc = kmalloc(USB_DT_CONFIG_SIZE, GFP_KERNEL);
 	if (!desc)
-		return -ENOMEM;
+		goto bailout;
 
 	for (cfgno = 0; cfgno < ncfg; cfgno++) {
 		/* We grab just the first descriptor so we know how long
@@ -1012,6 +1012,15 @@ int usb_get_configuration(struct usb_device *dev)
 	dev->descriptor.bNumConfigurations = cfgno;
 
 	return result;
+
+bailout:
+	kfree(dev->rawdescriptors);
+	dev->rawdescriptors = NULL;
+bailout2:
+	kfree(dev->config);
+	dev->config = NULL;
+
+	return -ENOMEM;
 }
 
 void usb_release_bos_descriptor(struct usb_device *dev)
Signature · 1 line
2.54.0
author syzbot
#9 lore raw
syzbot tried to test the proposed patch but the build/boot failed:

Hello,

syzbot tried to test the proposed patch but the build/boot failed:

failed to checkout kernel repo git://repo/address.git on commit dd6c438c3e64: failed to run ["git" "fetch" "--force" "--tags" "b7cf8f2fbfc36c709a08e0b9c77990e491473738"]: exit status 128

Tested on:

commit:         [unknown 
git tree:       git://repo/address.git dd6c438c3e64
kernel config:  https://syzkaller.appspot.com/x/.config?x=ac5083db84233db3
dashboard link: https://syzkaller.appspot.com/bug?extid=2afd7e71155c7e241560

compiler:
patch: https://syzkaller.appspot.com/x/patch.diff?x=1575b236580000

#10 lore raw
In reply to Oliver Neukum
Quoted 41 lines · Oliver Neukum

On 25.04.26 04:12, syzbot wrote:

#syz test: git://repo/address.git dd6c438c3e64

From 001175f4d2e1c2ceac98b4af2521fc4d0253d0c8 Mon Sep 17 00:00:00 2001
From: Oliver Neukum <[email protected]>
Date: Mon, 27 Apr 2026 13:35:38 +0200
Subject: [PATCH] usb: core: fix memory of error case in usb_get_configuration

Prior allocations need to be reversed if subsequent allocations fail.

Fixes dd2057e544dc9 ("USB: core: drop OOM message")
Reported-by [email protected]
---
 drivers/usb/core/config.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/usb/core/config.c +2 -2
index 417140b012bb..67475ff81641 100644
@@ -944,11 +944,11 @@ int usb_get_configuration(struct usb_device *dev)
 	length = ncfg * sizeof(char *);
 	dev->rawdescriptors = kzalloc(length, GFP_KERNEL);
 	if (!dev->rawdescriptors)
-		return -ENOMEM;
+		goto bailout2;
 
 	desc = kmalloc(USB_DT_CONFIG_SIZE, GFP_KERNEL);
 	if (!desc)
-		return -ENOMEM;
+		goto bailout;
 
 	for (cfgno = 0; cfgno < ncfg; cfgno++) {
 		/* We grab just the first descriptor so we know how long
@@ -1012,6 +1012,15 @@ int usb_get_configuration(struct usb_device *dev)
 	dev->descriptor.bNumConfigurations = cfgno;
 
 	return result;

drivers/usb/core/config.c int usb_get_configuration(struct usb_device *dev) · line 1024

Quoted 10 lines
drivers/usb/core/config.c +9 -0
+
+bailout:
+	kfree(dev->rawdescriptors);
+	dev->rawdescriptors = NULL;
+bailout2:
+	kfree(dev->config);
+	dev->config = NULL;
+
+	return -ENOMEM;
 }

This is not needed. dev->rawdescriptors and dev->config are deallocated in usb_destroy_configuration(), which gets called when the usb_device structure is released.

The memory leak must have a different cause.

Alan Stern

#11 lore raw
Quoted 5 lines · Alan Stern

This is not needed. dev->rawdescriptors and dev->config are deallocated in usb_destroy_configuration(), which gets called when the usb_device structure is released.

The memory leak must have a different cause.

You are correct. Yet I can see no way for usb_destroy_configuration() to not run. Hence we must be overlooking something.

Regards
Oliver

#12 lore raw
Quoted 11 lines · Oliver Neukum
Quoted 5 lines · Alan Stern

This is not needed. dev->rawdescriptors and dev->config are deallocated in usb_destroy_configuration(), which gets called when the usb_device structure is released.

The memory leak must have a different cause.

You are correct. Yet I can see no way for usb_destroy_configuration() to not run. Hence we must be overlooking something.

Maybe the usb_device structures are not being released at all. For instance, the snd_usb_audio or snd_usb_caiaq driver may forget to drop a reference in an error pathway.

It seems odd that the bug report says there are 5 suspected memory leaks right after 5 devices have disconnected, yet the tracebacks are for different size allocations, implying that they all refer to the same device (i.e., not the same allocation for each of the 5 devices). But it could just be a coincidence.

Alan Stern

#13 lore raw

PATCH 1/1 usb: core: hcd: fix possible deadlock in rh control transfers

In reply to syzbot

From within the SCSI error handler memory allocations must not trigger IO. Handling errors in UAS and the storage driver may involve resetting a device. The thread doing the reset itself relies on VM magic. However, that is insufficient, as resetting a device involves resuming it. Resumption as well as resetting involves conrol transfers to the parent of the device to be reset. That may be a root hub. Hence usbcore must heed the flags passed to usb_submit_urb() processing control transfers to root hubs.

The problem exist since the storage driver has been merged.

---
 drivers/usb/core/hcd.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/usb/core/hcd.c +8 -6
index 89221f1ce769..29c74ed40526 100644
@@ -448,7 +448,8 @@ rh_string(int id, struct usb_hcd const *hcd, u8 *data, unsigned len)
 
 
 /* Root hub control transfers execute synchronously */
-static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
+static int rh_call_control(struct usb_hcd *hcd,
+		struct urb *urb, gfp_t mem_flags)
 {
 	struct usb_ctrlrequest *cmd;
 	u16		typeReq, wValue, wIndex, wLength;
@@ -483,8 +484,8 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
 	 * tbuf should be at least as big as the
 	 * USB hub descriptor.
 	 */
-	tbuf_size =  max_t(u16, sizeof(struct usb_hub_descriptor), wLength);
-	tbuf = kzalloc(tbuf_size, GFP_KERNEL);
+	tbuf_size = max_t(u16, sizeof(struct usb_hub_descriptor), wLength);
+	tbuf = kzalloc(tbuf_size, mem_flags);
 	if (!tbuf) {
 		status = -ENOMEM;
 		goto err_alloc;
@@ -809,12 +810,13 @@ static int rh_queue_status (struct usb_hcd *hcd, struct urb *urb)
 	return retval;
 }
 
-static int rh_urb_enqueue (struct usb_hcd *hcd, struct urb *urb)
+static int rh_urb_enqueue(struct usb_hcd *hcd,
+		struct urb *urb, gfp_t mem_flags)
 {
 	if (usb_endpoint_xfer_int(&urb->ep->desc))
 		return rh_queue_status (hcd, urb);
 	if (usb_endpoint_xfer_control(&urb->ep->desc))
-		return rh_call_control (hcd, urb);
+		return rh_call_control(hcd, urb, mem_flags);
 	return -EINVAL;
 }
 
@@ -1535,7 +1537,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
 	 */
 
 	if (is_root_hub(urb->dev)) {
-		status = rh_urb_enqueue(hcd, urb);
+		status = rh_urb_enqueue(hcd, urb, mem_flags);
 	} else {
 		status = map_urb_for_dma(hcd, urb, mem_flags);
 		if (likely(status == 0)) {
Signature · 1 line
2.54.0
#14 lore raw

Re: [PATCH] usb: core: hcd: fix possible deadlock in rh control transfers

Quoted 8 lines · Oliver Neukum

From within the SCSI error handler memory allocations must not trigger IO. Handling errors in UAS and the storage driver may involve resetting a device. The thread doing the reset itself relies on VM magic. However, that is insufficient, as resetting a device involves resuming it. Resumption as well as resetting involves conrol transfers to the parent of the device to be reset. That may be a root hub. Hence usbcore must heed the flags passed to usb_submit_urb() processing control transfers to root hubs.

The SCSI core prevents devices from suspending while they are in use. If the error handler wants to do a reset (or if a USB transfer fails and the driver does a reset to recover), the device won't be in runtime suspend at the time, and so neither will its root hub.

Besides, even if a resume was necessary, wouldn't the same VM magic that works for the reset thread also work for the resume? After all, they will be the same thread; the usb_autoresume_device() call in usb_reset_device() is synchronous and it is called after memalloc_noio_save().

Alan Stern

#15 lore raw

Re: [PATCH] usb: core: hcd: fix possible deadlock in rh control transfers

Quoted 2 lines · Alan Stern

Besides, even if a resume was necessary, wouldn't the same VM magic that works for the reset thread also work for the resume? After all, they

They need not be the same thread. That is the point. usb_reset_device() does a resume. However, it is possible for this to race with another thread doing a resume or a suspend. In that case it will block and wait for another thread. Hence we essentially get priority inversion more or less.

Regards
Oliver

#16 lore raw

Re: [PATCH] usb: core: hcd: fix possible deadlock in rh control transfers

Quoted 10 lines · Oliver Neukum
Quoted 2 lines · Alan Stern

Besides, even if a resume was necessary, wouldn't the same VM magic that works for the reset thread also work for the resume? After all, they

They need not be the same thread. That is the point. usb_reset_device() does a resume. However, it is possible for this to race with another thread doing a resume or a suspend. In that case it will block and wait for another thread. Hence we essentially get priority inversion more or less.

Okay, I see. Good point. You should include this in the patch description.

Alan Stern

#17 lore raw

PATCH 1/1 sound: usb: caiaq: fix reference leak in probe error

In reply to syzbot

If probing a device fails early a reference to a device is leaked.

---
 sound/usb/caiaq/device.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)
sound/usb/caiaq/device.c +17 -4
index 8af0c04041ee..1a9ddbdc2cd1 100644
@@ -442,7 +442,8 @@ static int init_card(struct snd_usb_caiaqdev *cdev)
 
 	if (usb_set_interface(usb_dev, 0, 1) != 0) {
 		dev_err(dev, "can't set alt interface.\n");
-		return -EIO;
+		err = -EIO;
+		goto dev_err_put;
 	}
 
 	usb_init_urb(&cdev->ep1_in_urb);
@@ -462,14 +463,18 @@ static int init_card(struct snd_usb_caiaqdev *cdev)
 	if (usb_urb_ep_type_check(&cdev->ep1_in_urb) ||
 	    usb_urb_ep_type_check(&cdev->midi_out_urb)) {
 		dev_err(dev, "invalid EPs\n");
-		return -EINVAL;
+		err = -EINVAL;
+		goto dev_err_put;
 	}
 
 	init_waitqueue_head(&cdev->ep1_wait_queue);
 	init_waitqueue_head(&cdev->prepare_wait_queue);
 
-	if (usb_submit_urb(&cdev->ep1_in_urb, GFP_KERNEL) != 0)
-		return -EIO;
+	if (usb_submit_urb(&cdev->ep1_in_urb, GFP_KERNEL) != 0) {
+		err = -EIO;
+		goto dev_err_put;
+	}
+
 
 	err = snd_usb_caiaq_send_command(cdev, EP1_CMD_GET_DEVICE_INFO, NULL, 0);
 	if (err)
@@ -520,6 +525,14 @@ static int init_card(struct snd_usb_caiaqdev *cdev)
 
  err_kill_urb:
 	usb_kill_urb(&cdev->ep1_in_urb);
+
+	/*
+ 	 * private_free has not been set.
+	 * Undoing the usb_get_dev() from
+	 * create_card()
+	 */
+ err_dev_put:
+	usb_put_dev(usb_dev);
 	return err;
 }
 
Signature · 1 line
2.54.0
#18 lore raw

Re: [PATCH] sound: usb: caiaq: fix reference leak in probe error

Quoted 5 lines · Oliver Neukum

If probing a device fails early a reference to a device is leaked.

Thanks, but I believe it's been already fixed in my tree for 7.1-rc2:
7a5f1cd22d47f8ca4b760b6334378ae42c1bd24b
ALSA: caiaq: fix usb_dev refcount leak on probe failure

Also, there are a couple of fixes for caiaq queued for 7.1-rc2, too.

Takashi

Quoted 58 lines
---
 sound/usb/caiaq/device.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)
sound/usb/caiaq/device.c +17 -4
index 8af0c04041ee..1a9ddbdc2cd1 100644
@@ -442,7 +442,8 @@ static int init_card(struct snd_usb_caiaqdev *cdev)
 
 	if (usb_set_interface(usb_dev, 0, 1) != 0) {
 		dev_err(dev, "can't set alt interface.\n");
-		return -EIO;
+		err = -EIO;
+		goto dev_err_put;
 	}
 
 	usb_init_urb(&cdev->ep1_in_urb);
@@ -462,14 +463,18 @@ static int init_card(struct snd_usb_caiaqdev *cdev)
 	if (usb_urb_ep_type_check(&cdev->ep1_in_urb) ||
 	    usb_urb_ep_type_check(&cdev->midi_out_urb)) {
 		dev_err(dev, "invalid EPs\n");
-		return -EINVAL;
+		err = -EINVAL;
+		goto dev_err_put;
 	}
 
 	init_waitqueue_head(&cdev->ep1_wait_queue);
 	init_waitqueue_head(&cdev->prepare_wait_queue);
 
-	if (usb_submit_urb(&cdev->ep1_in_urb, GFP_KERNEL) != 0)
-		return -EIO;
+	if (usb_submit_urb(&cdev->ep1_in_urb, GFP_KERNEL) != 0) {
+		err = -EIO;
+		goto dev_err_put;
+	}
+
 
 	err = snd_usb_caiaq_send_command(cdev, EP1_CMD_GET_DEVICE_INFO, NULL, 0);
 	if (err)
@@ -520,6 +525,14 @@ static int init_card(struct snd_usb_caiaqdev *cdev)
 
  err_kill_urb:
 	usb_kill_urb(&cdev->ep1_in_urb);
+
+	/*
+ 	 * private_free has not been set.
+	 * Undoing the usb_get_dev() from
+	 * create_card()
+	 */
+ err_dev_put:
+	usb_put_dev(usb_dev);
 	return err;
 }
 
Signature · 1 line
2.54.0
#19 lore raw

Re: [PATCH] sound: usb: caiaq: fix reference leak in probe error

Quoted 6 lines · Takashi Iwai
Quoted 4 lines · Oliver Neukum

If probing a device fails early a reference to a device is leaked.

Quoted 7 lines
Quoted 1 line

Thanks, but I believe it's been already fixed in my tree for 7.1-rc2:
7a5f1cd22d47f8ca4b760b6334378ae42c1bd24b
ALSA: caiaq: fix usb_dev refcount leak on probe failure

Also, there are a couple of fixes for caiaq queued for 7.1-rc2, too.

Very good. Such things happen.

Regards
Oliver

#20 lore raw

Re: [PATCH] sound: usb: caiaq: fix reference leak in probe error

In reply to Oliver Neukum
kernel test robot noticed the following build errors:

Hi Oliver,

kernel test robot noticed the following build errors:

[auto build test ERROR on tiwai-sound/for-next]
[also build test ERROR on tiwai-sound/for-linus usb/usb-testing usb/usb-next usb/usb-linus westeri-thunderbolt/next peter-chen-usb/for-usb-next linus/master v7.1-rc1 next-20260429] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Oliver-Neukum/sound-usb-caiaq-fix-reference-leak-in-probe-error/20260429-205539
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next
patch link:    https://lore.kernel.org/r/20260429104527.19927-1-oneukum%40suse.com
patch subject: [PATCH] sound: usb: caiaq: fix reference leak in probe error
config: x86_64-rhel-9.4 (https://download.01.org/0day-ci/archive/20260429/[email protected]/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260429/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All error/warnings (new ones prefixed by >>):

sound/usb/caiaq/device.c: In function 'init_card':

>> sound/usb/caiaq/device.c:534:2: warning: label 'err_dev_put' defined but not used [-Wunused-label]
     534 |  err_dev_put:
         |  ^~~~~~~~~~~
>> sound/usb/caiaq/device.c:475:17: error: label 'dev_err_put' used but not defined
     475 |                 goto dev_err_put;
         |                 ^~~~

vim +/dev_err_put +475 sound/usb/caiaq/device.c

434
435 static int init_card(struct snd_usb_caiaqdev *cdev)
436 {
437 char *c, usbpath[32];
438 struct usb_device *usb_dev = cdev->chip.dev;
439 struct snd_card *card = cdev->chip.card;
440 struct device *dev = caiaqdev_to_dev(cdev);
441 int err, len;
442
443 if (usb_set_interface(usb_dev, 0, 1) != 0) {
444 dev_err(dev, "can't set alt interface.\n");
445 err = -EIO;
446 goto dev_err_put;
447 }
448
449 usb_init_urb(&cdev->ep1_in_urb);
450 usb_init_urb(&cdev->midi_out_urb);
451
452 usb_fill_bulk_urb(&cdev->ep1_in_urb, usb_dev,

   453				  usb_rcvbulkpipe(usb_dev, 0x1),
   454				  cdev->ep1_in_buf, EP1_BUFSIZE,
   455				  usb_ep1_command_reply_dispatch, cdev);
   456	
   457		usb_fill_bulk_urb(&cdev->midi_out_urb, usb_dev,
   458				  usb_sndbulkpipe(usb_dev, 0x1),
   459				  cdev->midi_out_buf, EP1_BUFSIZE,
   460				  snd_usb_caiaq_midi_output_done, cdev);
   461	
   462		/* sanity checks of EPs before actually submitting */
   463		if (usb_urb_ep_type_check(&cdev->ep1_in_urb) ||
   464		    usb_urb_ep_type_check(&cdev->midi_out_urb)) {
   465			dev_err(dev, "invalid EPs\n");
   466			err = -EINVAL;
   467			goto dev_err_put;
   468		}
   469	
   470		init_waitqueue_head(&cdev->ep1_wait_queue);
   471		init_waitqueue_head(&cdev->prepare_wait_queue);
   472	
   473		if (usb_submit_urb(&cdev->ep1_in_urb, GFP_KERNEL) != 0) {
   474			err = -EIO;
 > 475			goto dev_err_put;
   476		}
   477	
   478	
   479		err = snd_usb_caiaq_send_command(cdev, EP1_CMD_GET_DEVICE_INFO, NULL, 0);
   480		if (err)
   481			goto err_kill_urb;
   482	
   483		if (!wait_event_timeout(cdev->ep1_wait_queue, cdev->spec_received, HZ)) {
   484			err = -ENODEV;
   485			goto err_kill_urb;
   486		}
   487	
   488		usb_string(usb_dev, usb_dev->descriptor.iManufacturer,
   489			   cdev->vendor_name, CAIAQ_USB_STR_LEN);
   490	
   491		usb_string(usb_dev, usb_dev->descriptor.iProduct,
   492			   cdev->product_name, CAIAQ_USB_STR_LEN);
   493	
   494		strscpy(card->driver, MODNAME, sizeof(card->driver));
   495		strscpy(card->shortname, cdev->product_name, sizeof(card->shortname));
   496		strscpy(card->mixername, cdev->product_name, sizeof(card->mixername));
   497	
   498		/* if the id was not passed as module option, fill it with a shortened
   499		 * version of the product string which does not contain any
   500		 * whitespaces */
   501	
   502		if (*card->id == '\0') {
   503			char id[sizeof(card->id)];
   504	
   505			memset(id, 0, sizeof(id));
   506	
   507			for (c = card->shortname, len = 0;
   508				*c && len < sizeof(card->id) - 1; c++)
   509				if (*c != ' ')
   510					id[len++] = *c;
   511	
   512			snd_card_set_id(card, id);
   513		}
   514	
   515		usb_make_path(usb_dev, usbpath, sizeof(usbpath));
   516		scnprintf(card->longname, sizeof(card->longname), "%s %s (%s)",
   517			       cdev->vendor_name, cdev->product_name, usbpath);
   518	
   519		card->private_free = card_free;
   520		err = setup_card(cdev);
   521		if (err < 0)
   522			return err;
   523	
   524		return 0;
   525	
   526	 err_kill_urb:
   527		usb_kill_urb(&cdev->ep1_in_urb);
   528	
   529		/*
   530	 	 * private_free has not been set.
   531		 * Undoing the usb_get_dev() from
   532		 * create_card()
   533		 */
 > 534	 err_dev_put:

535 usb_put_dev(usb_dev);
536 return err;
537 }
538

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#21 lore raw

Re: [PATCH] sound: usb: caiaq: fix reference leak in probe error

In reply to Oliver Neukum
kernel test robot noticed the following build errors:

Hi Oliver,

kernel test robot noticed the following build errors:

[auto build test ERROR on tiwai-sound/for-next]
[also build test ERROR on tiwai-sound/for-linus usb/usb-testing usb/usb-next usb/usb-linus westeri-thunderbolt/next peter-chen-usb/for-usb-next linus/master v7.1-rc1 next-20260429] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Oliver-Neukum/sound-usb-caiaq-fix-reference-leak-in-probe-error/20260429-205539
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next
patch link:    https://lore.kernel.org/r/20260429104527.19927-1-oneukum%40suse.com
patch subject: [PATCH] sound: usb: caiaq: fix reference leak in probe error
config: m68k-allmodconfig (https://download.01.org/0day-ci/archive/20260430/[email protected]/config)
compiler: m68k-linux-gcc (GCC) 15.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260430/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All error/warnings (new ones prefixed by >>):

sound/usb/caiaq/device.c: In function 'init_card':

>> sound/usb/caiaq/device.c:534:2: warning: label 'err_dev_put' defined but not used [-Wunused-label]
     534 |  err_dev_put:
         |  ^~~~~~~~~~~
>> sound/usb/caiaq/device.c:475:17: error: label 'dev_err_put' used but not defined
     475 |                 goto dev_err_put;
         |                 ^~~~

vim +/dev_err_put +475 sound/usb/caiaq/device.c

434
435 static int init_card(struct snd_usb_caiaqdev *cdev)
436 {
437 char *c, usbpath[32];
438 struct usb_device *usb_dev = cdev->chip.dev;
439 struct snd_card *card = cdev->chip.card;
440 struct device *dev = caiaqdev_to_dev(cdev);
441 int err, len;
442
443 if (usb_set_interface(usb_dev, 0, 1) != 0) {
444 dev_err(dev, "can't set alt interface.\n");
445 err = -EIO;
446 goto dev_err_put;
447 }
448
449 usb_init_urb(&cdev->ep1_in_urb);
450 usb_init_urb(&cdev->midi_out_urb);
451
452 usb_fill_bulk_urb(&cdev->ep1_in_urb, usb_dev,

   453				  usb_rcvbulkpipe(usb_dev, 0x1),
   454				  cdev->ep1_in_buf, EP1_BUFSIZE,
   455				  usb_ep1_command_reply_dispatch, cdev);
   456	
   457		usb_fill_bulk_urb(&cdev->midi_out_urb, usb_dev,
   458				  usb_sndbulkpipe(usb_dev, 0x1),
   459				  cdev->midi_out_buf, EP1_BUFSIZE,
   460				  snd_usb_caiaq_midi_output_done, cdev);
   461	
   462		/* sanity checks of EPs before actually submitting */
   463		if (usb_urb_ep_type_check(&cdev->ep1_in_urb) ||
   464		    usb_urb_ep_type_check(&cdev->midi_out_urb)) {
   465			dev_err(dev, "invalid EPs\n");
   466			err = -EINVAL;
   467			goto dev_err_put;
   468		}
   469	
   470		init_waitqueue_head(&cdev->ep1_wait_queue);
   471		init_waitqueue_head(&cdev->prepare_wait_queue);
   472	
   473		if (usb_submit_urb(&cdev->ep1_in_urb, GFP_KERNEL) != 0) {
   474			err = -EIO;
 > 475			goto dev_err_put;
   476		}
   477	
   478	
   479		err = snd_usb_caiaq_send_command(cdev, EP1_CMD_GET_DEVICE_INFO, NULL, 0);
   480		if (err)
   481			goto err_kill_urb;
   482	
   483		if (!wait_event_timeout(cdev->ep1_wait_queue, cdev->spec_received, HZ)) {
   484			err = -ENODEV;
   485			goto err_kill_urb;
   486		}
   487	
   488		usb_string(usb_dev, usb_dev->descriptor.iManufacturer,
   489			   cdev->vendor_name, CAIAQ_USB_STR_LEN);
   490	
   491		usb_string(usb_dev, usb_dev->descriptor.iProduct,
   492			   cdev->product_name, CAIAQ_USB_STR_LEN);
   493	
   494		strscpy(card->driver, MODNAME, sizeof(card->driver));
   495		strscpy(card->shortname, cdev->product_name, sizeof(card->shortname));
   496		strscpy(card->mixername, cdev->product_name, sizeof(card->mixername));
   497	
   498		/* if the id was not passed as module option, fill it with a shortened
   499		 * version of the product string which does not contain any
   500		 * whitespaces */
   501	
   502		if (*card->id == '\0') {
   503			char id[sizeof(card->id)];
   504	
   505			memset(id, 0, sizeof(id));
   506	
   507			for (c = card->shortname, len = 0;
   508				*c && len < sizeof(card->id) - 1; c++)
   509				if (*c != ' ')
   510					id[len++] = *c;
   511	
   512			snd_card_set_id(card, id);
   513		}
   514	
   515		usb_make_path(usb_dev, usbpath, sizeof(usbpath));
   516		scnprintf(card->longname, sizeof(card->longname), "%s %s (%s)",
   517			       cdev->vendor_name, cdev->product_name, usbpath);
   518	
   519		card->private_free = card_free;
   520		err = setup_card(cdev);
   521		if (err < 0)
   522			return err;
   523	
   524		return 0;
   525	
   526	 err_kill_urb:
   527		usb_kill_urb(&cdev->ep1_in_urb);
   528	
   529		/*
   530	 	 * private_free has not been set.
   531		 * Undoing the usb_get_dev() from
   532		 * create_card()
   533		 */
 > 534	 err_dev_put:

535 usb_put_dev(usb_dev);
536 return err;
537 }
538

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#22 lore raw

Re: [PATCH] sound: usb: caiaq: fix reference leak in probe error

In reply to Oliver Neukum
kernel test robot noticed the following build errors:

Hi Oliver,

kernel test robot noticed the following build errors:

[auto build test ERROR on tiwai-sound/for-next]
[also build test ERROR on tiwai-sound/for-linus usb/usb-testing usb/usb-next usb/usb-linus westeri-thunderbolt/next peter-chen-usb/for-usb-next linus/master v7.1-rc1 next-20260429] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Oliver-Neukum/sound-usb-caiaq-fix-reference-leak-in-probe-error/20260429-205539
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next
patch link:    https://lore.kernel.org/r/20260429104527.19927-1-oneukum%40suse.com
patch subject: [PATCH] sound: usb: caiaq: fix reference leak in probe error
config: x86_64-rhel-9.4-rust (https://download.01.org/0day-ci/archive/20260430/[email protected]/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
rustc: rustc 1.88.0 (6b00bc388 2025-06-23)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260430/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All error/warnings (new ones prefixed by >>):

>> sound/usb/caiaq/device.c:446:8: error: use of undeclared label 'dev_err_put'
     446 |                 goto dev_err_put;
         |                      ^
>> sound/usb/caiaq/device.c:534:2: warning: unused label 'err_dev_put' [-Wunused-label]
     534 |  err_dev_put:
         |  ^~~~~~~~~~~~

1 warning and 1 error generated.

vim +/dev_err_put +446 sound/usb/caiaq/device.c

434
435 static int init_card(struct snd_usb_caiaqdev *cdev)
436 {
437 char *c, usbpath[32];
438 struct usb_device *usb_dev = cdev->chip.dev;
439 struct snd_card *card = cdev->chip.card;
440 struct device *dev = caiaqdev_to_dev(cdev);
441 int err, len;
442
443 if (usb_set_interface(usb_dev, 0, 1) != 0) {
444 dev_err(dev, "can't set alt interface.\n");
445 err = -EIO;

 > 446			goto dev_err_put;
   447		}
   448	
   449		usb_init_urb(&cdev->ep1_in_urb);
   450		usb_init_urb(&cdev->midi_out_urb);
   451	
   452		usb_fill_bulk_urb(&cdev->ep1_in_urb, usb_dev,
   453				  usb_rcvbulkpipe(usb_dev, 0x1),
   454				  cdev->ep1_in_buf, EP1_BUFSIZE,
   455				  usb_ep1_command_reply_dispatch, cdev);
   456	
   457		usb_fill_bulk_urb(&cdev->midi_out_urb, usb_dev,
   458				  usb_sndbulkpipe(usb_dev, 0x1),
   459				  cdev->midi_out_buf, EP1_BUFSIZE,
   460				  snd_usb_caiaq_midi_output_done, cdev);
   461	
   462		/* sanity checks of EPs before actually submitting */
   463		if (usb_urb_ep_type_check(&cdev->ep1_in_urb) ||
   464		    usb_urb_ep_type_check(&cdev->midi_out_urb)) {
   465			dev_err(dev, "invalid EPs\n");
   466			err = -EINVAL;
   467			goto dev_err_put;
   468		}
   469	
   470		init_waitqueue_head(&cdev->ep1_wait_queue);
   471		init_waitqueue_head(&cdev->prepare_wait_queue);
   472	
   473		if (usb_submit_urb(&cdev->ep1_in_urb, GFP_KERNEL) != 0) {
   474			err = -EIO;
   475			goto dev_err_put;
   476		}
   477	
   478	
   479		err = snd_usb_caiaq_send_command(cdev, EP1_CMD_GET_DEVICE_INFO, NULL, 0);
   480		if (err)
   481			goto err_kill_urb;
   482	
   483		if (!wait_event_timeout(cdev->ep1_wait_queue, cdev->spec_received, HZ)) {
   484			err = -ENODEV;
   485			goto err_kill_urb;
   486		}
   487	
   488		usb_string(usb_dev, usb_dev->descriptor.iManufacturer,
   489			   cdev->vendor_name, CAIAQ_USB_STR_LEN);
   490	
   491		usb_string(usb_dev, usb_dev->descriptor.iProduct,
   492			   cdev->product_name, CAIAQ_USB_STR_LEN);
   493	
   494		strscpy(card->driver, MODNAME, sizeof(card->driver));
   495		strscpy(card->shortname, cdev->product_name, sizeof(card->shortname));
   496		strscpy(card->mixername, cdev->product_name, sizeof(card->mixername));
   497	
   498		/* if the id was not passed as module option, fill it with a shortened
   499		 * version of the product string which does not contain any
   500		 * whitespaces */
   501	
   502		if (*card->id == '\0') {
   503			char id[sizeof(card->id)];
   504	
   505			memset(id, 0, sizeof(id));
   506	
   507			for (c = card->shortname, len = 0;
   508				*c && len < sizeof(card->id) - 1; c++)
   509				if (*c != ' ')
   510					id[len++] = *c;
   511	
   512			snd_card_set_id(card, id);
   513		}
   514	
   515		usb_make_path(usb_dev, usbpath, sizeof(usbpath));
   516		scnprintf(card->longname, sizeof(card->longname), "%s %s (%s)",
   517			       cdev->vendor_name, cdev->product_name, usbpath);
   518	
   519		card->private_free = card_free;
   520		err = setup_card(cdev);
   521		if (err < 0)
   522			return err;
   523	
   524		return 0;
   525	
   526	 err_kill_urb:
   527		usb_kill_urb(&cdev->ep1_in_urb);
   528	
   529		/*
   530	 	 * private_free has not been set.
   531		 * Undoing the usb_get_dev() from
   532		 * create_card()
   533		 */
 > 534	 err_dev_put:

535 usb_put_dev(usb_dev);
536 return err;
537 }
538

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki