From patchwork Thu Mar 2 20:57:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 13157899 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8FF57C6FA8E for ; Thu, 2 Mar 2023 20:58:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229530AbjCBU6V (ORCPT ); Thu, 2 Mar 2023 15:58:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229656AbjCBU6E (ORCPT ); Thu, 2 Mar 2023 15:58:04 -0500 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DC1C3AB5 for ; Thu, 2 Mar 2023 12:58:02 -0800 (PST) Received: by mail-pl1-x62e.google.com with SMTP id i10so578393plr.9 for ; Thu, 02 Mar 2023 12:58:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=ZoE82ediI01A5EdAcBIkRb3PkC7PP+5jkbrsFputEpo=; b=IcKUSA+EnuGnw3tV8llJ/OuQ/URwcOxUt4vMHMdmI0cl80uo99NckQFSSGd+X1bt7y EZ8iN54pqeullwGTBsl8yZFZGoeQOI3UEiWq97jfC6zKYR8O4XS9z3vs0mp2wjlRDksF e9OVtXzE/Xv6/lKkjuO0rxKk0CO83aR3xufmCJ8fJP4hqmPc6IaaDh1D9lN7DdKQt5TO bL4zBtHPAndSEJe/5+bKYccRw9e4qZi5QVUFCqLMtIvNEUPV3+EiT3BEmjinkgI9ldus bqV1GDkhi/xrXMogOYn3fhbFEQEUU87LTnnOAzpKuBeBN4IRdtkNxmNScO/qRU7tsLA2 OTIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZoE82ediI01A5EdAcBIkRb3PkC7PP+5jkbrsFputEpo=; b=FtyLoF28HWQ36ddB2bQBsAoAfXRNWY6ABu2/gvuoLya5I3Md/Yhg/Fic5s2j1blqy8 k5AwJM1CF+p7QUnXT+Jhvj1Fb9HQuLHE9hhynvqyUW/rX8c/6s+ZzG5VxTOwPtrQwC7W 73edLCTSz2j7GAeBERNpPq/0mO4kN6rMYK/BYfSVEk/DgSKw4ul7PPy/a4tQ8sxhyGii nI4L5RY8k+hkb2wd481yKXhSrw2kAwJ3qle9EVL0UbKNG49KefS7MZTiBul/1B5HnC8y Not94lDrlI0CViEZJmc6KnlYY33sAgjll22BSELh1djNj4J4ZPmYAY8gzojLbEcrYJZG VwcQ== X-Gm-Message-State: AO0yUKUW+ZRVrtrgyNQq3gbENs5QLB9jH4CJRLXv1kibcvYabFp29Wpr 7abdTm5VqvDk4E+/SbthqqMHbAvvJ6k= X-Google-Smtp-Source: AK7set82cQloygOGztrBfhS1k+PdTs9fdBMgtdIMFHDi8cx1ZU0SQAG3wp6PM/k9Vm3xHQCCs6RgyQ== X-Received: by 2002:a05:6a20:7343:b0:b5:a231:107f with SMTP id v3-20020a056a20734300b000b5a231107fmr12285045pzc.12.1677790681232; Thu, 02 Mar 2023 12:58:01 -0800 (PST) Received: from lvondent-mobl4.. (c-71-59-129-171.hsd1.or.comcast.net. [71.59.129.171]) by smtp.gmail.com with ESMTPSA id i5-20020aa78d85000000b005dfc8a35793sm143463pfr.38.2023.03.02.12.57.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 12:58:00 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 1/2] shared/bap: Make use of bt_gatt_client_idle_register Date: Thu, 2 Mar 2023 12:57:57 -0800 Message-Id: <20230302205758.1252736-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This uses bt_gatt_client_idle_register to track when instance is ready instead of using a dedicated queue to track requests. Fixes: https://github.com/bluez/bluez/issues/485 --- src/shared/bap.c | 168 +++++++++++++++++++++-------------------------- 1 file changed, 74 insertions(+), 94 deletions(-) diff --git a/src/shared/bap.c b/src/shared/bap.c index c0f35e1c9aa4..3ebcd81f16c1 100644 --- a/src/shared/bap.c +++ b/src/shared/bap.c @@ -127,17 +127,6 @@ struct bt_bap_req { void *user_data; }; -typedef void (*bap_func_t)(struct bt_bap *bap, bool success, uint8_t att_ecode, - const uint8_t *value, uint16_t length, - void *user_data); - -struct bt_bap_pending { - unsigned int id; - struct bt_bap *bap; - bap_func_t func; - void *user_data; -}; - typedef void (*bap_notify_t)(struct bt_bap *bap, uint16_t value_handle, const uint8_t *value, uint16_t length, void *user_data); @@ -156,12 +145,13 @@ struct bt_bap { struct bt_gatt_client *client; struct bt_att *att; struct bt_bap_req *req; - unsigned int cp_id; + unsigned int cp_id; unsigned int process_id; unsigned int disconn_id; + unsigned int idle_id; + struct queue *reqs; - struct queue *pending; struct queue *notify; struct queue *streams; struct queue *local_eps; @@ -192,6 +182,7 @@ struct bt_bap_pac { }; struct bt_bap_endpoint { + struct bt_bap *bap; struct bt_bap_db *bdb; struct bt_bap_stream *stream; struct gatt_db_attribute *attr; @@ -2576,7 +2567,6 @@ static void bap_free(void *data) queue_destroy(bap->remote_eps, free); queue_destroy(bap->reqs, bap_req_free); - queue_destroy(bap->pending, NULL); queue_destroy(bap->notify, NULL); queue_destroy(bap->streams, bap_stream_free); @@ -2650,7 +2640,6 @@ struct bt_bap *bt_bap_new(struct gatt_db *ldb, struct gatt_db *rdb) bap = new0(struct bt_bap, 1); bap->ldb = bdb; bap->reqs = queue_new(); - bap->pending = queue_new(); bap->notify = queue_new(); bap->pac_cbs = queue_new(); bap->ready_cbs = queue_new(); @@ -2735,9 +2724,6 @@ static void bap_notify_ready(struct bt_bap *bap) { const struct queue_entry *entry; - if (!queue_isempty(bap->pending)) - return; - if (!bt_bap_ref_safe(bap)) return; @@ -2835,10 +2821,12 @@ static void bap_parse_pacs(struct bt_bap *bap, uint8_t type, } } -static void read_source_pac(struct bt_bap *bap, bool success, uint8_t att_ecode, +static void read_source_pac(bool success, uint8_t att_ecode, const uint8_t *value, uint16_t length, void *user_data) { + struct bt_bap *bap = user_data; + if (!success) { DBG(bap, "Unable to read Source PAC: error 0x%02x", att_ecode); return; @@ -2847,10 +2835,12 @@ static void read_source_pac(struct bt_bap *bap, bool success, uint8_t att_ecode, bap_parse_pacs(bap, BT_BAP_SOURCE, bap->rdb->sources, value, length); } -static void read_sink_pac(struct bt_bap *bap, bool success, uint8_t att_ecode, +static void read_sink_pac(bool success, uint8_t att_ecode, const uint8_t *value, uint16_t length, void *user_data) { + struct bt_bap *bap = user_data; + if (!success) { DBG(bap, "Unable to read Sink PAC: error 0x%02x", att_ecode); return; @@ -2859,54 +2849,11 @@ static void read_sink_pac(struct bt_bap *bap, bool success, uint8_t att_ecode, bap_parse_pacs(bap, BT_BAP_SINK, bap->rdb->sinks, value, length); } -static void bap_pending_destroy(void *data) -{ - struct bt_bap_pending *pending = data; - struct bt_bap *bap = pending->bap; - - if (queue_remove_if(bap->pending, NULL, pending)) - free(pending); - - bap_notify_ready(bap); -} - -static void bap_pending_complete(bool success, uint8_t att_ecode, - const uint8_t *value, uint16_t length, - void *user_data) -{ - struct bt_bap_pending *pending = user_data; - - if (pending->func) - pending->func(pending->bap, success, att_ecode, value, length, - pending->user_data); -} - -static void bap_read_value(struct bt_bap *bap, uint16_t value_handle, - bap_func_t func, void *user_data) -{ - struct bt_bap_pending *pending; - - pending = new0(struct bt_bap_pending, 1); - pending->bap = bap; - pending->func = func; - pending->user_data = user_data; - - pending->id = bt_gatt_client_read_value(bap->client, value_handle, - bap_pending_complete, pending, - bap_pending_destroy); - if (!pending->id) { - DBG(bap, "Unable to send Read request"); - free(pending); - return; - } - - queue_push_tail(bap->pending, pending); -} - -static void read_source_pac_loc(struct bt_bap *bap, bool success, - uint8_t att_ecode, const uint8_t *value, - uint16_t length, void *user_data) +static void read_source_pac_loc(bool success, uint8_t att_ecode, + const uint8_t *value, uint16_t length, + void *user_data) { + struct bt_bap *bap = user_data; struct bt_pacs *pacs = bap_get_pacs(bap); if (!success) { @@ -2925,14 +2872,17 @@ static void read_source_pac_loc(struct bt_bap *bap, bool success, if (gatt_db_attribute_get_char_data(pacs->source, NULL, &value_handle, NULL, NULL, NULL)) - bap_read_value(bap, value_handle, read_source_pac, bap); + bt_gatt_client_read_value(bap->client, value_handle, + read_source_pac, bap, + NULL); } } -static void read_sink_pac_loc(struct bt_bap *bap, bool success, - uint8_t att_ecode, const uint8_t *value, - uint16_t length, void *user_data) +static void read_sink_pac_loc(bool success, uint8_t att_ecode, + const uint8_t *value, uint16_t length, + void *user_data) { + struct bt_bap *bap = user_data; struct bt_pacs *pacs = bap_get_pacs(bap); if (!success) { @@ -2951,14 +2901,17 @@ static void read_sink_pac_loc(struct bt_bap *bap, bool success, if (gatt_db_attribute_get_char_data(pacs->sink, NULL, &value_handle, NULL, NULL, NULL)) - bap_read_value(bap, value_handle, read_sink_pac, bap); + bt_gatt_client_read_value(bap->client, value_handle, + read_sink_pac, bap, + NULL); } } -static void read_pac_context(struct bt_bap *bap, bool success, - uint8_t att_ecode, const uint8_t *value, - uint16_t length, void *user_data) +static void read_pac_context(bool success, uint8_t att_ecode, + const uint8_t *value, uint16_t length, + void *user_data) { + struct bt_bap *bap = user_data; struct bt_pacs *pacs = bap_get_pacs(bap); if (!success) { @@ -2970,10 +2923,11 @@ static void read_pac_context(struct bt_bap *bap, bool success, NULL, NULL); } -static void read_pac_supported_context(struct bt_bap *bap, bool success, - uint8_t att_ecode, const uint8_t *value, - uint16_t length, void *user_data) +static void read_pac_supported_context(bool success, uint8_t att_ecode, + const uint8_t *value, uint16_t length, + void *user_data) { + struct bt_bap *bap = user_data; struct bt_pacs *pacs = bap_get_pacs(bap); if (!success) { @@ -3015,7 +2969,8 @@ static void foreach_pacs_char(struct gatt_db_attribute *attr, void *user_data) if (!pacs->sink) pacs->sink = attr; - bap_read_value(bap, value_handle, read_sink_pac, bap); + bt_gatt_client_read_value(bap->client, value_handle, + read_sink_pac, bap, NULL); } if (!bt_uuid_cmp(&uuid, &uuid_source)) { @@ -3028,7 +2983,8 @@ static void foreach_pacs_char(struct gatt_db_attribute *attr, void *user_data) if (!pacs->source) pacs->source = attr; - bap_read_value(bap, value_handle, read_source_pac, NULL); + bt_gatt_client_read_value(bap->client, value_handle, + read_source_pac, bap, NULL); } if (!bt_uuid_cmp(&uuid, &uuid_sink_loc)) { @@ -3040,7 +2996,8 @@ static void foreach_pacs_char(struct gatt_db_attribute *attr, void *user_data) return; pacs->sink_loc = attr; - bap_read_value(bap, value_handle, read_sink_pac_loc, NULL); + bt_gatt_client_read_value(bap->client, value_handle, + read_sink_pac_loc, bap, NULL); } if (!bt_uuid_cmp(&uuid, &uuid_source_loc)) { @@ -3052,7 +3009,8 @@ static void foreach_pacs_char(struct gatt_db_attribute *attr, void *user_data) return; pacs->source_loc = attr; - bap_read_value(bap, value_handle, read_source_pac_loc, NULL); + bt_gatt_client_read_value(bap->client, value_handle, + read_source_pac_loc, bap, NULL); } if (!bt_uuid_cmp(&uuid, &uuid_context)) { @@ -3063,7 +3021,8 @@ static void foreach_pacs_char(struct gatt_db_attribute *attr, void *user_data) return; pacs->context = attr; - bap_read_value(bap, value_handle, read_pac_context, NULL); + bt_gatt_client_read_value(bap->client, value_handle, + read_pac_context, bap, NULL); } if (!bt_uuid_cmp(&uuid, &uuid_supported_context)) { @@ -3075,8 +3034,9 @@ static void foreach_pacs_char(struct gatt_db_attribute *attr, void *user_data) return; pacs->supported_context = attr; - bap_read_value(bap, value_handle, read_pac_supported_context, - NULL); + bt_gatt_client_read_value(bap->client, value_handle, + read_pac_supported_context, + bap, NULL); } } @@ -3324,14 +3284,17 @@ static void bap_ep_set_status(struct bt_bap *bap, struct bt_bap_endpoint *ep, bap_stream_state_changed(ep->stream); } -static void read_ase_status(struct bt_bap *bap, bool success, uint8_t att_ecode, +static void read_ase_status(bool success, uint8_t att_ecode, const uint8_t *value, uint16_t length, void *user_data) { struct bt_bap_endpoint *ep = user_data; + struct bt_bap *bap = ep->bap; - if (!success) + if (!success) { + DBG(bap, "ASE read status failed: 0x%04x", att_ecode); return; + } bap_ep_set_status(bap, ep, value, length); } @@ -3409,7 +3372,10 @@ static void bap_endpoint_attach(struct bt_bap *bap, struct bt_bap_endpoint *ep) DBG(bap, "ASE handle 0x%04x", value_handle); - bap_read_value(bap, value_handle, read_ase_status, ep); + ep->bap = bap; + + bt_gatt_client_read_value(bap->client, value_handle, read_ase_status, + ep, NULL); ep->state_id = bap_register_notify(bap, value_handle, bap_endpoint_notify, ep); @@ -3734,6 +3700,15 @@ static void bap_attach_att(struct bt_bap *bap, struct bt_att *att) bap, NULL); } +static void bap_idle(void *data) +{ + struct bt_bap *bap = data; + + bap->idle_id = 0; + + bap_notify_ready(bap); +} + bool bt_bap_attach(struct bt_bap *bap, struct bt_gatt_client *client) { bt_uuid_t uuid; @@ -3769,6 +3744,9 @@ clone: bap_attach_att(bap, bt_gatt_client_get_att(client)); + bap->idle_id = bt_gatt_client_idle_register(bap->client, bap_idle, + bap, NULL); + if (bap->rdb->pacs) { uint16_t value_handle; struct bt_pacs *pacs = bap->rdb->pacs; @@ -3778,8 +3756,10 @@ clone: if (gatt_db_attribute_get_char_data(pacs->sink, NULL, &value_handle, NULL, NULL, NULL)) { - bap_read_value(bap, value_handle, - read_sink_pac, bap); + bt_gatt_client_read_value(bap->client, + value_handle, + read_sink_pac, + bap, NULL); } } @@ -3788,8 +3768,10 @@ clone: if (gatt_db_attribute_get_char_data(pacs->source, NULL, &value_handle, NULL, NULL, NULL)) { - bap_read_value(bap, value_handle, - read_source_pac, bap); + bt_gatt_client_read_value(bap->client, + value_handle, + read_source_pac, + bap, NULL); } } @@ -3797,8 +3779,6 @@ clone: bap_cp_attach(bap); - bap_notify_ready(bap); - return true; } From patchwork Thu Mar 2 20:57:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 13157900 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6836BC7EE30 for ; Thu, 2 Mar 2023 20:58:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229565AbjCBU6W (ORCPT ); Thu, 2 Mar 2023 15:58:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbjCBU6F (ORCPT ); Thu, 2 Mar 2023 15:58:05 -0500 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA2FE8A66 for ; Thu, 2 Mar 2023 12:58:03 -0800 (PST) Received: by mail-pf1-x42f.google.com with SMTP id c4so324600pfl.0 for ; Thu, 02 Mar 2023 12:58:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=vvtpwt+M3iad/DduKVIWcp3bK1L4ftpcrjFy+kPkfKI=; b=TtiJxaeXgrL1EfLuZTSQfLqd7s3RxRewhSJUAqf6I/0baWIk9nYX5xDyQzMy71ucZl Q6hJ1mtu8XOY42hoQo50OeXxo+yquBzHq7Y68lB0885ompDI43mnI8cIJLyrYyPrGwnk T2xnOrF+FCJRhoqqQLze6x23RDyFYCIQ+IT53sEuMymyw7+awJC31bYCWcNo4cGkp6AC VqFENn4PlcRmnCuy+2uLZrokNLgFBUeeHlwUc++ZT3PkIH6A5fhdMZEWrzevizyI+l3e XJCixPNOxQCbAypzoj6lCvvgXz8PX0FCXJK9lD/L5y4n+gGLES147TQXaUIHt31a+YiB Fp1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vvtpwt+M3iad/DduKVIWcp3bK1L4ftpcrjFy+kPkfKI=; b=lqOtxv4gKriaLKQVwJjdVWZNlRw3JcgxyXx9kf+gD5+yvPGQJoZpgVYWxFj+S49fWI AKjolVqwGYG5+IkrIVs+p73eJFXt4cRMf1ZVvnKZEJT1Lz9i2y87N4A3w9HQv9z1hMB5 hdwrhfVVV9PlirkTw6DlMgvjx7RVX9UtD9IwqgUL4FEvWOND5kLKd/Ttk2quWwqdbep5 wNbgjcgdiO4ugZ9s0Yn9t0qfWvbSXoufV5MpLMbPNhedhVuEmMHL6yFGG+Qe8nsYVvKl 6MLnkEmxxzeDRdtx/HZeOfAlW4RqZbJ6z7D3tPRoxob+AYmtNTgCDhBSrTyyemp3whJB ahLQ== X-Gm-Message-State: AO0yUKVhzLcBesFRITKNzCqWhuj9a1asXmIMOLftr/52I/GuX4t99C2g qQlyQAf1wyqDe4tXMDUEpK6xdTbK4pE= X-Google-Smtp-Source: AK7set9eZs5lMj8buNLEzOlsguSMDJKck2QD1Qxa0Set0ImhRD+NX80g6nxGGZ5qp49CqqkGbJB8HA== X-Received: by 2002:a62:19d0:0:b0:5e2:434d:116b with SMTP id 199-20020a6219d0000000b005e2434d116bmr10041686pfz.23.1677790682639; Thu, 02 Mar 2023 12:58:02 -0800 (PST) Received: from lvondent-mobl4.. (c-71-59-129-171.hsd1.or.comcast.net. [71.59.129.171]) by smtp.gmail.com with ESMTPSA id i5-20020aa78d85000000b005dfc8a35793sm143463pfr.38.2023.03.02.12.58.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 12:58:01 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 2/2] bap: Fix crash on unexpected disconnect Date: Thu, 2 Mar 2023 12:57:58 -0800 Message-Id: <20230302205758.1252736-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230302205758.1252736-1-luiz.dentz@gmail.com> References: <20230302205758.1252736-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz If an unexpected disconnect happens while bt_bap_config is pending the following trace can be observed, to fix it bt_bap_config is reworked so it no longer attempts to create and config the stream in place, instead it just return the new stream and the function is renamed to bt_bap_stream_new: Invalid write of size 4 at 0x3980D8: config_cb (bap.c:395) by 0x4DF5A3: bap_req_complete (bap.c:3471) by 0x4E9D33: bap_req_detach (bap.c:3807) by 0x4E9D33: bt_bap_detach (bap.c:3819) by 0x4E9D33: bt_bap_detach (bap.c:3810) by 0x397AA9: bap_disconnect (bap.c:1342) by 0x4223E0: btd_service_disconnect (service.c:305) by 0x4974D8F: g_slist_foreach (in /usr/lib64/libglib-2.0.so.0.7200.3) by 0x438FC3: att_disconnected_cb (device.c:5160) by 0x49A6C6: queue_foreach (queue.c:207) by 0x4B463B: disconnect_cb (att.c:701) by 0x5054DF: watch_callback (io-glib.c:157) by 0x495BFAE: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.7200.3) by 0x49B12C7: ??? (in /usr/lib64/libglib-2.0.so.0.7200.3) Address 0x6576940 is 96 bytes inside a block of size 112 free'd at 0x48480E4: free (vg_replace_malloc.c:872) by 0x48F78D: remove_interface (object.c:660) by 0x490489: g_dbus_unregister_interface (object.c:1394) by 0x397BA8: ep_remove (bap.c:1330) by 0x49ACF4: queue_remove_if (queue.c:279) by 0x49B0AC: queue_remove_all (queue.c:321) by 0x397A7C: bap_disconnect (bap.c:1339) by 0x4223E0: btd_service_disconnect (service.c:305) by 0x4974D8F: g_slist_foreach (in /usr/lib64/libglib-2.0.so.0.7200.3) by 0x438FC3: att_disconnected_cb (device.c:5160) by 0x49A6C6: queue_foreach (queue.c:207) by 0x4B463B: disconnect_cb (att.c:701) Block was alloc'd at at 0x484586F: malloc (vg_replace_malloc.c:381) by 0x49B432: util_malloc (util.c:43) by 0x39A1D9: ep_register (bap.c:563) by 0x39A1D9: pac_found (bap.c:664) by 0x4E5FEA: bap_foreach_pac (bap.c:3980) by 0x4EA437: bap_notify_ready (bap.c:2736) by 0x4EA437: bap_idle (bap.c:3711) by 0x4B52F0: idle_notify (gatt-client.c:171) by 0x49ACF4: queue_remove_if (queue.c:279) by 0x49B0AC: queue_remove_all (queue.c:321) by 0x4C092C: notify_client_idle (gatt-client.c:180) by 0x4C092C: request_unref (gatt-client.c:199) by 0x4AACB5: destroy_att_send_op (att.c:209) by 0x4B2B88: handle_rsp (att.c:862) by 0x4B2B88: can_read_data (att.c:1052) by 0x5054DF: watch_callback (io-glib.c:157) --- profiles/audio/bap.c | 28 ++++++++++++---------------- src/shared/bap.c | 16 ++-------------- src/shared/bap.h | 6 ++---- 3 files changed, 16 insertions(+), 34 deletions(-) diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c index b8c75f195854..dfdf8725589d 100644 --- a/profiles/audio/bap.c +++ b/profiles/audio/bap.c @@ -466,15 +466,13 @@ static DBusMessage *set_configuration(DBusConnection *conn, DBusMessage *msg, /* TODO: Check if stream capabilities match add support for Latency * and PHY. */ - if (ep->stream) - ep->id = bt_bap_stream_config(ep->stream, &ep->qos, ep->caps, - config_cb, ep); - else - ep->stream = bt_bap_config(ep->data->bap, ep->lpac, ep->rpac, - &ep->qos, ep->caps, - config_cb, ep); + if (!ep->stream) + ep->stream = bt_bap_stream_new(ep->data->bap, ep->lpac, + ep->rpac, &ep->qos, ep->caps); - if (!ep->stream) { + ep->id = bt_bap_stream_config(ep->stream, &ep->qos, ep->caps, + config_cb, ep); + if (!ep->id) { DBG("Unable to config stream"); free(ep->caps); ep->caps = NULL; @@ -604,15 +602,13 @@ static void bap_config(void *data, void *user_data) /* TODO: Check if stream capabilities match add support for Latency * and PHY. */ - if (ep->stream) - ep->id = bt_bap_stream_config(ep->stream, &ep->qos, ep->caps, - config_cb, ep); - else - ep->stream = bt_bap_config(ep->data->bap, ep->lpac, ep->rpac, - &ep->qos, ep->caps, - config_cb, ep); + if (!ep->stream) + ep->stream = bt_bap_stream_new(ep->data->bap, ep->lpac, + ep->rpac, &ep->qos, ep->caps); - if (!ep->stream) { + ep->id = bt_bap_stream_config(ep->stream, &ep->qos, ep->caps, + config_cb, ep); + if (!ep->id) { DBG("Unable to config stream"); util_iov_free(ep->caps, 1); ep->caps = NULL; diff --git a/src/shared/bap.c b/src/shared/bap.c index 3ebcd81f16c1..952b7be260ab 100644 --- a/src/shared/bap.c +++ b/src/shared/bap.c @@ -4176,18 +4176,15 @@ int bt_bap_select(struct bt_bap_pac *lpac, struct bt_bap_pac *rpac, return 0; } -struct bt_bap_stream *bt_bap_config(struct bt_bap *bap, +struct bt_bap_stream *bt_bap_stream_new(struct bt_bap *bap, struct bt_bap_pac *lpac, struct bt_bap_pac *rpac, struct bt_bap_qos *pqos, - struct iovec *data, - bt_bap_stream_func_t func, - void *user_data) + struct iovec *data) { struct bt_bap_stream *stream; struct bt_bap_endpoint *ep; struct match_pac match; - int id; if (!bap || !bap->rdb || queue_isempty(bap->remote_eps)) return NULL; @@ -4244,15 +4241,6 @@ struct bt_bap_stream *bt_bap_config(struct bt_bap *bap, if (!stream) stream = bap_stream_new(bap, ep, lpac, rpac, data, true); - id = bt_bap_stream_config(stream, pqos, data, func, user_data); - if (!id) { - DBG(bap, "Unable to config stream"); - queue_remove(bap->streams, stream); - ep->stream = NULL; - free(stream); - return NULL; - } - return stream; } diff --git a/src/shared/bap.h b/src/shared/bap.h index 47a15636ca22..bd13abef9ce5 100644 --- a/src/shared/bap.h +++ b/src/shared/bap.h @@ -190,13 +190,11 @@ void *bt_bap_pac_get_user_data(struct bt_bap_pac *pac); int bt_bap_select(struct bt_bap_pac *lpac, struct bt_bap_pac *rpac, bt_bap_pac_select_t func, void *user_data); -struct bt_bap_stream *bt_bap_config(struct bt_bap *bap, +struct bt_bap_stream *bt_bap_stream_new(struct bt_bap *bap, struct bt_bap_pac *lpac, struct bt_bap_pac *rpac, struct bt_bap_qos *pqos, - struct iovec *data, - bt_bap_stream_func_t func, - void *user_data); + struct iovec *data); struct bt_bap *bt_bap_stream_get_session(struct bt_bap_stream *stream); uint8_t bt_bap_stream_get_state(struct bt_bap_stream *stream);