Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp7114441rwr; Tue, 2 May 2023 09:38:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5ubIBQYfjYqPQsxjUe7eQCn8/wf7qlsOfPgSpKqhJWJPakbb9fGYlJMjVJDaD9LaFIaSjl X-Received: by 2002:a17:902:d2c5:b0:1a9:5ee9:71e0 with SMTP id n5-20020a170902d2c500b001a95ee971e0mr22824420plc.0.1683045503535; Tue, 02 May 2023 09:38:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683045503; cv=none; d=google.com; s=arc-20160816; b=jNE9+NPJNcVcOEHl4rZbFqhxxWGyDoAKEoLP2CDL5AQ1ho/BbyA4xlufTHER02lD+b dq6Yl3cQ9rwRay47OtMkvZS2bWE2gmZriktLxgjV1YCObeieCIUNvnAAbLsxHbSepJd/ yHT9w8mnlRK6GvRlh/qE53yvE3jUNIg2IxbxHgkso7jTmttDkreY2b4lWBoOqGGwCLVS 8fMZ8wi++xZ4nMmsSbKuL7IEJdqNLef65eZTkIJyJ3I/asbrlGdbKsQq1hcFhNhikumO hyxRtCzHNl+mXoPPydIlJ0+7Es84k3MNr8zdlTiJDWq027GZgXLKj8Qy8FiRg3jCs/kP Ic7w== 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=dWvsqDOsA3cc53eqEMTqO0Umsf+DzK5drqWkHB4m/4o=; b=iCrmAg8fMwJQ9tJDIn+mhNp3GztWAymn7QMdrG2LZ1PX7g0mb1PySq0VMJ7S3dvT6w eKsQDlfC/i4rOKzWVm0lK0goEZtoogFIGEpAugeMhTWPf4PI3LKII2q33/dsz2EusXf/ fzGgXJhqkOkPfnGWUkTGiXbgMnAw58bXSBinRLjze+oN+f1tfsNcLAyNKUNgPmxQFyJZ o9XN7Hub+jhPUzPYuu80C1ERGGD04gn7SUaG/IYn4BToXerDk5pZ2Ni7xGYWWvG00ged QVqBBN+4o/h7duzVe8WXIju9cBRdvwRclCxOpamH3ZjdNB2UqEB0wJcE5F+/2xjk2Zdn 1fTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=qNEK5tIi; 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 t6-20020a170902e84600b001a647aadbe0si32880279plg.568.2023.05.02.09.38.09; Tue, 02 May 2023 09:38:23 -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=qNEK5tIi; 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 S233862AbjEBQSX (ORCPT + 99 others); Tue, 2 May 2023 12:18:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233854AbjEBQSW (ORCPT ); Tue, 2 May 2023 12:18:22 -0400 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0BBC1984 for ; Tue, 2 May 2023 09:18:16 -0700 (PDT) Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-2ab25e8a4a7so39674261fa.3 for ; Tue, 02 May 2023 09:18:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683044295; x=1685636295; 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=dWvsqDOsA3cc53eqEMTqO0Umsf+DzK5drqWkHB4m/4o=; b=qNEK5tIipJNrkEtGDdEo9T1W2ntjbW25tCK28xLU2cRJl4quIta71fsj6zAlgUO1fx 3gu6GB4opc7IaW33WcWLCv9DDmR8OWeVp9G9E7V3OY8mpGlltRom5dV4AuL1myRM9q1R 5tRRYrMyNYQvbbKb5Uq57s/GAaB+4m8oDIOTcqMzs83IIlePKwxQUR3uovQEf3otRMaU YHsgf031s1VGRzdx22zL8QtCpEu16ztu94aS56CQOTiyIjdPREQpuTnVKCvQeFgR4ffL 2XFxnfGPdMvwNc7+n4r/LoreXTmvi10xjse9y2L9ftfMRunZzWURQiJ5IzgA72VeofR6 /lyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683044295; x=1685636295; 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=dWvsqDOsA3cc53eqEMTqO0Umsf+DzK5drqWkHB4m/4o=; b=mAYS6aapYD3eHj0wcogsA8rvcZ+MC4OW9z81xe7kxn3NBVqxafznG9i+TtYKpFmJgI WXFkJxwvcfC36tjGLDZzqXtKycjyJsKj3g0PPG0R+RwWP3nUfEiaXMhsf7LMbi/VHG8E xW61mFwulOyHuDz/gEesujc5W7VWTrH8W8AOLW7d5kJYZULoVFxlTGJqFk/O17p2GOHC LfR6/cyGU7gPaHRi6F2n3h77/kYXlw8uAPU8p1QtpA5/ffEcmdl+Y5On6KWU3lVialsC 09z87HG9nV6vtZitmSwPkhFYBnJLQaH+W0EvveS+Z2yzo0GEKCgkclfsR26Fke0ShOkN rH+A== X-Gm-Message-State: AC+VfDyYKuOR8s0JfOyRPVRXbJZuP88O0papdQ0vLJgpQISH5vi7t9sW 1NTRZGDl/AVFljr+DsXcmTQnoATyE4rAkhdD0bpDXtX0 X-Received: by 2002:a2e:97c4:0:b0:2a8:ca28:e4e with SMTP id m4-20020a2e97c4000000b002a8ca280e4emr4871599ljj.24.1683044294683; Tue, 02 May 2023 09:18:14 -0700 (PDT) MIME-Version: 1.0 References: <20230502145737.140856-1-lrh2000@pku.edu.cn> <20230502145737.140856-7-lrh2000@pku.edu.cn> In-Reply-To: <20230502145737.140856-7-lrh2000@pku.edu.cn> From: Luiz Augusto von Dentz Date: Tue, 2 May 2023 09:18:02 -0700 Message-ID: Subject: Re: [PATCH v3 6/6] Bluetooth: Avoid recursion 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= : > > Previously, hci_conn_unlink was implemented as a recursion function. To > unlink physical connections (e.g. ACL/LE), it calls itself to unlink all > its logical channels (e.g. SCO/eSCO/ISO). > > Recursion is not required. This patch refactors hci_conn_unlink into two > functions, where hci_conn_unlink_parent takes a physical connection, > checks out all its logical channels, and calls hci_conn_unlink_child for > each logical channel to unlink it. > > Signed-off-by: Ruihan Li > --- > net/bluetooth/hci_conn.c | 55 +++++++++++++++++++++++----------------- > 1 file changed, 32 insertions(+), 23 deletions(-) > > diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c > index de553e062..243d68a64 100644 > --- a/net/bluetooth/hci_conn.c > +++ b/net/bluetooth/hci_conn.c > @@ -1074,34 +1074,13 @@ struct hci_conn *hci_conn_add(struct hci_dev *hde= v, int type, bdaddr_t *dst, > return conn; > } > > -static void hci_conn_unlink(struct hci_conn *conn) > +static void hci_conn_unlink_parent(struct hci_conn *conn) > { > struct hci_dev *hdev =3D conn->hdev; > > bt_dev_dbg(hdev, "hcon %p", conn); > > - if (!conn->parent) { > - struct hci_link *link, *t; > - > - list_for_each_entry_safe(link, t, &conn->link_list, list)= { > - struct hci_conn *child =3D link->conn; > - > - hci_conn_unlink(child); > - > - /* Due to race, SCO connection might be not estab= lished > - * yet at this point. Delete it now, otherwise it= is > - * possible for it to be stuck and can't be delet= ed. > - */ > - if ((child->type =3D=3D SCO_LINK || > - child->type =3D=3D ESCO_LINK) && > - child->handle =3D=3D HCI_CONN_HANDLE_UNSET) > - hci_conn_del(child); > - } > - > - return; > - } > - > - if (!conn->link) > + if (WARN_ON(!conn->link)) > return; > > list_del_rcu(&conn->link->list); > @@ -1115,6 +1094,36 @@ static void hci_conn_unlink(struct hci_conn *conn) > conn->link =3D NULL; > } > > +static void hci_conn_unlink_children(struct hci_conn *conn) > +{ > + struct hci_dev *hdev =3D conn->hdev; > + struct hci_link *link, *t; > + > + bt_dev_dbg(hdev, "hcon %p", conn); > + > + list_for_each_entry_safe(link, t, &conn->link_list, list) { > + struct hci_conn *child =3D link->conn; > + > + hci_conn_unlink_parent(child); > + > + /* Due to race, SCO connection might be not established > + * yet at this point. Delete it now, otherwise it is > + * possible for it to be stuck and can't be deleted. > + */ > + if (child->type =3D=3D SCO_LINK || child->type =3D=3D ESC= O_LINK) > + if (child->handle =3D=3D HCI_CONN_HANDLE_UNSET) > + hci_conn_del(child); > + } This is not quite right, when we are unlinking the children's hci_conn it shall only unlink itself from the parent not everything. > +} > + > +static void hci_conn_unlink(struct hci_conn *conn) > +{ > + if (conn->parent) > + hci_conn_unlink_parent(conn); > + else > + hci_conn_unlink_children(conn); > +} > + > void hci_conn_del(struct hci_conn *conn) > { > struct hci_dev *hdev =3D conn->hdev; > -- > 2.40.0 > --=20 Luiz Augusto von Dentz