Commit f3c80e76 authored by Takashi Iwai's avatar Takashi Iwai
Browse files

ALSA: 6fire: Cover the whole probe and disconnect calls with register_mutex



In 6fire driver, we protect the concurrent calls against probe and
disconnect with the register_mutex, but it's applied only partially.
Since we handle two global pointers in devices[] and chips[] pairs,
the assignment of the latter can be inconsistent upon concurrent
interface probes, and the refcount handling isn't properly protected
at disconnect, either.

This patch extends the mutex application range to the whole probe and
disconnect functions.  It makes the code safer against potential
concurrent probles and disconnects, while it makes the code easier to
read, too.

Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20260414132218.411013-2-tiwai@suse.de
parent 28abd224
Loading
Loading
Loading
Loading
+17 −19
Original line number Diff line number Diff line
@@ -83,7 +83,7 @@ static int usb6fire_chip_probe(struct usb_interface *intf,
	struct snd_card *card = NULL;

	/* look if we already serve this card and return if so */
	scoped_guard(mutex, &register_mutex) {
	guard(mutex)(&register_mutex);
	for (i = 0; i < SNDRV_CARDS; i++) {
		if (devices[i] == device) {
			if (chips[i])
@@ -98,7 +98,6 @@ static int usb6fire_chip_probe(struct usb_interface *intf,
		return -ENODEV;
	}
	devices[regidx] = device;
	}

	/* check, if firmware is present on device, upload it if not */
	ret = usb6fire_fw_init(intf);
@@ -165,14 +164,13 @@ static void usb6fire_chip_disconnect(struct usb_interface *intf)
	struct sfire_chip *chip;
	struct snd_card *card;

	guard(mutex)(&register_mutex);
	chip = usb_get_intfdata(intf);
	if (chip) { /* if !chip, fw upload has been performed */
		chip->intf_count--;
		if (!chip->intf_count) {
			scoped_guard(mutex, &register_mutex) {
			devices[chip->regidx] = NULL;
			chips[chip->regidx] = NULL;
			}

			/*
			 * Save card pointer before teardown.