]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
ALSA: usb-audio: qcom: Don't allow USB offload path if PCM device is in use
authorWesley Cheng <quic_wcheng@quicinc.com>
Wed, 9 Apr 2025 19:48:02 +0000 (12:48 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 11 Apr 2025 11:02:32 +0000 (13:02 +0200)
Add proper checks and updates to the USB substream once receiving a USB QMI
stream enable request.  If the substream is already in use from the non
offload path, reject the stream enable request.  In addition, update the
USB substream opened parameter when enabling the offload path, so the
non offload path can be blocked.

Signed-off-by: Wesley Cheng <quic_wcheng@quicinc.com>
Acked-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20250409194804.3773260-30-quic_wcheng@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
sound/usb/qcom/qc_audio_offload.c

index 87e74c9493707a61e2f61e80f3c2cd9eb72e75f8..464c5106b420f7f74e9bbc4614e63c083de3dee4 100644 (file)
@@ -1567,12 +1567,17 @@ static void handle_uaudio_stream_req(struct qmi_handle *handle,
                goto response;
        }
 
+       mutex_lock(&chip->mutex);
        if (req_msg->enable) {
-               if (info_idx < 0 || chip->system_suspend) {
+               if (info_idx < 0 || chip->system_suspend || subs->opened) {
                        ret = -EBUSY;
+                       mutex_unlock(&chip->mutex);
+
                        goto response;
                }
+               subs->opened = 1;
        }
+       mutex_unlock(&chip->mutex);
 
        if (req_msg->service_interval_valid) {
                ret = get_data_interval_from_si(subs,
@@ -1594,6 +1599,11 @@ static void handle_uaudio_stream_req(struct qmi_handle *handle,
                if (!ret)
                        ret = prepare_qmi_response(subs, req_msg, &resp,
                                                   info_idx);
+               if (ret < 0) {
+                       mutex_lock(&chip->mutex);
+                       subs->opened = 0;
+                       mutex_unlock(&chip->mutex);
+               }
        } else {
                info = &uadev[pcm_card_num].info[info_idx];
                if (info->data_ep_pipe) {
@@ -1623,6 +1633,9 @@ static void handle_uaudio_stream_req(struct qmi_handle *handle,
                }
 
                disable_audio_stream(subs);
+               mutex_lock(&chip->mutex);
+               subs->opened = 0;
+               mutex_unlock(&chip->mutex);
        }
 
 response: