Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1390486ybj; Tue, 5 May 2020 19:54:58 -0700 (PDT) X-Google-Smtp-Source: APiQypLmV6oTxeYSoT+blIOb4m5BHEAePJhVD8FY+R7XhXYInsyXkJYBjbhht41ftq3ODtRrpNt5 X-Received: by 2002:a17:907:392:: with SMTP id ss18mr3187161ejb.130.1588733698140; Tue, 05 May 2020 19:54:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588733698; cv=none; d=google.com; s=arc-20160816; b=Rn7UFLVwdRlaOgoBlSeFLHVJ+Wx9ngz0iE7owtipc3wGD6qzxcLt9Mue3fm9hVfZ/h 9L1Db/9Ge623sTbTY5pcjsP/1Db23OcbI6yDrIRsXAeSHy3ZfXIlzilpJcUZlCFDf6kD GO3qKiYCo8QE8FzGaGRaNHeDISBBr6NeILug8othoM20kT6/lW220VesrAncFVV+7X+e i886I9f298ARim4jcAWiw9R3YiJPRc8GSxJ1URwjNIUAOq8kKyCEi2Jk4HuVqXIduFFh 1807rOavB6t9/i070e7MKZlQPvonp3UrVBPc4oCiPOFnZyyyLZn+2G+5HtDn5jJ1lrXI iwJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=CcKDwqWoXF/VhPyzX3cBbb0yv3XQfl+TX28l4SUumxo=; b=rBFnVj+dOenLIsnCclE/hRot3I1QFpSv4W+xsks9JvW9C4rAd3SyCTYFjRBUFGHnbO oMGu7cZAz6ei9UiokNZTmGT1qip1br3e0ou9Ku2yJDGf/Uinm45SPYJoQYjfx4QKGhEl EU6sDBpN9zZXHOc3RYU13h9yWM9wSPCqj3D/wXE/pqSMObUNQG1OrQYNlD6ZPxSAHJzB nyL2PU/ALqlGFl4Vto12L8Afb37ztOS0ijVcXgWNQur4mXjDyQppMsQZPt5SKZXMEw9u 5Dsg8ajk3bSfv/M6JjF3GYOubjN95Azt42CV/cwzsROs9w14uRXfZgbCYHmyHHzzJ0im LbLA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rs10si344303ejb.288.2020.05.05.19.54.17; Tue, 05 May 2020 19:54:58 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726516AbgEFCyK (ORCPT + 99 others); Tue, 5 May 2020 22:54:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726308AbgEFCyK (ORCPT ); Tue, 5 May 2020 22:54:10 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39F93C061A41 for ; Tue, 5 May 2020 19:54:10 -0700 (PDT) Received: from localhost.localdomain (unknown [IPv6:2607:f2c0:f00e:4a00:e12:aed3:7421:b166]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: tester) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id B0FC42A0662; Wed, 6 May 2020 03:54:07 +0100 (BST) From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= To: linux-bluetooth@vger.kernel.org Cc: Marcel Holtmann , Johan Hedberg Subject: [PATCH] Bluetooth: Avoid calling device_add() on duplicated HCI conn event Date: Tue, 5 May 2020 22:53:58 -0400 Message-Id: <20200506025358.361519-1-olivier.crete@collabora.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org 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 --- 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); + 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); -- 2.26.2