Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp7112203rwr; Tue, 2 May 2023 09:36:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5II67lpN/71pqHiCrZjwDY6YSd//hvcKg81lihWovIbEEC+vawnEnvWh7GTiQRKndgBEsf X-Received: by 2002:a17:902:c412:b0:19f:3234:fec5 with SMTP id k18-20020a170902c41200b0019f3234fec5mr22804797plk.51.1683045388597; Tue, 02 May 2023 09:36:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683045388; cv=none; d=google.com; s=arc-20160816; b=IoiUK9zbW83UTACVm9TMK1T6I0B9rzULmihVMpcX+HPlyRnTvGuDf0QFxSNGzXrsdn jZGED+KQ1x1q6czDijoPXShScFIFs9G7F/HIbxRUqAN7pARh/BMv7WjeeI0akgzfdBU8 R+LOgcv4Sb4rMDBGL1pCauW4EomNDj/y+VsqgMFJzFsJeRyNQ+6+KYq1J5Sug0JLHpPQ MsiffGWbdRnl/mS+ymOJuuQjvGbs5shG4cJLx/+T/UVinM7iN8E3wAuaZmiM5d8DP2F1 pimmowMkChyb7jW81q7o5pyvqXakDF0YYsCowovakSkT6vniDix99aWnPGFWkyR6F8li uVZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=b/NXhqQM3SFvQn4lhet+X4fvOmMKReAyLzS7MIS5Ql4=; b=sOpL5QVWH9BFPAqL/1Gq23RkZ831TvWrua3/Ny4TK8Bhs1xSa34xI9mZQrsT3Tlz/j pXgfvEkfaO9O42Yx1HFzSVhBJseftuOu/yHNOVX7+4qoFJCD5W0h7uSXRU+f2anrrjkl LyYV4GUQIGH6PLlOdIbofbgbr55+osEN9bCkqJnEZcTvDBpM/tHoO3RqjhP47nbLGm1m 2eDIYZ0Col+EtXe53U3i0qfsB08+E8tiHuEgtEU/i1xzWVGVXnHEU0+rfuUUs/ejAwVV wkssz18LAXyNqCV/0BTe36ZGI/v5V9bOTlJPJ/HUYQy+tXZBvnE8yANcs0dvijh/M3++ QwDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=ZjkRQlsa; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e14-20020a170902784e00b001a51cc721b8si27978141pln.327.2023.05.02.09.36.05; Tue, 02 May 2023 09:36:28 -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=@gmail.com header.s=20221208 header.b=ZjkRQlsa; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233969AbjEBQWn (ORCPT + 99 others); Tue, 2 May 2023 12:22:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229457AbjEBQWl (ORCPT ); Tue, 2 May 2023 12:22:41 -0400 Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8343410D8 for ; Tue, 2 May 2023 09:22:17 -0700 (PDT) Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2a8bbea12d7so40309351fa.3 for ; Tue, 02 May 2023 09:22:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683044536; x=1685636536; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=b/NXhqQM3SFvQn4lhet+X4fvOmMKReAyLzS7MIS5Ql4=; b=ZjkRQlsarJpsbU9NHzhM0OWQtArlbzDDZVFu636WrWBC/E9FkDqG7akU30+XE4TbmM xyOjOncjmM5IVfYPzr6WX0xzNj60bEYBTi51Ptw4VgRK7K4f4PU7nimTXtrVVEf1jc61 tzCjygAFAeFETa71QSj5moUTVt2YYZ5//vDKyjD/bSF/So5O8hsrkA+BOTa6WbdPVtC6 IP8q1wWOHe0MiEvSq1Y3BJZA2ea3C/orQS3PMcNXsX4JV0kC01EdTriDANJNl0LrZIZ3 o7RTy+fCMeRn7ARZDjuaMeL/Sj0Ex77PgVVAEfWQGy4nloynUjWE2G5uLgFGffXCgyYy 49Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683044536; x=1685636536; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=b/NXhqQM3SFvQn4lhet+X4fvOmMKReAyLzS7MIS5Ql4=; b=a7mhLc06G1FlG28n7In8E+sBdtaV276Ga0MJuxro+ldnBKJORMwZw5lW+AwQGc1EJ2 rxN/cqZgnsrNJnj3GgNaxNbJFFwzvxD6vRSgj3QgtkrD79wSH4AiaAseMwG/jdu3bC1h VhcbDNgfy/Zmjgu/RaMUgoTnsfZ21JLvdD5FMzxhUYgkqMsBemggY5FzYc3dvDXz5pML 5MdW9/hf0vsj1oubjw/O+vRpD77wczS3Kca7aF7ROLFwz0WFPe8oQNof9wagOeBqrbZC yHbbv3XvIbMZCJd5v9sAXYrEr/UQKO1Ro4kby44jWX8pWOCCw+DSqHKC13i7GCdv24lk FgTg== X-Gm-Message-State: AC+VfDyGgNy16l/z1KlJpjQd2t47fSGwOpEv8UDZFk3kE02v8tTl4Ryz GWYbGziT+FTip2EAgzEgQnJFVASgny8hsuDpSfM= X-Received: by 2002:ac2:5df0:0:b0:4eb:3021:3a8f with SMTP id z16-20020ac25df0000000b004eb30213a8fmr110205lfq.61.1683044535527; Tue, 02 May 2023 09:22:15 -0700 (PDT) MIME-Version: 1.0 References: <20230502145737.140856-1-lrh2000@pku.edu.cn> <20230502145737.140856-5-lrh2000@pku.edu.cn> In-Reply-To: <20230502145737.140856-5-lrh2000@pku.edu.cn> From: Luiz Augusto von Dentz Date: Tue, 2 May 2023 09:22:03 -0700 Message-ID: Subject: Re: [PATCH v3 4/6] Bluetooth: Perform hci_conn_drop in hci_conn_unlink To: Ruihan Li Cc: linux-bluetooth@vger.kernel.org, Marcel Holtmann , Johan Hedberg Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 Hi Ruihan, On Tue, May 2, 2023 at 7:57=E2=80=AFAM Ruihan Li wrote= : > > 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 =3D=3D NULL] > -> hci_conn_unlink(child) [child->parent =3D=3D 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 =3D 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 +=3D conn->sent; > } else { > - struct hci_conn *acl =3D conn->parent; > - > - if (acl) { > - hci_conn_unlink(conn); > - hci_conn_drop(acl); > - } > + hci_conn_unlink(conn); > > /* Unacked ISO frames */ > if (conn->type =3D=3D 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); Just merge the change where hci_conn_del calls hci_conn_unlink unconditionally so we don't have to do this change independently just to revert later. > if (conn->amp_mgr) > amp_mgr_put(conn->amp_mgr); > > -- > 2.40.0 > --=20 Luiz Augusto von Dentz