staging: sound: Adjust mutex unlock order
PATCH 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.
--- sound/usb/qcom/qc_audio_offload.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/usb/qcom/qc_audio_offload.c +1 -1
@@ -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 ; }
Signature · 1 line
2.43.0
Quoted 19 lines · Erick Karanja
The mutexes
qdev_mutexandchip->mutexare 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->mutexfollowed byqdev_mutex, ensuring consistency with the locking pattern.Signed-off-by Erick Karanja <[email protected]>--- sound/usb/qcom/qc_audio_offload.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)sound/usb/qcom/qc_audio_offload.c +0
-0
sound/usb/qcom/qc_audio_offload.c static int uaudio_sideband_notifier(struct usb_interface *intf, · line 832
Quoted 9 lines
sound/usb/qcom/qc_audio_offload.c +1
-1@@ -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 ; }
The same pattern is found in qc_usb_audio_offload_disconnect() and qc_usb_audio_offload_suspend(), too.
Care to address there as well?
Maybe it's better to replace with guard stuff, but it should be done by another patch in later kernel releases.
thanks,
Takashi
Quoted 30 lines · Takashi Iwai
Quoted 28 lines · Erick Karanja
The mutexes
qdev_mutexandchip->mutexare 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-
Quoted 1 line
mutex
followed by
qdev_mutex, ensuring consistency with the locking pattern.Signed-off-by Erick Karanja <[email protected]>---
sound/usb/qcom/qc_audio_offload.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)sound/usb/qcom/qc_audio_offload.c +0
-0@@ -825,8 +825,8 @@ static int uaudio_sideband_notifier(struct usb_interface *intf, } }sound/usb/qcom/qc_audio_offload.c +0
-1-mutex_unlock (&qdev_mutex);
mutex_unlock(&chip->mutex);
Quoted 8 lines
Quoted 4 lines
sound/usb/qcom/qc_audio_offload.c +1
-0+mutex_unlock (&qdev_mutex);
return 0;
}The same pattern is found in
qc_usb_audio_offload_disconnect()andqc_usb_audio_offload_suspend(), too.
Care to address there as well?
Yes, working on it.
Quoted 8 lines
Maybe it's better to replace with guard stuff, but it should be done by another patch in later kernel releases.
thanks,
Takashi
Quoted 4 lines · Erick Karanja
The mutexes
qdev_mutexandchip->mutexare 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.
Please explain how the deadlock would happen.
Pavel
Signature · 2 lines
I don't work for Nazis and criminals, and neither should you. Boycott Putin, Trump, and Musk!