On 8/1/2024 1:57 AM, Pierre-Louis Bossart wrote: > > On 8/1/24 03:17, Wesley Cheng wrote: >> 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. > It's a bit weird that the mutual exclusion between the standard path and > the offloaded path is handled at the vendor level. I would think this > needs to be handled in the soc_usb framework, no? > Hmm...I guess that make sense. In the end, the mutual exclusion check would need to either be handled by the vendor USB offload driver, or the USB backend DAI link. I could consider adding another SOC USB API to query for the USB PCM status. If it is open/active, then just return with an error, or maybe just rename the snd_soc_usb_find_format() API to something more generic which checks for parameters and current status before allowing offloading to start (ie snd_soc_check_offload_available()) Thanks Wesley Cheng >> Signed-off-by: Wesley Cheng <quic_wcheng@xxxxxxxxxxx> >> --- >> sound/usb/qcom/qc_audio_offload.c | 15 ++++++++++++++- >> 1 file changed, 14 insertions(+), 1 deletion(-) >> >> diff --git a/sound/usb/qcom/qc_audio_offload.c b/sound/usb/qcom/qc_audio_offload.c >> index 8b0913b7256b..3b46d05f1421 100644 >> --- a/sound/usb/qcom/qc_audio_offload.c >> +++ b/sound/usb/qcom/qc_audio_offload.c >> @@ -1460,12 +1460,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, >> @@ -1487,6 +1492,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) { >> @@ -1510,6 +1520,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: