Skip to content

Commit a263eb1

Browse files
darvellgregkh
authored andcommitted
ALSA: usb-audio: avoid kobject path lookup in DualSense match
commit 7693c0c upstream. The DualSense jack-detection input handler verifies that a matching input device belongs to the same physical controller by building kobject path strings for both the input device and the USB audio device, then comparing the path prefix. This was observed when a weak physical connection caused the controller to rapidly disconnect and reconnect. During that repeated hotplug, snd_dualsense_ih_match() can run while the controller's USB device is being disconnected. kobject_get_path() walks ancestor kobjects and dereferences their names; if the USB device kobject name is no longer valid, this can fault in strlen(): RIP: 0010:strlen+0x10/0x30 Call Trace: kobject_get_path+0x34/0x150 snd_dualsense_ih_match+0x49/0xd0 [snd_usb_audio] input_register_device+0x566/0x6a0 ps_probe+0xb89/0x1590 [hid_playstation] The same ownership check can be done without building kobject path strings. The input device is parented below the HID device, USB interface and USB device, so walking the input device parent chain and comparing against the mixer USB device preserves the check without dereferencing kobject names during disconnect. Fixes: 79d561c ("ALSA: usb-audio: Add mixer quirk for Sony DualSense PS5") Cc: <stable@vger.kernel.org> Assisted-by: Cute:gpt-5.5 Signed-off-by: Darvell Long <contact@darvell.me> Link: https://patch.msgid.link/20260624143723.2986353-1-contact@darvell.me Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 16f14f5 commit a263eb1

1 file changed

Lines changed: 12 additions & 28 deletions

File tree

sound/usb/mixer_quirks.c

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -567,46 +567,30 @@ static bool snd_dualsense_ih_match(struct input_handler *handler,
567567
{
568568
struct dualsense_mixer_elem_info *mei;
569569
struct usb_device *snd_dev;
570-
char *input_dev_path, *usb_dev_path;
571-
size_t usb_dev_path_len;
572-
bool match = false;
570+
struct device *parent;
573571

574572
mei = container_of(handler, struct dualsense_mixer_elem_info, ih);
575573
snd_dev = mei->info.head.mixer->chip->dev;
576574

577-
input_dev_path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL);
578-
if (!input_dev_path) {
579-
dev_warn(&snd_dev->dev, "Failed to get input dev path\n");
580-
return false;
581-
}
582-
583-
usb_dev_path = kobject_get_path(&snd_dev->dev.kobj, GFP_KERNEL);
584-
if (!usb_dev_path) {
585-
dev_warn(&snd_dev->dev, "Failed to get USB dev path\n");
586-
goto free_paths;
587-
}
588-
589575
/*
590576
* Ensure the VID:PID matched input device supposedly owned by the
591577
* hid-playstation driver belongs to the actual hardware handled by
592-
* the current USB audio device, which implies input_dev_path being
593-
* a subpath of usb_dev_path.
578+
* the current USB audio device.
594579
*
595580
* This verification is necessary when there is more than one identical
596581
* controller attached to the host system.
582+
*
583+
* The input device is registered below the HID device, USB interface and
584+
* USB device, so compare the parent chain directly instead of building
585+
* kobject path strings. This avoids dereferencing kobject names while the
586+
* USB device hierarchy is being torn down during disconnect.
597587
*/
598-
usb_dev_path_len = strlen(usb_dev_path);
599-
if (usb_dev_path_len >= strlen(input_dev_path))
600-
goto free_paths;
601-
602-
usb_dev_path[usb_dev_path_len] = '/';
603-
match = !memcmp(input_dev_path, usb_dev_path, usb_dev_path_len + 1);
604-
605-
free_paths:
606-
kfree(input_dev_path);
607-
kfree(usb_dev_path);
588+
for (parent = dev->dev.parent; parent; parent = parent->parent) {
589+
if (parent == &snd_dev->dev)
590+
return true;
591+
}
608592

609-
return match;
593+
return false;
610594
}
611595

612596
static int snd_dualsense_ih_connect(struct input_handler *handler,

0 commit comments

Comments
 (0)