From patchwork Wed Apr 24 14:07:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlad Pruteanu X-Patchwork-Id: 13641935 Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2076.outbound.protection.outlook.com [40.107.105.76]) (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 78C9415B986 for ; Wed, 24 Apr 2024 14:08:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.105.76 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713967693; cv=fail; b=RPhVP/N2JbTFqrqlmpphNiOFg5ykHEOKsYyGgWWNaEtmvkJx40PiNjEuI4Zh9ymYnQ4yjsRr/AlCs4HM4PiqfwLjQCPhrky/HEZnYsG7InHyZ+xFCKSPEqw0oEfz2shvbursmjn6lMSWdPBGqvf7AuB0CoZKyulFycq6Lsp0co4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713967693; c=relaxed/simple; bh=JvvG4CU40e3ldfeTSs8j1C5BYI4tHfib12wMV5Svlzg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=eMWLbCLs+UvZwpFf5JiTuSuLngvZRK7xYggbu0bc6cLH8X0ILQyk+LutEm2qRXVpcA8ugH+rnVFmcUWyGnVxS+14jo6xVEqOLyUuN8n+Og8e+CWH5+/QM9DSPQlLM45TT3N/R/b81clyTxihWuejV1+MBLR25+KdjCcbvsd8cX8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b=tAXz4gH4; arc=fail smtp.client-ip=40.107.105.76 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="tAXz4gH4" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AWTS53QuVsb4NpYraIPWIq6dxT33Iq57uFcLVyha8F5vL5XlSjOnuYKI1amf4v1zfon3VyKpvesR6ihOdI7BkrP9X8Uj1G7ihw7sVRbhNAu4BvPkIj3Nttv4aYROJOJtjlzebyGdmMS13dvIoHttKeenUmsxRh7xKgh2NmPOOpNpq2OreSYklOXIOSfbJkkwrialUF5cvXYFaC1mNz+/n5RDcSNnX0gmQ9u/Z/k6q8wh6fLpGRpepaf/lHw0H44W1M22kANzS/Xf+uqXsvLd8mmzw8Y51Jb2IEcdYi9MhCmyVt1hnWCSvUZ3VmO5qkbtAhGSeuKjewwl0J2ls9XD7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ah1qdlhwIRAfKrdXvwMq+RXqgeeS4Ss7tDXnkwt4G3o=; b=oPNTaHrpU22DHkCsA1meaTvWoSyG0wl/32Gog82uqibpDUaTx/C+peCyE46y8I2GvmTDmK8cnWV8reM9NJIJ0zaN+GP4i+HE3PDEIrmoG/+ETsQJMWGruRy9nwd6iFgf6/U34+eHqnR9x/DGSHUSKTrOyTppNGE81IRdEsVemAulVFoDLxhfCBrRg/VSKuClGF/tDTlvpCkL3RXmcUSNIL2p8PL7mSQ3/zmyK6lMkerAW92o501ntyAT9IM7DoEiI2Cxz5fXtyLGJABggGoHnhVg64PPkWwmz2yEBKOAYuOiCkj5ACYPQ0qo9mYLum0HN+J63PqbsxVO3T7aOST4AA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ah1qdlhwIRAfKrdXvwMq+RXqgeeS4Ss7tDXnkwt4G3o=; b=tAXz4gH4elnMrJnzK8L4YkkIBtPkE6u3fAOvcBa5hQ/+pZXBLzH+N0zxN6KYRIgLU4riRSkFTd3RHrUVE8dCl6Bb06bmn+ridws+TLFBRffADm3pcyKMWsUiiwnEnNPBX2URHNuBMlxBjQtluMRdXgmvefyg1Xp72r6MrIcVDHs= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB5384.eurprd04.prod.outlook.com (2603:10a6:20b:2b::17) by DU2PR04MB8582.eurprd04.prod.outlook.com (2603:10a6:10:2d9::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Wed, 24 Apr 2024 14:08:08 +0000 Received: from AM6PR04MB5384.eurprd04.prod.outlook.com ([fe80::ab73:5047:a22:9439]) by AM6PR04MB5384.eurprd04.prod.outlook.com ([fe80::ab73:5047:a22:9439%4]) with mapi id 15.20.7472.044; Wed, 24 Apr 2024 14:08:08 +0000 From: Vlad Pruteanu To: linux-bluetooth@vger.kernel.org Cc: claudia.rosu@nxp.com, mihai-octavian.urzica@nxp.com, silviu.barbulescu@nxp.com, iulia.tanasescu@nxp.com, andrei.istodorescu@nxp.com, luiz.dentz@gmail.com, Vlad Pruteanu Subject: [PATCH BlueZ v2 1/4] bap: Initialize bap_data for scanned device in bap_bcast_probe Date: Wed, 24 Apr 2024 17:07:38 +0300 Message-Id: <20240424140741.73899-2-vlad.pruteanu@nxp.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240424140741.73899-1-vlad.pruteanu@nxp.com> References: <20240424140741.73899-1-vlad.pruteanu@nxp.com> X-ClientProxiedBy: AS4PR09CA0026.eurprd09.prod.outlook.com (2603:10a6:20b:5d4::9) To AM6PR04MB5384.eurprd04.prod.outlook.com (2603:10a6:20b:2b::17) Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB5384:EE_|DU2PR04MB8582:EE_ X-MS-Office365-Filtering-Correlation-Id: c099fa30-8806-4a9b-a4f5-08dc6467f81a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yj1bgMBEpV53qdY7IC51fcNVj1t0NLKXOt/r96AwVAirDzBlJGb+0CkPq6Sse4B0rumQldbzE4ZierRp9wpCzJMp6fJek1T+8AkME56vF5scW9j8reJLEiHWbE1ZBkD2uVJjmo6nCaGhSieDwOoGvj5HQeNewJqwyyRuY3cQFNS6lVgsHg/pHWrP4fIHscFITZ06LiQbNSbS9Q1X+ilRD6bObBD1cRHcwo+k3fim363WR8s2YVfbkQONCPEd4k3Koc2JOSt7+KhxigOWRJFIPhcaYvpH5MvyBneAkAeKsmiD9xVStXG4o6/79rELU0z8ptvDHCekBf7OoQrU0JT73p0u9IFIzkudXDo+tg0GqMAWrYwsCWBJUgvoj510xbWFZXyIlH8ts9xEkwpuJhOWUrjlvR8KhTtqtzW3BMbngcimBBh8NosUAHn0k91sqQr/x9JUYEH5CFhNpDl041OXObjvmp6NV0bZHCPmdYyLHzO3jwpqTEThxuf7sWx4pHGBBcT2/5uaYS1k38BerzAHM41figbxr8oRKr5AsX5XHMpj8SkTxPuzqjOkqt+elsWhYfYf+0ZxXi/ofTTEhyqSSgV6HYNASJQVLsB211bDAfh55lcD4VCOcZAiZ3zynDtiJuMWxVqlDLYDTHaxvoRiI4BWS2UbBx66bLjqYVohs7PxWWe0Hyj/mXXyETlEEZeEtwEbbC7RoQ3XL1BxwW0xyedLZWWR71uh7sdOfxMNZWOAuZ3l8LY7oDgBSnss5OMbPrBztExJJhfn1ow6XAD2EARqNOoJggFRH/+BDyIm15QSEZ5iLnHpFYTkWkAvOHTrQVIwGMbHyA1Vk+EgtvrsVaaNobwji4waqcD+M0PDmbFfstYhvcveQM9UHX1DhRKDBziOclOTVZn/rbQ4wUoixvhUmcZEFIeq/YQ1ld9IHiR/cZxPkPKsIHNMX9jNAQm4LhSGSVRwGwfDoj/cTjdhhGWfuwZq5xc2VA+7BNaoAnPmZQ7x0F0mxLV1C92fyhQb/jxUeIP1uvBjY1UWRS7/M7fF0pohCORJuLsWBeOPyCKFaAxGIuwrfwa0JhOMBa7ro2d2MgazMcosYhdp3o7n9CXrZuKb6rr3OU634QvzG5Vt9MVbBZ+O2Pknco+EThyoEqiWNUSRk8kudIXNDcn6kU708E8qvixm0pTdgm5dejEIROUndGyFL+vPXFPCShAkg3tMr2iJtWh2QETi+96JU0uvIAj2c1h49fUQLx3oA7P2tHxYAWpheA5eW0skO/dgo2t6+sjOQVFFrOWWz2aB41Rj8xwBSW/+29syoUswFDWIILRdppJ7wGI7/WjASaDnEjuXLC8yx3xyaHz/69WM8Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB5384.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(1800799015)(376005)(366007)(52116005)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Dhfp+G7rw2hMODpPi/78Nn5qZsUf3UWLwfFIF3fseGcWLFzaIuaOi61N2h9jRW3OEezwKKYTMCO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b/yIchPy9bR+8i8L76fo6oOfQNcox6ERvXWLM/kF5J8jri+MFc7RICeisEnyqBDFjxiEtNJO3zYdP5dGnESzIava/dX54tO+rBL7Heh7auqzguG61eaWAdFxC9f/eSmT3mBhlgmp5iGbuOMxIWzDx3bNgU3hPA4SnNZBrSBpv4UanfhrIxnt5lBB3+S1p3ozwWm3I6i1qIwMUplfJ/nyHD48rBQH0FrREjt9BYIGDp9+BH5V+//+Jy3J3XFntfyCPrsugunR7S/848mrWNlgEnpnysR45oX1jy4f3Y/nCnRZ3GeLCoLT759O+ZJDtGGAZZMgjDZt645bj4XLGdCVl6nZpP4BXwo1dBpPmPRFNBIfUTZrsdXbxiO8oC/H5ERnioTLpHmZTshuYxQIhLIpWv7BPEIn1QpjVR4l7sTyyT8FK/WOxS7fM/OYr X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c099fa30-8806-4a9b-a4f5-08dc6467f81a X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB5384.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2024 14:08:08.7938 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /E0htAGBbVdaD1qceMRoXPvGUOAOfXykcpEQ8jldWomp5cSUD/A4Zu++DpM3rAR6LpvLvxODcyurozYZaRYDCg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8582 By moving the bap_data initialization for a scanned device to bap_adapter_probe() the adapter field of bap_data will already be set when short_lived_pa_sync is called. When adapter will be changed for bap_adapter, this will help eliminate an additional queue search (in short_lived_pa_sync). --- profiles/audio/bap.c | 62 ++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c index ff6d6d881..9e93906ca 100644 --- a/profiles/audio/bap.c +++ b/profiles/audio/bap.c @@ -2768,43 +2768,13 @@ static void bap_detached(struct bt_bap *bap, void *user_data) static int short_lived_pa_sync(struct bap_bcast_pa_req *req) { struct btd_service *service = req->data.service; - struct btd_device *device = btd_service_get_device(service); - struct btd_adapter *adapter = device_get_adapter(device); - struct btd_gatt_database *database = btd_adapter_get_database(adapter); struct bap_data *data = btd_service_get_user_data(service); GError *err = NULL; - if (data) { + if (data->listen_io) { DBG("Already probed"); return -1; } - data = bap_data_new(device); - data->service = service; - data->adapter = adapter; - data->device = device; - data->bap = bt_bap_new(btd_gatt_database_get_db(database), - btd_gatt_database_get_db(database)); - if (!data->bap) { - error("Unable to create BAP instance"); - free(data); - return -EINVAL; - } - - if (!bt_bap_attach(data->bap, NULL)) { - error("BAP unable to attach"); - return -EINVAL; - } - - bap_data_add(data); - - data->ready_id = bt_bap_ready_register(data->bap, bap_ready, service, - NULL); - data->state_id = bt_bap_state_register(data->bap, bap_state_bcast, - bap_connecting_bcast, data, NULL); - data->pac_id = bt_bap_pac_register(data->bap, pac_added_broadcast, - pac_removed_broadcast, data, NULL); - - bt_bap_set_user_data(data->bap, service); DBG("Create PA sync with this source"); req->in_progress = TRUE; @@ -2925,14 +2895,44 @@ static int bap_bcast_probe(struct btd_service *service) { struct btd_device *device = btd_service_get_device(service); struct btd_adapter *adapter = device_get_adapter(device); + struct btd_gatt_database *database = btd_adapter_get_database(adapter); struct bap_bcast_pa_req *pa_req = new0(struct bap_bcast_pa_req, 1); + struct bap_data *data; if (!btd_adapter_has_exp_feature(adapter, EXP_FEAT_ISO_SOCKET)) { error("BAP requires ISO Socket which is not enabled"); return -ENOTSUP; } + data = bap_data_new(device); + data->service = service; + data->adapter = adapter; + data->device = device; + data->bap = bt_bap_new(btd_gatt_database_get_db(database), + btd_gatt_database_get_db(database)); + if (!data->bap) { + error("Unable to create BAP instance"); + free(data); + return -EINVAL; + } + + if (!bt_bap_attach(data->bap, NULL)) { + error("BAP unable to attach"); + return -EINVAL; + } + + bap_data_add(data); + + data->ready_id = bt_bap_ready_register(data->bap, bap_ready, service, + NULL); + data->state_id = bt_bap_state_register(data->bap, bap_state_bcast, + bap_connecting_bcast, data, NULL); + data->pac_id = bt_bap_pac_register(data->bap, pac_added_broadcast, + pac_removed_broadcast, data, NULL); + + bt_bap_set_user_data(data->bap, service); + /* First time initialize the queue and start the idle timer */ if (bcast_pa_requests == NULL) { bcast_pa_requests = queue_new(); From patchwork Wed Apr 24 14:07:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlad Pruteanu X-Patchwork-Id: 13641936 Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2060.outbound.protection.outlook.com [40.107.105.60]) (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 B2F3515D5A9 for ; Wed, 24 Apr 2024 14:08:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.105.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713967699; cv=fail; b=rZfrqsO/b0mUyxjWXFI50RqHMuK0A+DWIjW74lH9I9XQWpmEzQW+dRtRNOMcPhBgO5Nd1+MQgBAYVd7/l+DUsSv8pceZZ8KFt0Q0x7EcVIT/lh3DvaNc6HdR20Fm8SwiyyHN8gRuYkAHDAKhcSC7SFqn91y+cLF5zW8xSvBn344= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713967699; c=relaxed/simple; bh=VT+0fp2831OFSK4cycQi12UqEOX20k8srZn1wGpCQjU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=XwWhTqtmUKmD1o+ckamaGIGJJ5ka6QGorM+fXBuV6EaOXakpiSeuI1Ua9kBgJi7OUdIj/8NXF3wImEHYgDC5tn+Z7jAIh7IJS0+Qwh/HtSJJceqDQ2n2xofjAxC6r+O+PuTxAKgWDhbB97avkMWlK0EoXz3b40+hIG9a4qssF0o= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b=DjkaVfR0; arc=fail smtp.client-ip=40.107.105.60 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="DjkaVfR0" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PXDLoJBBcEEIg44/xkOq7L8PPHZhuocczSQlqMlj2cRRGMlpMjyKaOwOmnJg876UkW1zDi5SR0PKDpR2/9uyjfq9Bgm1vg5CB+JQONEN8MDvlxjgp7JgZ22tsek7G73wHoahcLuv8XCdcJsF/5aW4eDp6P+miIpCeG5kqKQtUbeoVOjU5BapM8XF9WdmmMfdQyTadv9VcRkxIT0rx74Ol5bsQ+4dR6Z9LCrNsHP0Ffk3qhbWqce5sBrkPgeAFooU4Fb0/dhUTmDmylINjdnhIM4INeOC9nCZBUy9E6qVwrroBiEk3P9tODZ0HIn3RAwzpPYvcrXtXnK1n1GYh1IDdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ZtCB9nZStQlg2zOfCk6e+4CLYGlUEDVCz+gJaZ/HGJI=; b=HP4MUsX1Bd3Pa9XM89CUWvYz3oV+D/VXtlOgqOUtUOvTvjS1btWYzsSletxSpjr0eWjf5k0EvsUhB2XSHrQZ3k2e0sVSmnVczuY5ohGS0z3YfyAD9CxQ5XlywaHbuFSKQojNJrw7amiuC23fROyp0dokiV1mQoUOJIITo+QSQanueD0qY6x12YTB5xtwVeF43QRb31xRBlPqlDqmkRE+BD6pPVXdvGbxexTAvo5Vk6OfdvCeqnyzOPLwME2DN1eEzqIa0+dm+ob38p9fRrc8oKWU8mdOlnCUkyBDhl0mIjD+4AbuTHLVpNesXdlJezjv6XmF2MX3Dg37azGbSJdxMw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZtCB9nZStQlg2zOfCk6e+4CLYGlUEDVCz+gJaZ/HGJI=; b=DjkaVfR0QRJsxhpQQxGBLgefTRCRDPEhkvS8hhKSBSzzpEFInB5pbl1QHqhaqEzhJzUOuTSjZvvUMoxhq4JdOLeA9DK33EaVs0elcwgRRoF26c82LyYcj07AbfBG88T8vHIAlYFZD+hL4DqYhrk+baDPMxUF4DW6HPtZdmVAoW0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB5384.eurprd04.prod.outlook.com (2603:10a6:20b:2b::17) by DU2PR04MB8582.eurprd04.prod.outlook.com (2603:10a6:10:2d9::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Wed, 24 Apr 2024 14:08:13 +0000 Received: from AM6PR04MB5384.eurprd04.prod.outlook.com ([fe80::ab73:5047:a22:9439]) by AM6PR04MB5384.eurprd04.prod.outlook.com ([fe80::ab73:5047:a22:9439%4]) with mapi id 15.20.7472.044; Wed, 24 Apr 2024 14:08:13 +0000 From: Vlad Pruteanu To: linux-bluetooth@vger.kernel.org Cc: claudia.rosu@nxp.com, mihai-octavian.urzica@nxp.com, silviu.barbulescu@nxp.com, iulia.tanasescu@nxp.com, andrei.istodorescu@nxp.com, luiz.dentz@gmail.com, Vlad Pruteanu Subject: [PATCH BlueZ v2 2/4] bap: Replace adapter in bap_data with bap_adapter Date: Wed, 24 Apr 2024 17:07:39 +0300 Message-Id: <20240424140741.73899-3-vlad.pruteanu@nxp.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240424140741.73899-1-vlad.pruteanu@nxp.com> References: <20240424140741.73899-1-vlad.pruteanu@nxp.com> X-ClientProxiedBy: AS4PR09CA0026.eurprd09.prod.outlook.com (2603:10a6:20b:5d4::9) To AM6PR04MB5384.eurprd04.prod.outlook.com (2603:10a6:20b:2b::17) Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB5384:EE_|DU2PR04MB8582:EE_ X-MS-Office365-Filtering-Correlation-Id: 87bde5e4-45e8-4ef3-780e-08dc6467fada X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zpH54ZhK6vLBI6J+QPRSsfj8+3NIZc84vov/tiMpHiR/bQcSsOM10/N454K025uuR1FcxitUfD9RbF13oYvQyCjpFC7t3bk7n8WanYLBQB8us1u1xDpVkW/cidt7l2/nWOS4We2mH3vQGBNZROkSQcw4ZgUiTrEopYHvMrGsH3Qm1WIYNZaxhU+PMaZ3f6T4OdaCOrsirYp/T6pa2Vqw+YJgORtjRqLou6Y0kuFIrEIlEtQcBPn7XwBUYIyGc9j7DkYbdbOYTMbK3h7V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a3Yg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB5384.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(1800799015)(376005)(366007)(52116005)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: j+GY/5WaNv/SfyWQmkVytzBhvwxfh+756GfxbZOTyGO30RbzvNHHfoqVwqTy/aNfLJJpdabgB00f2PZ0JE2qLePF8PeVrUpPGdvzhlwXAb3HXGo0dwwil67dXEbMvXd2v3sf35PC5Z/Nkkw9/Oi+UWAkEqIKuilIUHMcrz7buLDToG/UiIr7LsO2far2f1d3KXV9qXq9cELZLxN5ryw9eESMXkdAUnw/85aTvuA5KgA7dP0r1ZMxQAoTnt5LzjVlUgZuPUVxyK7y5X9LKXzILiIRPsZsse4dCxgqviDT6qe5RC8vMD9+sL0DCYrQxus9QHYy2Yf5T5Di8m+WyPFn8Q/aSYwLuyBJRIV1IuB5kcT5hWaT/qdhUQcwher95JwKwZMKhOMUZz16oqyEpmi1/OWfbaDJjY0593tKEm987C60Ip+Njx3omeHiZnDTjk8CPzIJWRJfPEwEs5+3d4YMOAsPGo8j8DCFj+EEPZjsG5+KOzOxUYY1T721uyKNidmvKFFOhMkDuZxuyE15Itwn2pNDS+L3hkP/gmAGh5vJZ8UAXy8kY/W/No5xHg2msg0XFlzrlDah41MbtVag3I0Q9JAMGXqk0ZxlnWEwPOIbG88/lfaYppNS4YStvqRrDiNPhza6yEcPiWIIJ61vNxh+z7EXXVrDWMGU+f2G62nOJE3RrdNBc4KgD5uB0kuFC7DKqzL8F4/lYJ+13gfL4pmrOuRnXfU0V+RMd9wKi7UjOAVA2+e7ZtfCveqdhn9osj7B16myFVMxWdFb1zMmgWHH5jukrJKIkpfXQ925bLaWiBSTt5O949Bj5HZLlW4gsJqWMMIYMPxyRHrw7GlfJa1NhFlWoUySCMwB02v/qFfpHzBFsd1VHjiuw137RP+WRFN+0vEtXMkKfv4V0qxNvYatUZDmQQNeZCZ7z7u5Sj+N4DvE98nNsydXQWB1XgV0txW9yg+Q1ZW+5V/z2+qdYXQhsqVB6NNLh3JpVLjx18brclOCP6KcmLgPPfOK1KP79/wXxgteunhzXm6e44JbjvNnG96xgk+ZbDOt40j4jJPK3CfHC4sKrmJgoiTBpdf7UdsXVW0Y3kKSlvtv/0yjh15967t7i4wIuZy1vOf5RNXSD9hkufPnED+hP7GBkh1ajpWfvMhyUh+U/2cC3XP2frK5kPpYyZnYBWt9Q4tHwfPEwB4c9pNN1lfTTGN50yU6yzTOSWlj5c3L6ZAEIEqXpq0Lz/4jKdP29SbykDfqwsHV1B27DPFK3aJEsdqS1FRoo0T+I6KYRcnxdXDWgftxELPQxwnhn7f+aHButxMPiIZOlwskQhFIqJVRnZr6eIvfVgUvwKP1A1G8IRcINQrgMLqWh7xK/4U1LwI00OUH/E5M+jCJQPKOeyZioK4UfXzhZQnywXKgk/+mJ17XDtMiO0D9D5ic6c/1edDuuwS5d7ltBue/jsxuos2r6rFXbbJf/thbA12KjLxx9si420ptoLXkW2UQjiykpPi2ZdTDMArZVpd6m4BG22JSoaF5PnZSNAlRNzYuIqASUIX655AFxGzt6qnAKy3Y84uNYn7veQwfn4HYW0aG4AgBX8YIOd6W4d2q X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 87bde5e4-45e8-4ef3-780e-08dc6467fada X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB5384.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2024 14:08:13.4379 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: wfKdWyRvRClpWJaamr9exAQCmvV20Qe8kVF9XBQxlmp4H4nJmJgDtcBC3tG8ZhpSQmr9QCXq4E96s15zx8niZw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8582 This patch introduces the bap_adapter structure. In addition to btd_adapter it also holds the pa_timer_id and the bcast_pa_requests queue associated with that adapter. This enables convenient access to these variables since the functions that need them already utilize bap_data. For each adapter a new instance of bap_adapter is created and inserted into the global queue, bap_adapters. For each scanned source bap_bcast_probe searches the bap_adapters queue based on the adapter and stores the result in the bap_data associated with the source. Operations made on the old global queue are now made on bap_data->bap_adapter->bcast_pa_requests queue. While this commit sought to utilize the already existing bap_data in order to avoid searching in queues, a lookup was still necessary in bap_bcast_probe. Here, the bap_data for the scanned devices is created and the bap_adapter field must be set to the appropriate value. There is no way of getting the correct bap_adapter refference without searching the bap_adapters queue. --- profiles/audio/bap.c | 100 ++++++++++++++++++++++++++++--------------- 1 file changed, 66 insertions(+), 34 deletions(-) diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c index 9e93906ca..d8cd05f26 100644 --- a/profiles/audio/bap.c +++ b/profiles/audio/bap.c @@ -98,9 +98,15 @@ struct bap_ep { struct queue *setups; }; +struct bap_adapter { + struct btd_adapter *adapter; + unsigned int pa_timer_id; + struct queue *bcast_pa_requests; +}; + struct bap_data { struct btd_device *device; - struct btd_adapter *adapter; + struct bap_adapter *bap_adapter; struct btd_service *service; struct bt_bap *bap; unsigned int ready_id; @@ -130,8 +136,7 @@ struct bap_bcast_pa_req { }; static struct queue *sessions; -static struct queue *bcast_pa_requests; -static unsigned int pa_timer_id; +static struct queue *bap_adapters; /* Structure holding the parameters for Periodic Advertisement create sync. * The full QOS is populated at the time the user selects and endpoint and @@ -366,7 +371,7 @@ static gboolean get_device(const GDBusPropertyTable *property, const char *path; if (bt_bap_pac_get_type(ep->lpac) == BT_BAP_BCAST_SOURCE) - path = adapter_get_path(ep->data->adapter); + path = adapter_get_path(ep->data->bap_adapter->adapter); else path = device_get_path(ep->data->device); @@ -993,7 +998,7 @@ static void iso_bcast_confirm_cb(GIOChannel *io, GError *err, void *user_data) DBG("BIG Sync completed"); - queue_remove(bcast_pa_requests, req); + queue_remove(setup->ep->data->bap_adapter->bcast_pa_requests, req); /* This device is no longer needed */ btd_service_connecting_complete(setup->ep->data->service, 0); @@ -1150,8 +1155,8 @@ static void iso_pa_sync_confirm_cb(GIOChannel *io, void *user_data) g_io_channel_unref(data->listen_io); g_io_channel_shutdown(io, TRUE, NULL); data->listen_io = NULL; - queue_remove(bcast_pa_requests, pa_req); - + queue_remove(data->bap_adapter->bcast_pa_requests, pa_req); + free(pa_req); /* Analyze received BASE data and create remote media endpoints for each * BIS matching our capabilities */ @@ -1209,7 +1214,7 @@ static struct bap_ep *ep_register_bcast(struct bap_data *data, struct bt_bap_pac *lpac, struct bt_bap_pac *rpac) { - struct btd_adapter *adapter = data->adapter; + struct btd_adapter *adapter = data->bap_adapter->adapter; struct btd_device *device = data->device; struct bap_ep *ep; struct queue *queue; @@ -2062,14 +2067,15 @@ static void pa_and_big_sync(struct bap_bcast_pa_req *req); static gboolean pa_idle_timer(gpointer user_data) { - struct bap_bcast_pa_req *req = user_data; + struct bap_adapter *bap_adapter = user_data; + struct bap_bcast_pa_req *req; bool in_progress = FALSE; /* Handle timer if no request is in progress */ - queue_foreach(bcast_pa_requests, check_pa_req_in_progress, + queue_foreach(bap_adapter->bcast_pa_requests, check_pa_req_in_progress, &in_progress); if (in_progress == FALSE) { - req = queue_peek_head(bcast_pa_requests); + req = queue_peek_head(bap_adapter->bcast_pa_requests); if (req != NULL) switch (req->type) { case BAP_PA_SHORT_REQ: @@ -2090,6 +2096,7 @@ static void setup_accept_io_broadcast(struct bap_data *data, struct bap_setup *setup) { struct bap_bcast_pa_req *pa_req = new0(struct bap_bcast_pa_req, 1); + struct bap_adapter *bap_adapter = data->bap_adapter; /* Add this request to the PA queue. * We don't need to check the queue here and the timer, as we cannot @@ -2098,7 +2105,7 @@ static void setup_accept_io_broadcast(struct bap_data *data, pa_req->type = BAP_PA_BIG_SYNC_REQ; pa_req->in_progress = FALSE; pa_req->data.setup = setup; - queue_push_tail(bcast_pa_requests, pa_req); + queue_push_tail(bap_adapter->bcast_pa_requests, pa_req); } static void setup_create_ucast_io(struct bap_data *data, @@ -2779,18 +2786,18 @@ static int short_lived_pa_sync(struct bap_bcast_pa_req *req) DBG("Create PA sync with this source"); req->in_progress = TRUE; data->listen_io = bt_io_listen(NULL, iso_pa_sync_confirm_cb, req, - NULL, &err, - BT_IO_OPT_SOURCE_BDADDR, - btd_adapter_get_address(data->adapter), - BT_IO_OPT_SOURCE_TYPE, - btd_adapter_get_address_type(data->adapter), - BT_IO_OPT_DEST_BDADDR, - device_get_address(data->device), - BT_IO_OPT_DEST_TYPE, - btd_device_get_bdaddr_type(data->device), - BT_IO_OPT_MODE, BT_IO_MODE_ISO, - BT_IO_OPT_QOS, &bap_sink_pa_qos, - BT_IO_OPT_INVALID); + NULL, &err, + BT_IO_OPT_SOURCE_BDADDR, + btd_adapter_get_address(data->bap_adapter->adapter), + BT_IO_OPT_SOURCE_TYPE, + btd_adapter_get_address_type(data->bap_adapter->adapter), + BT_IO_OPT_DEST_BDADDR, + device_get_address(data->device), + BT_IO_OPT_DEST_TYPE, + btd_device_get_bdaddr_type(data->device), + BT_IO_OPT_MODE, BT_IO_MODE_ISO, + BT_IO_OPT_QOS, &bap_sink_pa_qos, + BT_IO_OPT_INVALID); if (!data->listen_io) { error("%s", err->message); g_error_free(err); @@ -2877,7 +2884,7 @@ static void pa_and_big_sync(struct bap_bcast_pa_req *req) setup->io = bt_io_listen(NULL, iso_do_big_sync, req, NULL, &err, BT_IO_OPT_SOURCE_BDADDR, - btd_adapter_get_address(data->adapter), + btd_adapter_get_address(data->bap_adapter->adapter), BT_IO_OPT_DEST_BDADDR, device_get_address(data->device), BT_IO_OPT_DEST_TYPE, @@ -2891,11 +2898,20 @@ static void pa_and_big_sync(struct bap_bcast_pa_req *req) } } +static bool match_bap_adapter(const void *data, const void *match_data) +{ + struct bap_adapter *bap_adapter = (struct bap_adapter *)data; + + return bap_adapter->adapter == match_data; +} + static int bap_bcast_probe(struct btd_service *service) { struct btd_device *device = btd_service_get_device(service); struct btd_adapter *adapter = device_get_adapter(device); struct btd_gatt_database *database = btd_adapter_get_database(adapter); + struct bap_adapter *bap_adapter = queue_find(bap_adapters, + match_bap_adapter, adapter); struct bap_bcast_pa_req *pa_req = new0(struct bap_bcast_pa_req, 1); struct bap_data *data; @@ -2907,7 +2923,7 @@ static int bap_bcast_probe(struct btd_service *service) data = bap_data_new(device); data->service = service; - data->adapter = adapter; + data->bap_adapter = bap_adapter; data->device = device; data->bap = bt_bap_new(btd_gatt_database_get_db(database), btd_gatt_database_get_db(database)); @@ -2933,12 +2949,10 @@ static int bap_bcast_probe(struct btd_service *service) bt_bap_set_user_data(data->bap, service); - /* First time initialize the queue and start the idle timer */ - if (bcast_pa_requests == NULL) { - bcast_pa_requests = queue_new(); - pa_timer_id = g_timeout_add_seconds(PA_IDLE_TIMEOUT, - pa_idle_timer, NULL); - } + /* Start the PA timer if it hasn't been started yet */ + if (bap_adapter->pa_timer_id == 0) + bap_adapter->pa_timer_id = g_timeout_add_seconds( + PA_IDLE_TIMEOUT, pa_idle_timer, bap_adapter); /* Enqueue this device advertisement so that we can do short-lived */ @@ -2946,7 +2960,7 @@ static int bap_bcast_probe(struct btd_service *service) pa_req->type = BAP_PA_SHORT_REQ; pa_req->in_progress = FALSE; pa_req->data.service = service; - queue_push_tail(bcast_pa_requests, pa_req); + queue_push_tail(bap_adapter->bcast_pa_requests, pa_req); return 0; } @@ -3067,6 +3081,7 @@ static int bap_adapter_probe(struct btd_profile *p, { struct btd_gatt_database *database = btd_adapter_get_database(adapter); struct bap_data *data; + struct bap_adapter *bap_adapter; char addr[18]; ba2str(btd_adapter_get_address(adapter), addr); @@ -3078,7 +3093,6 @@ static int bap_adapter_probe(struct btd_profile *p, } data = bap_data_new(NULL); - data->adapter = adapter; data->bap = bt_bap_new(btd_gatt_database_get_db(database), btd_gatt_database_get_db(database)); @@ -3102,6 +3116,15 @@ static int bap_adapter_probe(struct btd_profile *p, bt_bap_set_user_data(data->bap, adapter); bap_data_set_user_data(data, adapter); + + bap_adapter = new0(struct bap_adapter, 1); + bap_adapter->adapter = adapter; + data->bap_adapter = bap_adapter; + + if (bap_adapters == NULL) + bap_adapters = queue_new(); + bap_adapter->bcast_pa_requests = queue_new(); + queue_push_tail(bap_adapters, bap_adapter); return 0; } @@ -3115,6 +3138,15 @@ static void bap_adapter_remove(struct btd_profile *p, ba2str(btd_adapter_get_address(adapter), addr); DBG("%s", addr); + queue_destroy(data->bap_adapter->bcast_pa_requests, free); + queue_remove(bap_adapters, data->bap_adapter); + free(data->bap_adapter); + + if (queue_isempty(bap_adapters)) { + queue_destroy(bap_adapters, NULL); + bap_adapters = NULL; + } + if (!data) { error("BAP service not handled by profile"); return; From patchwork Wed Apr 24 14:07:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlad Pruteanu X-Patchwork-Id: 13641937 Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2060.outbound.protection.outlook.com [40.107.105.60]) (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 2DC7A15D5D7 for ; Wed, 24 Apr 2024 14:08:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.105.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713967701; cv=fail; b=LW5ZCkrWN0J9XCaoIU380t1PNj/DbJ2LN8ivGjoguQw68wjNKLL707XuMCap3VpxIIl7Eb36MOgTfwAcyEW21LSDzftr42lAMcWnrQ5kbOCoTYokbPiVoP1IW8UyNEu6msSi6qVBBz1ihgOSbGgdldQI3fAPVfZMoZp+2npGKPc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713967701; c=relaxed/simple; bh=kCZa6rDedY+yOCenEVm1iWfLZdI7umB4Yn8lmk0B5kY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=Nfq8HePCM6HFiem6qUL3HDtpB+NJkbiW1aW0CQU8YhCibrV7OPKm0LEd8ixW+dmsljU4n4fG6g04DU5rgvuhpTrja8mWpnAKcdlHdfGpqj680D9H6WE1ZSNMgwpv/5N+YhyQTk50syHgoAq3UYS12KftM/gjFFCwHhEYZMKdDs8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b=egwWdn/9; arc=fail smtp.client-ip=40.107.105.60 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="egwWdn/9" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QCA5NBHwl6x/G3IIt5Lw8g1mwyiyRXDcnarK5t/crKO36aZED3uWP1l+py64SkqoBqla3Jm79y5bdM93kFv3DRdEu5AFyF2T2UiNoIKPwDtXMGXmvixXBzJY0c0iKEizLRa5zAXzSlKhm74ct1ZDNL4pbGt581tmFIUfqw5t6GuTWcIxMiKEQ5H8+Ap8k4P7KPXFffZ1eoZGhwkLIuh/VLHEl8rP5xyY1dtGWF9pd0BfpYqfDzzKiGoe9yynBQSys3Q2flY/RDNRCnxWMFdzxMY4mG23EgdXYddKEY3DHhwWzNlEBjXpTlfQm7Fs3fyiRFyEAhEbAi/VZ8P1Nu6AYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=j86YT3G3ebyA2k/zqzfN/RCoZwTdaltCqTWIXzuhjDw=; b=hjWGHwdKX9ouer7Fn56p1rCoK12awFwVcO7Kil8vm0SBt2UuSsnZLh9/Ns6TB4P9nzMXTnghz9DgYj/tV8YKfrbtZy3Q/zBYwdJ1MMXTDG9n006BqmpPpp8uj9U99+w4VBe0bqA49yCEsq05TFgVs04DaU0qvyy5nwLEGxb7RGRG9H+2W4T9NxDvNwpHeLZw0AjzYU4MRMPzsbWIRnKbwhYdS/83y9uVZJ28/bOhqlJCNrQ/kJJrA3sc6jaTGtmBzY7ujnZOLXVYoP4w3YFYDqAibbVjUuwpa9YGKPJ/Ttn2iO4jYPQ5yuh7UC3bSj7SBXiaU+sJphL/cRQW/Zr/LQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=j86YT3G3ebyA2k/zqzfN/RCoZwTdaltCqTWIXzuhjDw=; b=egwWdn/9C7McumN6s866/Zwfv9WLTqw0Nli4s9mfFuJOepJBj2nNCiWgWvGyC5O8QepI5qUKTBxZVUdulBYMF3M1j8A160tPoS76VHhXgUcHCupxGK6IEmu8UIGcgh2S6/X6uRYLe4UyZfp8lA/aCWb9ZdFT19iC0/rBt2fVnV0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB5384.eurprd04.prod.outlook.com (2603:10a6:20b:2b::17) by DU2PR04MB8582.eurprd04.prod.outlook.com (2603:10a6:10:2d9::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Wed, 24 Apr 2024 14:08:16 +0000 Received: from AM6PR04MB5384.eurprd04.prod.outlook.com ([fe80::ab73:5047:a22:9439]) by AM6PR04MB5384.eurprd04.prod.outlook.com ([fe80::ab73:5047:a22:9439%4]) with mapi id 15.20.7472.044; Wed, 24 Apr 2024 14:08:16 +0000 From: Vlad Pruteanu To: linux-bluetooth@vger.kernel.org Cc: claudia.rosu@nxp.com, mihai-octavian.urzica@nxp.com, silviu.barbulescu@nxp.com, iulia.tanasescu@nxp.com, andrei.istodorescu@nxp.com, luiz.dentz@gmail.com, Vlad Pruteanu Subject: [PATCH BlueZ v2 3/4] bap: Improve handling of pa_req timer Date: Wed, 24 Apr 2024 17:07:40 +0300 Message-Id: <20240424140741.73899-4-vlad.pruteanu@nxp.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240424140741.73899-1-vlad.pruteanu@nxp.com> References: <20240424140741.73899-1-vlad.pruteanu@nxp.com> X-ClientProxiedBy: AS4PR09CA0026.eurprd09.prod.outlook.com (2603:10a6:20b:5d4::9) To AM6PR04MB5384.eurprd04.prod.outlook.com (2603:10a6:20b:2b::17) Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB5384:EE_|DU2PR04MB8582:EE_ X-MS-Office365-Filtering-Correlation-Id: 929cf3d1-9bd4-40bc-a0cc-08dc6467fc73 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: C1wookv5nCKfKKnRkFGczII6LAmZeosm67/Cubzuffek0kGp8X4Rui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l0FGctsm9H47gwCrU+A58LIax/AWORri1PjpGKk/OXMUcHmLKC7519PXRIlQhEPsOLRX5/xpcLxREEsDBT9xH8X+hP2B1lGWhvqAbaakePyZP/horoRaUcw36auaSYEE1Kit09MBVGc5m1T6xJ81JL+EogLnLtf8/wvssYNNx7nKhWdwdxlEaUpRjhnoyvmIdfV/Rd/13to3aD0o0N26qT6j6g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB5384.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(1800799015)(376005)(366007)(52116005)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: jc54cLoifD6GtifKKo960YvY8r2yivYu+OY1CvnuU0oQj0FlDgzbnHSq1zdbQOXGh3FAD2NDfUkisJvlYhXje3V1zRl6Un8deVRei5OyZ5sMAKsfFi2UCcY+uZklhy2ksDSUhHG3F8z7Q9D1pSm21LQuGt93994qUuPzZIaw1W6XSybJl8D+rodcGq9I94jNLbY/Mx52rAiwdzfL3o+in+uWq9xXBuWO+roZ/GVJLL+DO8JlRwP+13AnWE7YNFfvjzZy1/MN09V/Zb8OFjzzJAvavBgxu1BezelhbrDO5qer3I/vU4ELD/18dGXJkcKdvbfdfl+gK+ETHCadskGZ4a05jjjvQiDTmOf8Fs960FpsTryTUgrlsNOiif54SWaBTq+u6fn+2yDrsjNyPOPknyz71te2s2DpLkY8fpdvRdhtb/qOX/sksHIKnViiw/xm8wW02bzA+/5LwWCMwcpqa4ENjMRSeQ38BNJTmRAoiq39fqG3YzPqH09pzf6LlP9HPabIyvMz0+E3b7JdOJUgg1YSMmyUQHXMxs53tAa8QcpT97FvxG63ZHyh2Pa/KT2djWL1VsgZnNjwNq3nUTPIi63hDRmGK75HCxPgafhWGp2lZlXNi4WbS/z7yttP4pJUjGloFAyIKxha14499z8hpfYZr5n805SbdbvjOWAtql3eLIouTkqVwJdjugxbO/U9Ru2tyEf+jVp1vnIeK4A6dI7OVpt+h235dNb5EzicBt2cKVYz5R92Nex0lfoiW6ZoQnd1vLpNaV5oBeS5UnvcCqrwJLHNxzgp8CitE4Ya9ULMnMRTRTPkI1E/sH4bwqI/o2AE+Xo37wzP+aSgrjdiUGbQhXikAPpX1ysP8410x9rTOhBQenohSGX0KgPHBMvHSnvqeA5R+IqS3cCQHg/72YihMg3Pjh51wwpuPax0H0jgg4S3i7WshLHJV58a6LgYPEK5IPkT/rkZ5Uj1RZzW64fjRhHpYx2IIgYx5U/7nNgxo9v5ZEEXDz8WVb0K4vxLjB6LhK09UDQHfSQNdWW3eU0LKdPUFuMEbNOuw3pG3LAs5/Gd/Vfj3gj8HRJ+eXb0jrmf9cXEVQriitvryK6B/VwbVxpMofy7d4b1eM77ZVz3uNMSS1iT3aMExEyN7HU5rXRTBfi1b3E276MgPvj1bWFzYnMaVi0Zqm8CasZwAahw4C0RIhc+N8WpeuYP+bn+0BFrHiuwyERljZXCDG4Y5eYPZQAcpLj0qdLU2iU81N3U7JpzdCP51xn7wXtIpeuiOffZ7lcVxMFfP+pGmtcPEr8Hgw1765LaGFD2wAR43e9jZbwuhe8dcE17+j15W5ahCneVqUM1Vb/1cB3JZbBeclkpfKDG7bid+poM1EFpAyELm+RPABLyMpj8GDC2ZJdtpISpVGz/Xdgxa/3poUZFJOkqzGQrA8SMcWCgAThnA1tU05tAx93k+/GSShtoMAsdRDZYtkQO0eLm+yGfO390MgUBYEttR7Uu2MTpYIHw+Av9ESj/YiEpwPPOQ1YTAB2+G+8ykawgC5w/+SMxBsVT5GeBt5hOkviuuGONwIzEzkOAfSocaYXa4gzo953d5dsk X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 929cf3d1-9bd4-40bc-a0cc-08dc6467fc73 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB5384.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2024 14:08:16.1334 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: tmYm8PK5cpSfWliSsB+r3IaYXGg5hxhraEboVpRkOYc6hDrxShW4tbnsfxi+cy+jjbufIOvIZLOQWn7n7vl0QA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8582 The patch handles timers on a per adapter basis. The timer is now also started on setup_accept_io_broadcast, so BAP_PA_BIG_SYNC_REQ can be treated if the timer is stopped in the meantime. The timer is stopped if the bap_adapter's pa_req queue is empty. A pa_timer_id equal to 0 means that the timer is stopped. --- profiles/audio/bap.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c index d8cd05f26..ab0b96222 100644 --- a/profiles/audio/bap.c +++ b/profiles/audio/bap.c @@ -2087,6 +2087,14 @@ static gboolean pa_idle_timer(gpointer user_data) pa_and_big_sync(req); break; } + else { + /* pa_req queue is empty, stop the timer by returning + * FALSE and set the pa_timer_id to 0. This will later + * be used to check if the timer is active. + */ + bap_adapter->pa_timer_id = 0; + return FALSE; + } } return TRUE; @@ -2098,9 +2106,17 @@ static void setup_accept_io_broadcast(struct bap_data *data, struct bap_bcast_pa_req *pa_req = new0(struct bap_bcast_pa_req, 1); struct bap_adapter *bap_adapter = data->bap_adapter; + /* Timer could be stopped if all the short lived requests were treated. + * Check the state of the timer and turn it on so that this requests + * can also be treated. + */ + if (bap_adapter->pa_timer_id == 0) + bap_adapter->pa_timer_id = g_timeout_add_seconds( + PA_IDLE_TIMEOUT, pa_idle_timer, bap_adapter); + /* Add this request to the PA queue. - * We don't need to check the queue here and the timer, as we cannot - * have BAP_PA_BIG_SYNC_REQ before a short PA (BAP_PA_SHORT_REQ) + * We don't need to check the queue here, as we cannot have + * BAP_PA_BIG_SYNC_REQ before a short PA (BAP_PA_SHORT_REQ) */ pa_req->type = BAP_PA_BIG_SYNC_REQ; pa_req->in_progress = FALSE; From patchwork Wed Apr 24 14:07:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlad Pruteanu X-Patchwork-Id: 13641938 Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2060.outbound.protection.outlook.com [40.107.105.60]) (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 323A615E1EA for ; Wed, 24 Apr 2024 14:08:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.105.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713967704; cv=fail; b=kFMw06omgHxMIuNCJgTczlDPlY6o/CKXR1tY8cplKcjX3bWqg7KjN2L8iTDEeqx/VMLrguyKKWBNmdedVx5RENTs8Ol3/6gGWdVxwkqxRPaURjLl/bJHXVQzlILqkibZoRG3bbq8cW+bhQy+e3ux3kUL4gJsvH4jm0PfxPHevaI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713967704; c=relaxed/simple; bh=H6l6yphTpbBr1Cy3bMU3zlxBSN2pI5Psj62hi0RwWuI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=KHStgpqyQmvdnGJzZgyt/Q6Fv9axljkxGlVcuDF8IsbSXZaRvU7nkaGnDdbp8yMGvBo4tExfKcERmWUO31GsaHLxKq5eqTkikcElcdskiutTsH+rW7v8F7CRF4s0XlqcuaOuzosY4p2HvAtncaH5ovP4TnTwc/qE7q75t8gRiYY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b=oqbgWqcO; arc=fail smtp.client-ip=40.107.105.60 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="oqbgWqcO" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Sva3kkBaxuFvCMiWjoDqyNaMFmVH+pHfwLoec0UWhCs4Wp6024Qz1b3sTmu9335M2s1Js4qH5rp5o88nr5FuilXrpNt92av6HMD4syjlLlGC6j9ireitVxgQbrA7GOSfUwpMJuGO4AbOoVSbyMK8icTCuIFwzy80qmGiYqUaGu8QHrIr5GxY6/WJHg7An0cO+6SKOYvhX2ob6FijMI+PCEqX62z6maMoW2iViTmShWO3SvB6MpKqz04E2eiPcliVfxRumy1s5e1RJGn+fJ8W6ThB/uiIWJ7BOEWqr/ExtyXv5cZUNilCtzrYEqwi0/e5w/4UkCXqIaA2RxRL0tf8ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lH+3gCTsxHN2VZwc3IucOef1nAfRk3hkcBArv6SwSno=; b=jriCj5HeJK1yerddhdHLi2XCBkFBkFH4uamYYFJYh/Ff2Ju0JSrQfzqjYVMfFkZHw5Za1Kp2Z7lvyObfC9i6CBZuxwHEZwXqPlr31APmfrJI4l45cfuJ6cJfz0SIH4SSf7MnjTED23nfD8nurkCMeWks9gsV6OKhVQsf1Cz2l6dO24TfykzRmUIrGFsFlt+gu1I4Ns+J2jI7xv/xsf0KgG6BqSDQvBS698t0etDUTkIL34lX+/9Rccf2qfiIaZcqEw9IfqG4me4ECMt8g5ZYqVzi1ZYryBeHRg+qgA1yvePB6yxc5P/yYj+U05zPTN9KYJ7hbHbHaONbo0o7TrbXIA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lH+3gCTsxHN2VZwc3IucOef1nAfRk3hkcBArv6SwSno=; b=oqbgWqcOtkT0ossnR8xFCfOl8hpgCkAGv4091hVXdn0XdHwueUwnJSi1TDn4GCtXs3+xdVD0Oq0WfVmUekooWD15rUlxN+5BxIY8Um/ykPaA/qkNRKUJGsVJZlhHxC3B94Nxg/998CZCerYgPghKaLaGvH44qxGRNnt3H26oK/0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB5384.eurprd04.prod.outlook.com (2603:10a6:20b:2b::17) by DU2PR04MB8582.eurprd04.prod.outlook.com (2603:10a6:10:2d9::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Wed, 24 Apr 2024 14:08:18 +0000 Received: from AM6PR04MB5384.eurprd04.prod.outlook.com ([fe80::ab73:5047:a22:9439]) by AM6PR04MB5384.eurprd04.prod.outlook.com ([fe80::ab73:5047:a22:9439%4]) with mapi id 15.20.7472.044; Wed, 24 Apr 2024 14:08:18 +0000 From: Vlad Pruteanu To: linux-bluetooth@vger.kernel.org Cc: claudia.rosu@nxp.com, mihai-octavian.urzica@nxp.com, silviu.barbulescu@nxp.com, iulia.tanasescu@nxp.com, andrei.istodorescu@nxp.com, luiz.dentz@gmail.com, Vlad Pruteanu Subject: [PATCH BlueZ v2 4/4] bap: Remove deleted devices from pa_req queue Date: Wed, 24 Apr 2024 17:07:41 +0300 Message-Id: <20240424140741.73899-5-vlad.pruteanu@nxp.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240424140741.73899-1-vlad.pruteanu@nxp.com> References: <20240424140741.73899-1-vlad.pruteanu@nxp.com> X-ClientProxiedBy: AS4PR09CA0026.eurprd09.prod.outlook.com (2603:10a6:20b:5d4::9) To AM6PR04MB5384.eurprd04.prod.outlook.com (2603:10a6:20b:2b::17) Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB5384:EE_|DU2PR04MB8582:EE_ X-MS-Office365-Filtering-Correlation-Id: 53041280-a41e-47b3-dfea-08dc6467fe16 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ArLuB8y4VDBfxkf+IjxB3lxdcm0pHxOvHCq29DQel2+ktCWSMQCYxCHNyE7ehjTwS+yMjTUR4ri/S62LaXmO7anXdMO/k2YiLEnmNkuUMeR4/60Sd3jGih/iIoPHN6rFqXZFfgOQOEtLOVcdrJdlL8ffFF5322G2UQ4dEU8O4cWIyTlv1ZXsZS6R+wYQjMqklAKviIS7/PsQUkSZLC9HG+FYas2oDHq9OpHy0hsEEENK026mKLAtMThsUFa1FsGmBLWkaIiPlfNLVrKXWY/tlkPief3kJnkGySC9dApRjxu9lPn/ndjFXncGVxr3QpJcizvz08mO3CwPa9TAXaiCkui2tZAqoL830ORmjzztVbYAnoaLLN+S+UUpTv/XfWRYys3l+Bh/bJZailNgSkj/ZuQfLNxCcl5UBm+2H+7k5mrY+Cb0TtuF3Xqz7US8J3fewHr1a0P929HUv35KG1IMRIobCkr8NRtL2d3yyAanWS/63T3f9l/gylmIkGQA7RElaLnItjOz4Q1jWkexKSTXNDwoT+51eupLUyL23ttkhVVbZR+38X9DunUy3AKGxmp/24k0d5iysJZLvthpXY2ocHTsAHqJ7t3Vm6vME4buD8xLFOVZ/rLG17VPgHm1LajdeQajbNk0uI3ucwqsO5IgUxrLVJipZLajGgPFyE6hEJO4VIzB5p5J3fVCiaS3WH1Ddsqw0+CTSnvs1PPyVFBqZpDebBkZNVXv7hq8Vvss+/BnQ2p42bkQ1mPpUZEfO1o7MCAEinnerD8hLP7CSK0x/UeRuCgHzEtuDE+5ChEKmPCrsy7uGOxNRzYSxOD2m4yxDnxRzRv7i3ryA4FYQ0UhG0WtUK5HhuQw2tthZx+zR8ECnGIzcd2Tr3/Q2VAyFZzerGDzffwwdzG+H3v5MVJpvq1ohF1kf7PYW5XbykxjU3yvwP50Uhohomuo8EkCGOrTh7sGjCuxtolgvNeLiFunUhyBCqSunc0yxNx5cmlWkJ5aeus3uKVX7MBxwBvbrxpCAQKcaXW7Lrd4wfC72wDk1/261+ZbN74VYlj9EOtdOvA8atKFbtU+X91MGG3y4pqMVoR8lob6trOEk/QtVK9m4lq/MY/3a/zbrgrvg44qOJl0nqgBsNxCHRyRq6KOebIMG2vqoSJLkh9b8NlQoMMYGosMlphROA6SmkM6pbYK4DF9vTAVN/lVYpjZe5Iim0DOl1ws9htbtAp34EOoPtDAuTmkOUEYCkLlj8bUOPtRaG1S2uOcDxH8wRW/9/wUfZ0VY043WisUeLBzObPdy6wD7yv7ALlJ55onBT1/kn2MWby6KFcZ9QABKVKrjl2MLZwRx/vngZbQ0unJaSgt9WzEBw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB5384.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(1800799015)(376005)(366007)(52116005)(38350700005);DIR:OUT;SFP:1101;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Aft54Q2ht2GBMqzg2PNgPZX7ftk7PrM8My4NQZGc4Yh4lxURhP3mt4LL9o5yYgwyw7U9KTtCevBztHWSTLfQpeeKqXa5NyaORkm+1fvbZ3Yg/RTSVE0oAkUAoJ0lT7vaEP6MRylKdv+Y0pPSAlBzs7UlmKAmgkfaHFrXy/rr1mbPEZqajsoVRt0dRBIQHVMNhtqwBhF51heoBkdktpewNmPkfZlZO2If1nCLogb2ofZFSS2vNKF4r091awM1jdTgy1/VjuHtWw3M8KekvkqEhTLo8dadjSDl4VrE/8svnJ3RzVaOeW/aC487WHyMXDKVjtnRp8eQrfB9kb/Lhs0RXzF6pt/AdiS6lUNlQOTmz9iTgupgOwmSrmUtP6TmZ2SdNf8+4m8rELKG5v1VB3TMF0PnFR17ffqIja2Z/M2Az2LhFB67v7YBu4ddfbJQkReovv0XEdURRjMAsn63sI0ns57zaChG6ZSs9YZW7T5cXMwbXEbbzBAgCTC5hgABQSDDP+Tmt8wlhCMcwKK1Zrw726QUWKiwaDEEN5TsWsJRHvi1vi7+k3mux7y16AdSdlJlEvk X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 53041280-a41e-47b3-dfea-08dc6467fe16 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB5384.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2024 14:08:18.8473 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: +SQ4FrFGypDAoB0t0IS130gv4gkKJaKXcEe2IXZvKfOsKuvK0EIYEoEG7McU3ocTJvtpneV12+4/9/rxU1CKqg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8582 The bap_bcast_remove function has been updated to remove from the pa_req queue entries of devices that were freed. pa_req that are already in progress are treated by the bap_data_free function. The lookup in bap_bcast_remove was necessary. The entry corresponding to the calling service must be removed from the pa_req queue. There is no other way to get a refference to this entry other than to search in the queue. This patch fixes a crash that occurs when a device is freed before the pa_idle_timer handles it's entry in the pa_req queue. The following log was obtained while running an Unicast setup: ==105052==ERROR: AddressSanitizer: heap-use-after-free on address 0x60400001c418 at pc 0x55775caf1846 bp 0x7ffc83d9fb90 sp 0x7ffc83d9fb80 READ of size 8 at 0x60400001c418 thread T0 0 0x55775caf1845 in btd_service_get_device src/service.c:325 1 0x55775ca03da2 in short_lived_pa_sync profiles/audio/bap.c:2693 2 0x55775ca03da2 in pa_idle_timer profiles/audio/bap.c:1996 --- profiles/audio/bap.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c index ab0b96222..2b1ed501b 100644 --- a/profiles/audio/bap.c +++ b/profiles/audio/bap.c @@ -2981,10 +2981,20 @@ static int bap_bcast_probe(struct btd_service *service) return 0; } +static bool match_service(const void *data, const void *match_data) +{ + struct bap_bcast_pa_req *pa_req = (struct bap_bcast_pa_req *)data; + + if (pa_req->data.service == match_data) + return true; + return false; +} + static void bap_bcast_remove(struct btd_service *service) { struct btd_device *device = btd_service_get_device(service); struct bap_data *data; + struct bap_bcast_pa_req *pa_req; char addr[18]; ba2str(device_get_address(device), addr); @@ -2995,6 +3005,14 @@ static void bap_bcast_remove(struct btd_service *service) error("BAP service not handled by profile"); return; } + /* Remove the corresponding entry from the pa_req queue. Any pa_req that + * are in progress will be stopped by bap_data_remove which calls + * bap_data_free. + */ + pa_req = queue_remove_if(data->bap_adapter->bcast_pa_requests, + match_service, service); + if (pa_req) + free(pa_req); bap_data_remove(data); }