From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795978073; b=c2AMkKruM8zbMfiD3FmZSi1M6eu0yuX2zvVqN20ERaC8epEyMEWFgJRyJn7GrVFDKGA/ nIyFxGbGKC8XexZh3a/Hb8NHxgJoILS3frZvPZTq+2A/WyRBe7xM6ufLYEbuTpoM46Hn8 f9hzQLjutxjr6/lO6LWVVblk3WC74BakiImwMURuHaKR0ooFq/nXJ8few8kvgoVpD37fN bNs3+Ge4Xv+VTj+94e5OnWzQ3sCGBXnmCJ0MgnZLzmfsjMVzQq4Mr6Xd3/lAbGuRyPkvY scEadxst4036/8HYIbm+dAmPQc6vTv1QS2gYP0qHID2ezSYD0575F4hITvgWNXEN2IA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795978073; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Subject:Date: Message-ID:X-Mailer:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=ndpGh6EVlildp8FDFrS7J5StMcuhjGkYYTMUq4jzP8w=; b=GRcxyXJsIHf9brdJfgH3jl/wsZDjHHDGv1gZsP1nXCyQLGYs6QBtU34carDL7wBTXDRs WNDG05PwRIa5cU/PyVAyjSXTefLRxWmGYnFR7gNhANxM02VjFqNyD2fsnFCVdSgHXgpPq B8aDVM72eTJYJtWYCHX43yijsEgVkr5ILQcEhsRnYxIoqbMGBWvtt3OuZHK2SBtp2HPyZ KtkcXoRuH4XHogBPo6IFYba7U/bmAtCNue5g+NrbFgbmecsoMODSeCHXi8nMDDmsychfl YVTMAarLyeE5Qbc5wwOBcyPrgJou0PHniUzEZtlHbytKjcbiQFlBGT1FyfMu0ck2iTw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=QHR+2ghz; arc=none smtp.remote-ip=209.85.128.53 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCA24606A31C for ; Sun, 29 Nov 2026 18:47:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BCA24606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=QHR+2ghz Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-49d05d51553so66611075e9.2 for ; Sun, 29 Nov 2026 10:47:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795978071; x=1796582871; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:message-id:date :subject:to:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ndpGh6EVlildp8FDFrS7J5StMcuhjGkYYTMUq4jzP8w=; b=QHR+2ghzrY9x4Ty0qgQStZyh1PfRB3k9rYDpH6RUuYNwy564mVGwbThy/ZQ+8+jSA5 pgI2Alvn7QxUT9a/XMGZVcL5bafNpNUdy47O9pNmbKEnA9wTirM3V4ckbUycDLCdje9c 6m1Hc/ijv4SgXcT+Do3k8Ti6MQ4cSUgXdiE22u7pnwLMP77HN1/9/nqX+hGWYx3LcudD mit04PBDBE1lGH3MeoKveNHYJHiuYkdtS4OPTjYXCmwSlDZmPPk1Dca+6xuUkGpOFJN4 mBLkyMPumyZ9c67VZ3TMbYGdbohDCztF7oIETmKWMUvwlAj35KZBzjv4fbC0cwXaXK8/ LjRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795978071; x=1796582871; h=content-transfer-encoding:content-type:mime-version:message-id:date :subject:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ndpGh6EVlildp8FDFrS7J5StMcuhjGkYYTMUq4jzP8w=; b=JNhMsVfwm3HPGzIBR2+VEFvkuOVp8ela4jiIpmQZgprQgTR83+Cfw3KEEDOIBPAqXG y3zRVyReqMJJ1oiKdeiP/UpYwPli8D9NoI1gvh70PTRlSu+51NtPqPCh1b41RxvSi+cE E2daTFLoEDcYiphnRvhwBot9lmqiwBrW8sqoMs/uG9bzipxf2k0XnCyDZ7zgjvVjg02w 1MG0eIWd2wJl41FsKP9YLD/RdKJmkcgNAh+tFlvTxAekrbbQcdls7LmFO0wjAdYglZwr cZWSEzLZEfQuGO9cd3eZDr9Y163ZwPIxaU0/ehglECZmYcFue41gbv/HXDEa3uZVVH1z twPA== X-Gm-Message-State: APuU4Z8lRN21iHDO8APhbWBX/3DMD1qnWkOkegl/7Of6jbFbk9AAPE2J yGIumA0yXh5NmYYOSa0cpa0Rh7z3vLIvxddVpIYzG/gBAdJGcWmoStX3C7fENexF X-Gm-Gg: AZFdTZcnQj2RGBcq3iJKvMPssams67UJAEh+BS2RU7JZargX559fnPTRfX/3tZmJUuz kcBK6zC2U2VagH/tBP2PB3bS9B8KhjqXyZxTkVYiQyiOCzgOPX5aBd7Z7ag/Xerj56qYiwAPAiw NwTurfFhNbQhl6C0FERqXiynIXaMea85OpybDeUfkzOBzqsMPGSxPl/ApSm+ysPTxQngno1BWhj 7FkZY/EuLkPxAWt3X5Cip54hgY2YVX8eErLKlLaKwPtRUFVxk7oOheUSQM6wpamJMK7cAt900rx jsyTCByKmkeKhNWbjTKysb63gFya9OYxLXvgLl3xk2xvb7Sge4XO9OCiyB4njOkX9/E6sTRNr7e EjVmcvZJTLYS6fMP/QlfxcO46Rtq2Y4kEuHE95XLLjJb1r2npZ74j0h35YnIxlApcccunzUqY02 i8vBtbvb+lbo75LldV9HXwCF5VL/2fe+M88/UmtDLL7i8CxM3HYebljGYHAWEO+j7tjWpuJ5eQI QqGaUPCW8ewXPb2z18SZOboIX792MEI8ncAcvwIJIaQj+dgK7hsnbVu5zjx9RX0ET6vXiaCeJmF ckcFckFPiIWIszcqMDP2b1hqnGb8nkyScMtSdoAHtf7TniWsv9O8sbCsjSHkP+ztiXLOmcKs1YP gVEYsLwzvNTL0iZ46dWrQJySgVAAruUbwn3eZNro7rO3PQd7rUqUY X-Received: by 2002:a05:600c:4e0c:b0:4bb:875b:f23f with SMTP id 5b1f17b1804b1-4bb88827f0bmr596539045e9.33.1795978070833; Sun, 29 Nov 2026 10:47:50 -0800 (PST) Received: from fdanis-tpp14s (2a02-8428-af44-1001-a1ac-9629-e946-8c0b.rev.sfr.net. [2a02:8428:af44:1001:a1ac:9629:e946:8c0b]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbc184d8dcsm52423025e9.1.2026.11.29.10.47.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 10:47:50 -0800 (PST) From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Danis?= To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ] audio/hfp-hf: Destroy MediaTransport1 on codec change/disconnect Date: Sun, 29 Nov 2026 19:47:49 +0100 Message-ID: <20261129184749.152063-1-frederic.danis.oss@gmail.com> X-Mailer: git-send-email 2.56.1 X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit The HF profile created an org.bluez.MediaTransport1 object for the SCO audio whenever a call started, but never destroyed it when the codec changed or the device disconnected (e.g. SLC dropped after hanging up and disconnecting from the phone). The stale transport(s) kept being listed by "bluetoothctl transport.list" forever. Since a device only ever has one SCO connection at a time, clear the previous codec's transport as soon as a new codec is selected, and clear the current one when the device goes away, mirroring what a2dp's clear_config() does. Assisted-by: Copilot:claude-sonnet-5 --- profiles/audio/hfp-hf.c | 56 ++++++++++++++++++++++++++++++++++------- profiles/audio/media.c | 15 +++++++++++ profiles/audio/media.h | 2 ++ 3 files changed, 64 insertions(+), 9 deletions(-) diff --git a/profiles/audio/hfp-hf.c b/profiles/audio/hfp-hf.c index bc6d7229f..56c5f649e 100644 --- a/profiles/audio/hfp-hf.c +++ b/profiles/audio/hfp-hf.c @@ -138,6 +138,19 @@ static struct hfp_server *find_server(GSList *list, struct btd_adapter *a) return NULL; } +static struct media_endpoint *find_server_endpoint(struct hfp_server *server, + uint8_t codec) +{ + GSList *l; + + for (l = server->endpoints; l; l = l->next) { + if (media_endpoint_get_codec(l->data) == codec) + return l->data; + } + + return NULL; +} + static void unregister_endpoint(gpointer data, gpointer user_data) { struct media_endpoint *ep = data; @@ -248,9 +261,21 @@ static void device_destroy(struct hfp_device *dev) server = find_server(servers, device_get_adapter(telephony_get_device(dev->telephony))); - if (server) + if (server) { + struct media_endpoint *ep; + + /* Destroy the MediaTransport1 created for this device's SCO + * audio, if any, so it does not linger after the device is + * gone. + */ + ep = find_server_endpoint(server, dev->codec); + if (ep) + hfp_hf_clear_configuration(ep, + telephony_get_device(dev->telephony)); + g_slist_foreach(server->endpoints, unregister_endpoint, dev->telephony); + } telephony_unregister_interface(dev->telephony); } @@ -422,21 +447,34 @@ static bool hfp_hf_select_codec(uint8_t codec, void *user_data) struct hfp_device *dev = user_data; struct btd_adapter *adapter; struct hfp_server *server; - GSList *l; + struct media_endpoint *ep; DBG("Selecting codec: %u", codec); adapter = device_get_adapter(telephony_get_device(dev->telephony)); server = find_server(servers, adapter); - for (l = server->endpoints; l; l = l->next) { - if (media_endpoint_get_codec(l->data) == codec) { - dev->codec = codec; - return true; - } + ep = find_server_endpoint(server, codec); + if (!ep) { + DBG("Unsupported codec: %u", codec); + return false; } - DBG("Unsupported codec: %u", codec); - return false; + if (dev->codec != codec) { + /* A device only ever has one SCO connection at a time, so + * the previous codec's transport, if any, is no longer + * valid. + */ + struct media_endpoint *prev; + + prev = find_server_endpoint(server, dev->codec); + if (prev) + hfp_hf_clear_configuration(prev, + telephony_get_device(dev->telephony)); + } + + dev->codec = codec; + + return true; } static struct hfp_hf_callbacks hf_session_callbacks = { diff --git a/profiles/audio/media.c b/profiles/audio/media.c index 13fead886..f1c8906e4 100644 --- a/profiles/audio/media.c +++ b/profiles/audio/media.c @@ -1501,6 +1501,21 @@ gboolean hfp_hf_set_configuration(struct media_endpoint *endpoint, cb, user_data, destroy, -1); } +void hfp_hf_clear_configuration(struct media_endpoint *endpoint, + struct btd_device *device) +{ + struct media_transport *transport; + + if (!endpoint) + return; + + transport = find_device_transport(endpoint, device); + if (!transport) + return; + + clear_configuration(endpoint, transport); +} + static bool endpoint_init_sco(struct media_endpoint *endpoint, int *err) { diff --git a/profiles/audio/media.h b/profiles/audio/media.h index eb95a8b06..c20238f1a 100644 --- a/profiles/audio/media.h +++ b/profiles/audio/media.h @@ -89,3 +89,5 @@ gboolean hfp_hf_set_configuration(struct media_endpoint *endpoint, media_endpoint_cb_t cb, void *user_data, GDestroyNotify destroy); +void hfp_hf_clear_configuration(struct media_endpoint *endpoint, + struct btd_device *device); -- 2.43.0