Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp603076pxu; Sun, 25 Oct 2020 10:51:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHt9hSf3uYSFIndkt0DDxz3Vw/CS9hCHMgZsPUQUoqezDWy/kwaZ3B+F5/gSkm4ib4DV84 X-Received: by 2002:a17:906:c451:: with SMTP id ck17mr11960168ejb.303.1603648297332; Sun, 25 Oct 2020 10:51:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603648297; cv=none; d=google.com; s=arc-20160816; b=ntoNPs1CvG1VuVPDZzEc1mE667yyZx55WNokYgY8jZPDfo6U658a6NeE4Ucv8StDT/ 3rEHLCZuYHmIasSzt1nsUG88TKamAHxz8I6sBafJl9UfbPEQXsubKwRzrwexq+1Eakri Fk7FGT00dVTGTbEaGojXyJBdEW7tIWw+LSEqVev7KfNtjCLoFV6ZAVI8omONVPPOlfz3 mTb7hvPwGrzrYn0FK0vAxZJRHKUm6gZ35guGDkQRxvMOzlOmXD4UaKxpvBLkio7vD8JL +IkHdlpAQMixm9HMalUCY5eHX/MLrq9J4wNp3mt0zPmctJBXvXn1F6kk9pCDMh+NsEuG MSRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=IHC46FtSi5Vh0QJOnXwhOPEpFW6y1XbIKpBe2/NGyYM=; b=X4PBIy/ucmpD1VUJF59WIpX9ZalgQ153DIFrmTSG/ZjxUx+jvZgEFUxxxcu1ZKV8hO e9xkzK+7554blafuvjghq45BSi8Dv6Ze6rBM9EtjmvGN30SAKJTKFvZxRVyD2nlPSHyh smrprEvqZY/QLuHgksUASuhIyRFRSeuonczzMJEVshK89A9X8iNzSMZm/QHpsXV9Mm3X 3Y+qTsVQt98VjBiIQAcD8ZLybPr/25HT2SHJyGCCy93OD6IoHl5FtzPLub6/9GfDHWDB EOdH+taleytvqGHrFs05pDM4XGkk6WM+NjtGfbm/3ZXJmbS1QO60KsH6Gjtl6G92q+4S qD6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=oYJqRhZW; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l11si6920467ejx.254.2020.10.25.10.51.11; Sun, 25 Oct 2020 10:51:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=oYJqRhZW; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1417154AbgJYQ1q (ORCPT + 99 others); Sun, 25 Oct 2020 12:27:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1417129AbgJYQ1q (ORCPT ); Sun, 25 Oct 2020 12:27:46 -0400 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4A98C0613CE for ; Sun, 25 Oct 2020 09:27:45 -0700 (PDT) Received: by mail-ed1-x544.google.com with SMTP id dg9so6900917edb.12 for ; Sun, 25 Oct 2020 09:27:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=IHC46FtSi5Vh0QJOnXwhOPEpFW6y1XbIKpBe2/NGyYM=; b=oYJqRhZW54vfEo193qFbsE+6YrOArspeNgzc0kkMb2ZjBIBo/E8npcjMKrqX1xiN9T uvRzq6xUDTPz6JPjX6YpFEXoDBjKCQFBVIyYDlyHdQ7xKzYHbJ54nrH0Yr1iFG/4IKDd jWezKu4wbjK5sLWDrCVKcSJxEqoxugTs+yOpAGfxfp928ivP3V9lxGktEm1+RLUkCSVt TDzG3b+cwW9etJ+UFMDJQT33bT/mpKy5Jn0MrNy65Ikkl0eA1IoCLF4PlzU8KUjEYf1X iDSN+y18O6BeDKO47PC0Hmef61Zt8HS2qJ2colVP2U+fPMiBYAg+nEgGIwwwVkc/HRUx 4Z1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=IHC46FtSi5Vh0QJOnXwhOPEpFW6y1XbIKpBe2/NGyYM=; b=jHEbqm9Atm7rCaTxIfbHtciF0eaoSh6z7S+bIgkV/5yAB1OQAXUk49XI8G6tQVq2xF xxBXgSv6ZUZ/EwIctH9KTIoBB+Pd2Tr/l9i8PsiHg6osaSglnfY3AuymaZv09Avmlogi 4s7FanBeq0IgMdIgWohqC99Xs4JE29TcDGEJ/f6shoTqrYelA0qlwnECAA02YjydGtBs rjPHY/7kAMssQPEvTUzHc3dMN729bkQAabFdskATXgGrNq4X9ZuXbCVegv7/MxzvgR1H VOgB+YD2g4GFitRH0fMubgDo2P/mLfLtg8EVs7P0b2oEiITqSKT9ke0iLPP5hjI/K/vb D0rw== X-Gm-Message-State: AOAM532khqToe58JZ2J9xsK+3U3R3g4OX7oc3WooeroJfEak9a++dDjx TExazjOjWt1Cmee0pLx3oylycs4sgOI= X-Received: by 2002:a05:6402:2073:: with SMTP id bd19mr11699848edb.127.1603643264254; Sun, 25 Oct 2020 09:27:44 -0700 (PDT) Received: from Marijn-Arch-PC.localdomain (94-209-165-62.cable.dynamic.v4.ziggo.nl. [94.209.165.62]) by smtp.gmail.com with ESMTPSA id a27sm4185928ejb.67.2020.10.25.09.27.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Oct 2020 09:27:43 -0700 (PDT) From: Marijn Suijten To: linux-bluetooth@vger.kernel.org Cc: luiz.dentz@gmail.com, pali@kernel.org, Marijn Suijten Subject: [PATCH BlueZ] audio/a2dp: a2dp_channel should have a refcount on avdtp session Date: Sun, 25 Oct 2020 17:27:30 +0100 Message-Id: <20201025162730.47247-1-marijns95@gmail.com> X-Mailer: git-send-email 2.29.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org a2dp_channel keeps a reference to an avdtp session without incrementing its refcount. Not only does this appear wrong, it causes unexpected disconnections when the remote SEP responds with rejections. During testing with an audio application disconnections are observed when a codec config change through MediaEndpoint1.SetConfiguration fails. As soon as BlueZ receives this failure from the peer the corresponding a2dp_setup object is cleaned up which holds the last refcount to an avdtp session, in turn starting the disconnect process. An eventual open sink/source and transport have already closed by that time and released their refcounts. Adding refcounting semantics around a2dp_channel resolves the disconnections and allows future calls on MediaEndpoint1 to safely access the sesion stored within this channel. --- profiles/audio/a2dp.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c index cc4866b5b..0eac0135f 100644 --- a/profiles/audio/a2dp.c +++ b/profiles/audio/a2dp.c @@ -1507,6 +1507,9 @@ static void channel_free(void *data) avdtp_remove_state_cb(chan->state_id); + if (chan->session) + avdtp_unref(chan->session); + queue_destroy(chan->seps, remove_remote_sep); free(chan->last_used); g_free(chan); @@ -2065,7 +2068,7 @@ static void avdtp_state_cb(struct btd_device *dev, struct avdtp *session, break; case AVDTP_SESSION_STATE_CONNECTED: if (!chan->session) - chan->session = session; + chan->session = avdtp_ref(session); load_remote_seps(chan); break; } @@ -2145,6 +2148,7 @@ found: channel_remove(chan); return NULL; } + avdtp_ref(chan->session); return avdtp_ref(chan->session); } @@ -2165,6 +2169,7 @@ static void connect_cb(GIOChannel *io, GError *err, gpointer user_data) error("Unable to create AVDTP session"); goto fail; } + avdtp_ref(chan->session); } g_io_channel_unref(chan->io); -- 2.29.1 Marijn Suijten