From patchwork Wed Dec 20 22:45:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 181872 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp65027dyi; Wed, 20 Dec 2023 15:11:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IHfVjJFYmUfTg422XvgRVTBSH7ElZd7GApFEj2mYNRqTOMJRHrPOMxpLxvI2ZWhZKiRejTG X-Received: by 2002:a17:90a:a785:b0:28a:d063:3051 with SMTP id f5-20020a17090aa78500b0028ad0633051mr7582537pjq.92.1703113911429; Wed, 20 Dec 2023 15:11:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703113911; cv=none; d=google.com; s=arc-20160816; b=l6mL3ad/S8sQlXMODfEHNskGB/8GYS4LTqmM5Sw6v5V8L9NIVbUtE+4I/EDt2UVGNT cQFxCi9CXtb9pfobUB/t2QYbi6+jboUpN20xRZ3EfEhv7K47PjEGNn9Ik2Jw+jG8oBJr wIu89hZhHi0CvxOzvPKRfRRiRxqaYfNxDakcjKYUJsd+DeL2vJhDy7AZfaWeyvoSMWuw 8ZwVt6qxV2ZBhTJlEdgauksGO881APareWIr6ET5kZxmBovDZmDqGZbdqWVqKL2xVFYc mlrzXcnprwN5GJfiO4bQQgIlXkUsjJv5qXe3bPu8DvauTWzzp3hHcghE/nT9QeDGT7dy OcJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=W1QR+0ygIJnmHyx39F8bsEZBn4lVbm3UtqAqif9j3C0=; fh=0KzismZj+xI0Z//ZGdqKIH/FO9LtSZM7Yj4P0VtrCz0=; b=C6g1hog1W97fUogPPk6a6egLJDOZFiyouzJ+z6/VBdqwyHzFVTXAFVe5wJ4hSFYzbe tjN8DErytC85/V5t6QP/GcA92qA+3MZzf7ZRDODxswze+I266k7jZUeMp9t7CSdf0qCV RAssTeq1/Dzt0II2XnVspO78rlWbeywlp3dZ6XUiXzkJVUNhIWQQhZKoLf87fg4iWaAD PnIztDOMqsk1wpohfxSuhilXBvznLebGi3dsyZ+ulq/RXi8deL+lcajDLJBEWMRvp4AD sIPvNOwaDOnklaISzoaiOh1PX5/gXL4iIqX29ERNHOntEtesPtKSvxfbhd0D5WNxfv6I jEAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=LquI4XKg; spf=pass (google.com: domain of linux-kernel+bounces-7575-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7575-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id r12-20020a17090aad0c00b0028b4d442624si3835991pjq.184.2023.12.20.15.11.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 15:11:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-7575-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=LquI4XKg; spf=pass (google.com: domain of linux-kernel+bounces-7575-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7575-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id A68BDB275A2 for ; Wed, 20 Dec 2023 23:03:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 14A846E585; Wed, 20 Dec 2023 22:46:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="LquI4XKg" X-Original-To: linux-kernel@vger.kernel.org Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C8904CB28; Wed, 20 Dec 2023 22:46:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 3BKMid37023592; Wed, 20 Dec 2023 22:46:02 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=W1QR+0ygIJnmHyx39F8b sEZBn4lVbm3UtqAqif9j3C0=; b=LquI4XKgwLzj7gs+W5ydv6cBI3/2Mey/KlZ0 ie3BMw1kXOfVIKwXhk+OZVU+SmelLIixG59tZqXBbKezkZaOZFgSHLfOcYliLvtv kUA6J2DErOs3LuOCXbm7U4eNcBaEnkMH6oazIyfoBX6XpxfRvoXjN0ftrstcGgLm AOlbsRttqvLjDK2tVIJKnkxAnlZKA0Fnoa8EqHJ4utprAa262NcipWoQ5zhNaKe8 MxeC8HUBw6df3mm0FhjbvtjWR0WmrlH585Rhhos2iz+mXXJTgAJIr7ZSAYtGT7c1 TryRSuN9324qNeX0joUGltpl0famhkcx0jmgWvBbQvuks5EHFw== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3v3v33a5q0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 20 Dec 2023 22:46:02 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3BKMk1YP031922 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 20 Dec 2023 22:46:01 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Wed, 20 Dec 2023 14:46:00 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v11 24/41] ALSA: usb-audio: Do not allow USB offload path if PCM device is in use Date: Wed, 20 Dec 2023 14:45:27 -0800 Message-ID: <20231220224544.18031-25-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231220224544.18031-1-quic_wcheng@quicinc.com> References: <20231220224544.18031-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: ZTrOKWUqO2ZX-ta1USSPE29rGi3-JdS4 X-Proofpoint-GUID: ZTrOKWUqO2ZX-ta1USSPE29rGi3-JdS4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_01,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 spamscore=0 mlxscore=0 malwarescore=0 mlxlogscore=933 clxscore=1015 priorityscore=1501 adultscore=0 suspectscore=0 lowpriorityscore=0 bulkscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2312200162 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785844373026724666 X-GMAIL-MSGID: 1785844373026724666 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 --- 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 114a7ba34e1d..754c4242f8bc 100644 --- a/sound/usb/qcom/qc_audio_offload.c +++ b/sound/usb/qcom/qc_audio_offload.c @@ -1448,12 +1448,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, @@ -1475,6 +1480,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) { @@ -1498,6 +1508,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: