Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp1555420rwb; Wed, 26 Jul 2023 14:37:51 -0700 (PDT) X-Google-Smtp-Source: APBJJlE0TP/oRp9cMF0PSQNuCKvFpfvfXRHVE9fmOemdommfvp7+wmkpEuTnq6uO7lOnTqGXPqWH X-Received: by 2002:a17:90b:4c47:b0:268:300b:ee81 with SMTP id np7-20020a17090b4c4700b00268300bee81mr3167438pjb.15.1690407471232; Wed, 26 Jul 2023 14:37:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1690407471; cv=pass; d=google.com; s=arc-20160816; b=lWL1nan6uouEfxWhIvu9DC14v6lbKFsCbSbO+/7sdSNIxWj0EyOSeh6+LYS4QmHe2/ H+Y89OTpjSh9ncL7g614OhQKJMY+A/nPcyrP9n1x4IodM4ocJQNOfGnOaBwS7Nzw6IZj Omp2Bdek/JLExgoSS/9vJUUAR5Ld3pIcf+BG7EtV8OEG68G/K0Xtr9CsATrGyAPaKTpr ysf2BELWHVMbDr+cK59CHeSCrhNDmoMmrfw0LOZpxYvLwFtht8F//5fmvkDFT+1fx5f0 23ZmJ3IToWaqpj8SH3NEwnplhoZ/MqJmH2tOMeYituWU6lUZHVqMBPWvjIleRiosIpCo Tq8Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QF4dKVf7TmhOZ/dmj3ft7QgJjtuX9ExKfqILvYm6EEI=; fh=raBgKoRsHCwQLc6ReOhmOoEQ+DtSaNc74fugaHBwryI=; b=PPUyEBN61b/0rPXi81z0axfcPQ3CMOsfDEd561GS4dFlhjNTlQ85fljFDfeNQSYXvk mlp3embNNNR67T5Zbib7k3C3SFIbhOssCKGBoFIecUH3nhqToO9r6UKk39OqpakqxvK7 DiqdPZUNontaidzcHgI0r0FmLBWEkGWtUarzoFEUsHNZOzJfhdjbF81ktq8BByO0MXOS X8/1aXKmXAtp8hHffniQerfhDNwSUpgnDBoUxoSsykjtQPyMlJXCqaAdpUz3r5MBgiIM NDsy52ifTP+7Q9vH8eidKcVqP1S0X4wAIaYhEwL07Ewcnnz4IHl2zvaEgDLqYojMLgBG MbxQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@iki.fi header.s=meesny header.b=tMSnUdNh; arc=pass (i=1); spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i4-20020a17090adc0400b00262ffca5a31si1587752pjv.161.2023.07.26.14.37.37; Wed, 26 Jul 2023 14:37:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@iki.fi header.s=meesny header.b=tMSnUdNh; arc=pass (i=1); spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231550AbjGZV0K (ORCPT + 99 others); Wed, 26 Jul 2023 17:26:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231569AbjGZV0J (ORCPT ); Wed, 26 Jul 2023 17:26:09 -0400 Received: from meesny.iki.fi (meesny.iki.fi [IPv6:2001:67c:2b0:1c1::201]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CE60269E for ; Wed, 26 Jul 2023 14:26:03 -0700 (PDT) Received: from monolith.lan (91-152-120-101.elisa-laajakaista.fi [91.152.120.101]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: pav) by meesny.iki.fi (Postfix) with ESMTPSA id 4RB6Q21MRYz109C; Thu, 27 Jul 2023 00:25:46 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1690406746; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QF4dKVf7TmhOZ/dmj3ft7QgJjtuX9ExKfqILvYm6EEI=; b=tMSnUdNhfinhzfxpyt1UM8GkkW3emkSWXn/TNUIq5PxSQFwXtOwQD9uRwppiT6dZZIpSHw TjHp5cHk2WY//V2fA6yA63y65Dcw2KiJkse+2inUpW4H9qdZzKV+ZmDtyV7xQG3C3vgn3G C4nvSoiGbT7k9vzR9vlrOqBHZZpRonQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1690406746; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QF4dKVf7TmhOZ/dmj3ft7QgJjtuX9ExKfqILvYm6EEI=; b=Qy5Lt0WW6VvfQvKSTJBSdOGks/ylXk/Xla2utYL22UHYMSW9j0RerSuK6GV3QVYeHDIpTR OICistTKdtjtTLWDRKvZdoZYxpA0V9WQAJBH9PRHLf9Q1+Kaju1lyKiOAIGZD4ItAsY0Nz acr4h40NYPbMKfCZJhvRGwRdQOFPlIE= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=pav smtp.mailfrom=pav@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1690406746; a=rsa-sha256; cv=none; b=phyUNmSJeQHSeXfYlfTyNB0T1nk4SuZzYlj9n5jeW5ZqLx/9s7OYexDbwQBexHSW3q23wT sCNl/eniy7hQGm46GwjgXJ3LF0I+ApsM2vS/DzPhml6rXJAcjQ+lBX4NP0lkim3ol0Zdyr BJlXUKq3zaUeeJOU90bDs/EYOoijaqM= From: Pauli Virtanen To: linux-bluetooth@vger.kernel.org Cc: Pauli Virtanen Subject: [PATCH RFC 6/6] Bluetooth: ISO: handle bound CIS cleanup via hci_conn Date: Thu, 27 Jul 2023 00:25:26 +0300 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Calling hci_conn_del in __iso_sock_close is invalid. It needs hdev->lock, but it cannot be acquired there due to lock ordering. Fix this by doing cleanup via hci_conn_drop. Return hci_conn with refcount 1 from hci_bind_cis and hci_connect_cis, so that the iso_conn always holds one reference. This also fixes refcounting when error handling. Since hci_conn_abort shall handle termination of connections in any state properly, we can handle BT_CONNECT socket state in the same way as BT_CONNECTED. Signed-off-by: Pauli Virtanen --- net/bluetooth/hci_conn.c | 5 +++++ net/bluetooth/iso.c | 14 +------------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index ba339a0eb851..33fbdc8e0748 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -1901,6 +1901,8 @@ struct hci_conn *hci_bind_cis(struct hci_dev *hdev, bdaddr_t *dst, return ERR_PTR(-EINVAL); } + hci_conn_hold(cis); + cis->iso_qos = *qos; cis->state = BT_BOUND; @@ -2254,6 +2256,9 @@ struct hci_conn *hci_connect_cis(struct hci_dev *hdev, bdaddr_t *dst, return ERR_PTR(-ENOLINK); } + /* Link takes the refcount */ + hci_conn_drop(cis); + cis->state = BT_CONNECT; hci_le_create_cis_pending(hdev); diff --git a/net/bluetooth/iso.c b/net/bluetooth/iso.c index cbe3299b4a41..358954bfbb32 100644 --- a/net/bluetooth/iso.c +++ b/net/bluetooth/iso.c @@ -628,6 +628,7 @@ static void __iso_sock_close(struct sock *sk) iso_sock_cleanup_listen(sk); break; + case BT_CONNECT: case BT_CONNECTED: case BT_CONFIG: if (iso_pi(sk)->conn->hcon) { @@ -643,19 +644,6 @@ static void __iso_sock_close(struct sock *sk) break; case BT_CONNECT2: - iso_chan_del(sk, ECONNRESET); - break; - case BT_CONNECT: - /* In case of DEFER_SETUP the hcon would be bound to CIG which - * needs to be removed so just call hci_conn_del so the cleanup - * callback do what is needed. - */ - if (test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags) && - iso_pi(sk)->conn->hcon) { - hci_conn_del(iso_pi(sk)->conn->hcon); - iso_pi(sk)->conn->hcon = NULL; - } - iso_chan_del(sk, ECONNRESET); break; case BT_DISCONN: -- 2.41.0