Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1613714ybj; Wed, 6 May 2020 01:50:50 -0700 (PDT) X-Google-Smtp-Source: APiQypLpdxTEIW+iq/oAPeB+bohoSV0pgSijME7mtory48U9jb1/eBqMAoFUh7vXXwJf4fdbUaDT X-Received: by 2002:a17:906:1cd5:: with SMTP id i21mr6242673ejh.251.1588755050227; Wed, 06 May 2020 01:50:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588755050; cv=none; d=google.com; s=arc-20160816; b=xu4PvtWqybHt83e94MvWEynhjXKZ7b3alOSNjAmqPRMq+Ej9nbIZaP5FOEWoN/ObUx hiMo4RsAMamrDm5e6sNZ6WZVCamUKLHYy4+KkBbOr2WJ7W2NRn4rFmtpX/kIvSzSw0qg O8y4DZI+fDCuIW+WHxrV4WVgVg68zBUsgRfpATFvOV+MzNKXbTEPun9PNgGcUIG1+d4e BfsiUPRz9nYzT9TBLOa/goaqkVT593wVBZ/TKud+uN3icuAcMRWmxpTTpnbY0HN/gNCM 9sGS+jY6OYaFFYrJdMXKB9021btCON7y7HZWKaO0Y2tA+tg8/BzqmNkbnwgp3Lc9XWyb m6Sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version; bh=YmeREIDFSgjgkwW9qvZYYtzCvfbTxwdOOqjrde8j6tY=; b=oqx32xSvFa33fFJJq7/fx+eVui+3wjW4lGBbPgTTVqvpf7mappFQdt0osjm9sufpRX Ve0bWS+J7uU+3KGdXlTC2IrEfERfVasuwjSazy2kYjix6SAPTfQ8ZulHHBRa9CjZ3D+u 3iqUwKXI8j8hLiLmUoknFDc2JvJ6YPo0aeUsAhOerZrbKPCFcnWL1OmoFMnh7r6bu6rC xnOsaaMnQomb7B3/7MhUEbmzcQxqgtvvz15ByDRrqDuh1J69qMjopJUs8fElxrz5Dp08 J1IZz2h3ISaJjDuY6ueX5bYgJXwbxVNkSFYki9YOaqGzxyWfAV8MqjpjohulI5dCj0GY abow== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id fi25si791960ejb.25.2020.05.06.01.50.09; Wed, 06 May 2020 01:50:50 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728954AbgEFIr5 convert rfc822-to-8bit (ORCPT + 99 others); Wed, 6 May 2020 04:47:57 -0400 Received: from coyote.holtmann.net ([212.227.132.17]:42918 "EHLO mail.holtmann.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728884AbgEFIr5 (ORCPT ); Wed, 6 May 2020 04:47:57 -0400 Received: from marcel-macbook.fritz.box (p4FEFC5A7.dip0.t-ipconnect.de [79.239.197.167]) by mail.holtmann.org (Postfix) with ESMTPSA id 18A44CED01; Wed, 6 May 2020 10:57:37 +0200 (CEST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\)) Subject: Re: [PATCH] Bluetooth: Avoid calling device_add() on duplicated HCI conn event From: Marcel Holtmann In-Reply-To: <20200506025358.361519-1-olivier.crete@collabora.com> Date: Wed, 6 May 2020 10:47:55 +0200 Cc: linux-bluetooth , Johan Hedberg Content-Transfer-Encoding: 8BIT Message-Id: <0858E407-99A0-4EF7-B890-B367B206F4AD@holtmann.org> References: <20200506025358.361519-1-olivier.crete@collabora.com> To: =?utf-8?Q?Olivier_Cr=C3=AAte?= X-Mailer: Apple Mail (2.3608.80.23.2.2) Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Olivier, > The BCM20702A1 device in the ThinkPad x230 seems to send the HCI > Connection Complete event twice for the same connection, for which the > stack seems to recover, except for the core device_add() function > which is not meant to be called twice for the same device. So let's > just avoid calling it in that case. > > BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=204633 > Signed-off-by: Olivier CrĂȘte > Cc: stable@vger.kernel.org please include the btmon output showing this issue. And there is no firmware update available for the Bluetooth controller in the ThinkPad. Most Broadcom devices require an actual firmware load to fix bugs. Does your device load firmware? > --- > include/net/bluetooth/hci_core.h | 3 +++ > net/bluetooth/hci_conn.c | 1 + > net/bluetooth/hci_event.c | 8 ++++++-- > 3 files changed, 10 insertions(+), 2 deletions(-) > > diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h > index d4e28773d378..b74669397dbb 100644 > --- a/include/net/bluetooth/hci_core.h > +++ b/include/net/bluetooth/hci_core.h > @@ -500,6 +500,9 @@ struct hci_dev { > > #define HCI_PHY_HANDLE(handle) (handle & 0xff) > > +/* Valid HCI handles are in the 0x0000-0x0EFF range per spec */ > +#define HCI_INVALID_HANDLE 0xFFFF > + > struct hci_conn { > struct list_head list; > > diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c > index e245bc155cc2..edf12a3f46aa 100644 > --- a/net/bluetooth/hci_conn.c > +++ b/net/bluetooth/hci_conn.c > @@ -532,6 +532,7 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst, > conn->rssi = HCI_RSSI_INVALID; > conn->tx_power = HCI_TX_POWER_INVALID; > conn->max_tx_power = HCI_TX_POWER_INVALID; > + conn->handle = HCI_INVALID_HANDLE; > > set_bit(HCI_CONN_POWER_SAVE, &conn->flags); > conn->disc_timeout = HCI_DISCONN_TIMEOUT; > diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c > index 0a591be8b0ae..e498f70fcda9 100644 > --- a/net/bluetooth/hci_event.c > +++ b/net/bluetooth/hci_event.c > @@ -2553,6 +2553,8 @@ static void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) > } > > if (!ev->status) { > + int first_connection = (conn->handle == HCI_INVALID_HANDLE); > + We have the type bool available for these kind of things. > conn->handle = __le16_to_cpu(ev->handle); > > if (conn->type == ACL_LINK) { > @@ -2567,8 +2569,10 @@ static void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) > } else > conn->state = BT_CONNECTED; > > - hci_debugfs_create_conn(conn); > - hci_conn_add_sysfs(conn); > + if (first_connection) { > + hci_debugfs_create_conn(conn); > + hci_conn_add_sysfs(conn); > + } > > if (test_bit(HCI_AUTH, &hdev->flags)) > set_bit(HCI_CONN_AUTH, &conn->flags); Regards Marcel