From 812fdf7afaebdfe9acc34d1c1c816c42870a2eba Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Apr 20 2023 11:00:30 +0000 Subject: Bluetooth: Fix printing errors if LE Connection times out (bsc#1012628). --- diff --git a/patches.kernel.org/6.2.12-057-Bluetooth-Fix-printing-errors-if-LE-Connection.patch b/patches.kernel.org/6.2.12-057-Bluetooth-Fix-printing-errors-if-LE-Connection.patch new file mode 100644 index 0000000..cd7310b --- /dev/null +++ b/patches.kernel.org/6.2.12-057-Bluetooth-Fix-printing-errors-if-LE-Connection.patch @@ -0,0 +1,150 @@ +From: Luiz Augusto von Dentz +Date: Fri, 24 Mar 2023 13:18:20 -0700 +Subject: [PATCH] Bluetooth: Fix printing errors if LE Connection times out +References: bsc#1012628 +Patch-mainline: 6.2.12 +Git-commit: b62e72200eaad523f08d8319bba50fc652e032a8 + +[ Upstream commit b62e72200eaad523f08d8319bba50fc652e032a8 ] + +This fixes errors like bellow when LE Connection times out since that +is actually not a controller error: + + Bluetooth: hci0: Opcode 0x200d failed: -110 + Bluetooth: hci0: request failed to create LE connection: err -110 + +Instead the code shall properly detect if -ETIMEDOUT is returned and +send HCI_OP_LE_CREATE_CONN_CANCEL to give up on the connection. + +Link: https://github.com/bluez/bluez/issues/340 +Fixes: 8e8b92ee60de ("Bluetooth: hci_sync: Add hci_le_create_conn_sync") +Signed-off-by: Luiz Augusto von Dentz +Signed-off-by: Sasha Levin +Signed-off-by: Jiri Slaby +--- + include/net/bluetooth/hci_core.h | 1 + + net/bluetooth/hci_conn.c | 7 +++++-- + net/bluetooth/hci_event.c | 16 ++++++---------- + net/bluetooth/hci_sync.c | 13 ++++++++++--- + 4 files changed, 22 insertions(+), 15 deletions(-) + +diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h +index 7254edfb..ffb89b98 100644 +--- a/include/net/bluetooth/hci_core.h ++++ b/include/net/bluetooth/hci_core.h +@@ -954,6 +954,7 @@ enum { + HCI_CONN_STK_ENCRYPT, + HCI_CONN_AUTH_INITIATOR, + HCI_CONN_DROP, ++ HCI_CONN_CANCEL, + HCI_CONN_PARAM_REMOVAL_PEND, + HCI_CONN_NEW_LINK_KEY, + HCI_CONN_SCANNING, +diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c +index 6fbc1fe7..bd38e36e 100644 +--- a/net/bluetooth/hci_conn.c ++++ b/net/bluetooth/hci_conn.c +@@ -1245,6 +1245,8 @@ static void create_le_conn_complete(struct hci_dev *hdev, void *data, int err) + { + struct hci_conn *conn = data; + ++ bt_dev_dbg(hdev, "err %d", err); ++ + hci_dev_lock(hdev); + + if (!err) { +@@ -1252,8 +1254,6 @@ static void create_le_conn_complete(struct hci_dev *hdev, void *data, int err) + goto done; + } + +- bt_dev_err(hdev, "request failed to create LE connection: err %d", err); +- + /* Check if connection is still pending */ + if (conn != hci_lookup_le_connect(hdev)) + goto done; +@@ -2787,6 +2787,9 @@ int hci_abort_conn(struct hci_conn *conn, u8 reason) + { + int r = 0; + ++ if (test_and_set_bit(HCI_CONN_CANCEL, &conn->flags)) ++ return 0; ++ + switch (conn->state) { + case BT_CONNECTED: + case BT_CONFIG: +diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c +index ad92a4be..e68f2a7d 100644 +--- a/net/bluetooth/hci_event.c ++++ b/net/bluetooth/hci_event.c +@@ -2881,16 +2881,6 @@ static void cs_le_create_conn(struct hci_dev *hdev, bdaddr_t *peer_addr, + + conn->resp_addr_type = peer_addr_type; + bacpy(&conn->resp_addr, peer_addr); +- +- /* We don't want the connection attempt to stick around +- * indefinitely since LE doesn't have a page timeout concept +- * like BR/EDR. Set a timer for any connection that doesn't use +- * the accept list for connecting. +- */ +- if (filter_policy == HCI_LE_USE_PEER_ADDR) +- queue_delayed_work(conn->hdev->workqueue, +- &conn->le_conn_timeout, +- conn->conn_timeout); + } + + static void hci_cs_le_create_conn(struct hci_dev *hdev, u8 status) +@@ -5902,6 +5892,12 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status, + if (status) + goto unlock; + ++ /* Drop the connection if it has been aborted */ ++ if (test_bit(HCI_CONN_CANCEL, &conn->flags)) { ++ hci_conn_drop(conn); ++ goto unlock; ++ } ++ + if (conn->dst_type == ADDR_LE_DEV_PUBLIC) + addr_type = BDADDR_LE_PUBLIC; + else +diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c +index 5a6aa162..632be126 100644 +--- a/net/bluetooth/hci_sync.c ++++ b/net/bluetooth/hci_sync.c +@@ -246,8 +246,9 @@ int __hci_cmd_sync_status_sk(struct hci_dev *hdev, u16 opcode, u32 plen, + + skb = __hci_cmd_sync_sk(hdev, opcode, plen, param, event, timeout, sk); + if (IS_ERR(skb)) { +- bt_dev_err(hdev, "Opcode 0x%4x failed: %ld", opcode, +- PTR_ERR(skb)); ++ if (!event) ++ bt_dev_err(hdev, "Opcode 0x%4x failed: %ld", opcode, ++ PTR_ERR(skb)); + return PTR_ERR(skb); + } + +@@ -5126,8 +5127,11 @@ static int hci_le_connect_cancel_sync(struct hci_dev *hdev, + if (test_bit(HCI_CONN_SCANNING, &conn->flags)) + return 0; + ++ if (test_and_set_bit(HCI_CONN_CANCEL, &conn->flags)) ++ return 0; ++ + return __hci_cmd_sync_status(hdev, HCI_OP_LE_CREATE_CONN_CANCEL, +- 6, &conn->dst, HCI_CMD_TIMEOUT); ++ 0, NULL, HCI_CMD_TIMEOUT); + } + + static int hci_connect_cancel_sync(struct hci_dev *hdev, struct hci_conn *conn) +@@ -6102,6 +6106,9 @@ int hci_le_create_conn_sync(struct hci_dev *hdev, struct hci_conn *conn) + conn->conn_timeout, NULL); + + done: ++ if (err == -ETIMEDOUT) ++ hci_le_connect_cancel_sync(hdev, conn); ++ + /* Re-enable advertising after the connection attempt is finished. */ + hci_resume_advertising_sync(hdev); + return err; +-- +2.35.3 + diff --git a/series.conf b/series.conf index 067f766..69a3821 100644 --- a/series.conf +++ b/series.conf @@ -2284,6 +2284,7 @@ patches.kernel.org/6.2.12-054-iavf-remove-active_cvlans-and-active_svlans-bi.patch patches.kernel.org/6.2.12-055-net-openvswitch-fix-race-on-port-output.patch patches.kernel.org/6.2.12-056-Bluetooth-hci_conn-Fix-not-cleaning-up-on-LE-C.patch + patches.kernel.org/6.2.12-057-Bluetooth-Fix-printing-errors-if-LE-Connection.patch ######################################################## # Build fixes that apply to the vanilla kernel too.