Skip to contentSkip to conversation

staging: sound: Adjust mutex unlock order

PATCH In review Erick Karanja 2 participants 2 messages Jul 16, 2025 Sound

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 staging: sound: 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.

changes since v1:
- Applied the unlock reordering in other functions with this pattern.

---
 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..a25c5a531690 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(&qdev_mutex);
 	mutex_unlock(&chip->mutex);
+	mutex_unlock(&qdev_mutex);
 }
 
 static struct snd_usb_platform_ops offload_ops = {
Signature · 1 line
2.43.0
#1 lore raw
Quoted 6 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.

Quoted 7 lines

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

changes since v1:
- Applied the unlock reordering in other functions with this pattern.

The code change looks good, but could you resubmit with the proper subject prefix (e.g. "ALSA: usb: qcom:"), and with a Fixes tag?

thanks,

Takashi