Skip to contentSkip to conversation

ALSA: usb-audio: qcom: Adjust mutex unlock order

PATCH In review Erick Karanja 3 participants 5 messages Jul 21, 2025 – Jul 22, 2025 Sound

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 ALSA: usb-audio: qcom: Adjust mutex unlock order

The mutexes qdev_mutex and chip->mutex are acquired in that order throughout the driver. To preserve proper lock hierarchy and avoid potential deadlocks, they must be released in the reverse order of acquisition.

This change reorders the unlock sequence to first release chip->mutex followed by qdev_mutex, ensuring consistency with the locking pattern.

Fixes 326bbc348298a ("ALSA: usb-audio: qcom: Introduce QC USB

SND offloading support")

changes since v3:
- Add the correct fixes tag.

---
 sound/usb/qcom/qc_audio_offload.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
sound/usb/qcom/qc_audio_offload.c +3 -3
index 3543b5a53592..711f5612a83a 100644
@@ -825,8 +825,8 @@ static int uaudio_sideband_notifier(struct usb_interface *intf,
 		}
 	}
 
-	mutex_unlock(&qdev_mutex);
 	mutex_unlock(&chip->mutex);
+	mutex_unlock(&qdev_mutex);
 
 	return 0;
 }
@@ -1865,8 +1865,8 @@ static void qc_usb_audio_offload_disconnect(struct snd_usb_audio *chip)
 
 	/* Device has already been cleaned up, or never populated */
 	if (!dev->chip) {
-		mutex_unlock(&qdev_mutex);
 		mutex_unlock(&chip->mutex);
+		mutex_unlock(&qdev_mutex);
 		return;
 	}
 
@@ -1921,8 +1921,8 @@ static void qc_usb_audio_offload_suspend(struct usb_interface *intf,
 
 	uaudio_send_disconnect_ind(chip);
 
+        mutex_unlock(&chip->mutex);
 	mutex_unlock(&qdev_mutex);
-	mutex_unlock(&chip->mutex);
 }
 
 static struct snd_usb_platform_ops offload_ops = {
Signature · 1 line
2.43.0
#1 lore raw

…

Quoted 8 lines

This change reorders the unlock sequence to first release chip->mutex followed by qdev_mutex, ensuring consistency with the locking pattern.

Fixes 326bbc348298a ("ALSA: usb-audio: qcom: Introduce QC USB

SND offloading support")

changes since v3:
- Add the correct fixes tag.

…

Please take another look at patch requirements.

* https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.16-rc6#n94

* https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.16-rc6#n145

* https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.16-rc6#n784

Regards,
Markus

#3 lore raw
In reply to Erick Karanja
Quoted 11 lines · Erick Karanja

The mutexes qdev_mutex and chip->mutex are acquired in that order throughout the driver. To preserve proper lock hierarchy and avoid potential deadlocks, they must be released in the reverse order of acquisition.

This change reorders the unlock sequence to first release chip->mutex followed by qdev_mutex, ensuring consistency with the locking pattern.

Fixes 326bbc348298a ("ALSA: usb-audio: qcom: Introduce QC USB

SND offloading support")

This has to be a single line without folding.

Quoted 33 lines

changes since v3:
- Add the correct fixes tag.

---
 sound/usb/qcom/qc_audio_offload.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
sound/usb/qcom/qc_audio_offload.c +2 -2
index 3543b5a53592..711f5612a83a 100644
@@ -825,8 +825,8 @@ static int uaudio_sideband_notifier(struct usb_interface *intf,
 		}
 	}
 
-	mutex_unlock(&qdev_mutex);
 	mutex_unlock(&chip->mutex);
+	mutex_unlock(&qdev_mutex);
 
 	return 0;
 }
@@ -1865,8 +1865,8 @@ static void qc_usb_audio_offload_disconnect(struct snd_usb_audio *chip)
 
 	/* Device has already been cleaned up, or never populated */
 	if (!dev->chip) {
-		mutex_unlock(&qdev_mutex);
 		mutex_unlock(&chip->mutex);
+		mutex_unlock(&qdev_mutex);
 		return;
 	}
 

sound/usb/qcom/qc_audio_offload.c static void qc_usb_audio_offload_suspend(struct usb_interface *intf, · line 1925

Quoted 6 lines
sound/usb/qcom/qc_audio_offload.c +1 -1
@@ -1921,8 +1921,8 @@ static void qc_usb_audio_offload_suspend(struct usb_interface *intf,
 
 	uaudio_send_disconnect_ind(chip);
 
+        mutex_unlock(&chip->mutex);
 	mutex_unlock(&qdev_mutex);
-	mutex_unlock(&chip->mutex);

The above used spaces instead of tabs, and I corrected in my side. Such a failure could be spotted out by running scripts/checkpatch.pl. At the next time, please run and test it before submissions.

In anyway, I applied the patch now.

thanks,

Takashi

#4 lore raw

…

Quoted 1 line
Quoted 1 line

+++ b/sound/usb/qcom/qc_audio_offload.c

…

Quoted 10 lines
Quoted 10 lines
sound/usb/qcom/qc_audio_offload.c +1 -1
@@ -1865,8 +1865,8 @@ static void qc_usb_audio_offload_disconnect(struct snd_usb_audio *chip)
 
 	/* Device has already been cleaned up, or never populated */
 	if (!dev->chip) {
-		mutex_unlock(&qdev_mutex);
 		mutex_unlock(&chip->mutex);
+		mutex_unlock(&qdev_mutex);
 		return;
 	}
 

…

Quoted 1 line

In anyway, I applied the patch now.

How do you think about to refine this function implementation another bit by using an additional label like “unlock” rather than keeping duplicate source code?

Regards,
Markus