Stable Archive on
 help / color / Atom feed
From: Samuel Holland <>
To: Marcel Holtmann <>,
	Johan Hedberg <>
Cc: Hans de Goede <>,,,
	Samuel Holland <>,
Subject: [PATCH 2/2] Bluetooth: hci_serdev: Fix crash with HCI_UART_INIT_PENDING
Date: Sat,  1 Aug 2020 10:43:46 -0500
Message-ID: <> (raw)
In-Reply-To: <>

When using HCI_UART_INIT_PENDING, hci_register_dev is not called from
hci_uart_register_device. Instead, it is called by hci_uart_init_work,
which is enqueued by hci_uart_init_ready (as hu->init_ready). In the
case of the hci_h5 proto, hci_uart_init_ready is called only after
handshaking with the hardware. If that handshake never completes,
hci_register_dev is never called. When later unregistering the device,
the kernel crashes:

  Unable to handle kernel write to read-only memory at virtual address 0000000000000008
  Internal error: Oops: 96000045 [#1] PREEMPT SMP
  Modules linked in: hci_uart(-) btrtl bnep bluetooth 8723cs(C) [...]
  CPU: 3 PID: 516 Comm: rmmod Tainted: G         C        5.8.0-rc7-00277-gd87641cb644c-dirty #1
  Hardware name: Pine64 PinePhone Braveheart (1.1) (DT)
  pstate: 80400005 (Nzcv daif +PAN -UAO BTYPE=--)
  pc : hci_unregister_dev+0x58/0x4b0 [bluetooth]
  lr : hci_unregister_dev+0x54/0x4b0 [bluetooth]
  sp : ffffffc011b5bc60
  x29: ffffffc011b5bc60 x28: ffffff8075d23800
  x27: 0000000000000000 x26: 0000000000000000
  x25: 0000000000000000 x24: 0000000000000000
  x23: 0000000000000000 x22: ffffffc008d86000
  x21: ffffff8079dd2000 x20: ffffff8078026000
  x19: ffffffc008f4f6d0 x18: 0000000000000000
  x17: 0000000000000000 x16: 0000000000000000
  x15: 0000000000000004 x14: ffffff807b15c110
  x13: 0000000000000000 x12: ffffff80778e6720
  x11: ffffff80778e66c8 x10: ffffff807ac6ada2
  x9 : ffffffc010c95864 x8 : 0000000000210d00
  x7 : 0000000000000000 x6 : 0000000000000001
  x5 : 0000000000000001 x4 : 0000000000000001
  x3 : 0000000000000000 x2 : 0000000000000000
  x1 : 0000000000000000 x0 : 0000000000000000
  Call trace:
   hci_unregister_dev+0x58/0x4b0 [bluetooth]
   hci_uart_unregister_device+0x40/0x74 [hci_uart]
   h5_serdev_remove+0x18/0x20 [hci_uart]
   h5_deinit+0x14/0xd10 [hci_uart]
   hci_uart_exit+0xc/0x30 [hci_uart]
  Code: aa1303e0 79408297 95f69770 a9400682 (f9000441)
  ---[ end trace b68f9044c8f92379 ]---

Fix the crash by flushing the hu->init_ready work to ensure
hci_register_dev is not being called concurrently, and then only
calling hci_unregister_dev if the HCI was previously registered.

Fixes: fdee6d8fc630 ("Bluetooth: hci_serdev: Fix HCI_UART_INIT_PENDING not working")
Signed-off-by: Samuel Holland <>
 drivers/bluetooth/hci_serdev.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/bluetooth/hci_serdev.c b/drivers/bluetooth/hci_serdev.c
index 599855e4c57c..3977bba485c2 100644
--- a/drivers/bluetooth/hci_serdev.c
+++ b/drivers/bluetooth/hci_serdev.c
@@ -355,7 +355,10 @@ void hci_uart_unregister_device(struct hci_uart *hu)
 	struct hci_dev *hdev = hu->hdev;
 	clear_bit(HCI_UART_PROTO_READY, &hu->flags);
-	hci_unregister_dev(hdev);
+	cancel_work_sync(&hu->init_ready);
+	if (test_bit(HCI_UART_REGISTERED, &hu->flags))
+		hci_unregister_dev(hdev);

  reply index

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-01 15:43 [PATCH 1/2] Bluetooth: hci_h5: Stop erroneously setting HCI_UART_REGISTERED Samuel Holland
2020-08-01 15:43 ` Samuel Holland [this message]
2020-08-01 16:24 ` Samuel Holland

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Stable Archive on

Archives are clonable:
	git clone --mirror stable/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 stable stable/ \
	public-inbox-index stable

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone