Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6991108rwr; Tue, 2 May 2023 08:07:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5pzVX1oHprAnLdQvy9OiBLgWgRLxdE7LfO4rlA9KGVgv4eZ9aK9R/gokhoXgqxyxwrd056 X-Received: by 2002:a05:6a20:4327:b0:f0:65fb:6cec with SMTP id h39-20020a056a20432700b000f065fb6cecmr26852591pzk.8.1683040040119; Tue, 02 May 2023 08:07:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683040040; cv=none; d=google.com; s=arc-20160816; b=EGvsndy886empYYlKBKUvuz/zXYlzzUSGjVrL0U3Gra2aIXZjCzSC/+hJwL5qiqMSd u8etgKW97/uRTuugG85FCh9sn+d/NgakBu24V8DBWtxdUPidSD/CfYPclP1MylMFJylI cmDqGNYnN939oDXKUiJOSG4VymxZ83zjqc+ENM4/ZPOK2cQly8KmhFBHCKlrHqj6vKMh T0MqFGz/aWXWsml4XgTG+TYBeH/nrUdnIy5Kg5tcFupP4LhD84y3qZeejF2kiOpWygTz RDL2e0ttebLogjtz3UoCsCPaDbC/Dbc+Nh5Au4v0/f0vYIjaKJEkHBkY9GRBXF+uKT+A BRYg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HxCd4rFmxpf8MfjsXA8dHp1Xyd+DZGMT1Hr7aQFCMrA=; b=iVNRiYPNNEZo5A3IUZNBMRRtl0suR9acRgn+6zcTJRr27bcZ9ff8Q86ZzIli8kI7nq 2J44Yye7bDxSyiM/qfnYSkf+1pqnjAQI0dIxf3F3JIK/Wt0/zcMYPZyn2/1CWGwtnKBS xTO5ipQbgIZO7UI+CuSho334VrnHJfVtckK6kJRNPctQch+S/2QigWkYVO8vJ8tMyfvL wz0mp+zHpQaLHVMkPMcmRyZqbhHEGBHtCeFYPjze/DFHjonKjsMUONNwwfnrbYl3wFx0 OGHqh4/+hTv1EBKGZH/u1AHytIGoJryvhW4iE+2b/SCF6uCNPHvlqU/lMYI9px/Bnsnm x5pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@pku.edu.cn header.s=dkim header.b=epzL2WH+; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=pku.edu.cn Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f10-20020a65628a000000b00520603e8e25si30781172pgv.67.2023.05.02.08.06.40; Tue, 02 May 2023 08:07:20 -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 (test mode) header.i=@pku.edu.cn header.s=dkim header.b=epzL2WH+; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=pku.edu.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234525AbjEBO6I (ORCPT + 99 others); Tue, 2 May 2023 10:58:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234187AbjEBO6B (ORCPT ); Tue, 2 May 2023 10:58:01 -0400 Received: from pku.edu.cn (mx18.pku.edu.cn [162.105.129.181]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CD9962723 for ; Tue, 2 May 2023 07:57:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pku.edu.cn; s=dkim; h=Received:From:To:Cc:Subject:Date: Message-Id:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=HxCd4rFmxpf8MfjsXA8dHp1Xyd+DZGMT1H r7aQFCMrA=; b=epzL2WH+Ohcrpl9r2IjoNk68zWNUJ4I1S1L/rm+dGXp86Zwjl7 kQKrwWLvsOrTyBQu65+hI28oNNzDuSRPZV9AFq733/A0psdtg2l43FoLaR8u095n dplnxVItw7NhNsqSQg8Wticf01g9bw+dLkcCpUc54BZ1ppfOFSFCZFKK0= Received: from localhost.localdomain (unknown [10.7.101.92]) by front01 (Coremail) with SMTP id 5oFpogBXX5fjJFFk6i5LAQ--.10226S6; Tue, 02 May 2023 22:57:48 +0800 (CST) From: Ruihan Li To: linux-bluetooth@vger.kernel.org Cc: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , Ruihan Li Subject: [PATCH v3 4/6] Bluetooth: Perform hci_conn_drop in hci_conn_unlink Date: Tue, 2 May 2023 22:57:35 +0800 Message-Id: <20230502145737.140856-5-lrh2000@pku.edu.cn> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230502145737.140856-1-lrh2000@pku.edu.cn> References: <20230502145737.140856-1-lrh2000@pku.edu.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: 5oFpogBXX5fjJFFk6i5LAQ--.10226S6 X-Coremail-Antispam: 1UD129KBjvJXoW7trykKF4xuw1DCr1UAw4xWFg_yoW8KF4Dpa 4Y934UXa1kJrZ09Fn2kr4kXFnYqr1DAFy7tr18Jr18Jws5tr1jyw4SkF18Kr45ZrWkJF1x ZF4jqr1IgF1UGr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9j1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s1l1IIY67AE w4v_Jr0_Jr4l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2 IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM28EF7xvwVC2 z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2vYz4IE04k24V AvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xf McIj6xIIjxv20xvE14v26r106r15McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7 v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxkIecxEwVCm -wCF04k20xvY0x0EwIxGrwCF04k20xvE74AGY7Cv6cx26w4UJr1UMxC20s026xCaFVCjc4 AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE 17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMI IF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4l IxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvf C2KfnxnUUI43ZEXa7VU1c4S5UUUUU== X-CM-SenderInfo: yssqiiarrvmko6sn3hxhgxhubq/1tbiAgETBVPy77xtrQAAsn X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,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 Since hci_conn_link invokes both hci_conn_get and hci_conn_hold, hci_conn_unlink should perform both hci_conn_put and hci_conn_drop as well. However, currently it performs only hci_conn_put. This patch makes hci_conn_unlink call hci_conn_drop as well, which simplifies the logic in hci_conn_del a bit and may benefit future users of hci_conn_unlink. But it is noted that this change additionally implies that hci_conn_unlink can queue disc_work on conn itself, with the following call stack: hci_conn_unlink(conn) [conn->parent == NULL] -> hci_conn_unlink(child) [child->parent == conn] -> hci_conn_drop(child->parent) -> queue_delayed_work(&conn->disc_work) Queued disc_work after hci_conn_del can be spurious, so during the process of hci_conn_del, it is necessary to make the call to cancel_delayed_work(&conn->disc_work) after invoking hci_conn_unlink. Signed-off-by: Ruihan Li --- net/bluetooth/hci_conn.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index eef148291..e76ebb50d 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -1105,6 +1105,7 @@ static void hci_conn_unlink(struct hci_conn *conn) list_del_rcu(&conn->link->list); synchronize_rcu(); + hci_conn_drop(conn->parent); hci_conn_put(conn->parent); conn->parent = NULL; @@ -1118,7 +1119,6 @@ void hci_conn_del(struct hci_conn *conn) BT_DBG("%s hcon %p handle %d", hdev->name, conn, conn->handle); - cancel_delayed_work_sync(&conn->disc_work); cancel_delayed_work_sync(&conn->auto_accept_work); cancel_delayed_work_sync(&conn->idle_work); @@ -1134,12 +1134,7 @@ void hci_conn_del(struct hci_conn *conn) else hdev->acl_cnt += conn->sent; } else { - struct hci_conn *acl = conn->parent; - - if (acl) { - hci_conn_unlink(conn); - hci_conn_drop(acl); - } + hci_conn_unlink(conn); /* Unacked ISO frames */ if (conn->type == ISO_LINK) { @@ -1152,6 +1147,11 @@ void hci_conn_del(struct hci_conn *conn) } } + /* hci_conn_unlink may trigger additional disc_work, so + * ensure to perform cancelling after that. + */ + cancel_delayed_work_sync(&conn->disc_work); + if (conn->amp_mgr) amp_mgr_put(conn->amp_mgr); -- 2.40.0