Skip to content

Instantly share code, notes, and snippets.

@diffficult
Last active April 1, 2024 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diffficult/21c5f3d41ae198695f55891da53ee561 to your computer and use it in GitHub Desktop.
Save diffficult/21c5f3d41ae198695f55891da53ee561 to your computer and use it in GitHub Desktop.
Patching Linux Kernel 6.8.2 to solve BT issues

foolproof step by step

  1. sudo pacman -Syu base-devel devtools. This will pull in the necessary dependencies to build Arch packages.
  2. pkgctl repo clone --protocol=https linux. This will grab the PKGBUILD for the linux package. There should now be a linux folder in your current directory.
  3. Visit https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=1c3366abdbe884 and download the patch by right-clicking the "patch" link next to the commit id and save as.
  4. Place the downloaded patch into the linux folder. It should be named d39a2734bf6221a1a4fe42eea1dd6a17f08ebf5b..1c3366abdbe884be62e5a7502b4db758aa3974c6.patch, but it really doesn't matter what you name it.
  5. Add that patch file name as another line in the source=() section. This tells the PKGBUILD to include the patch as a source file for the build.
  6. Add an extra 'SKIP' line as the last entry in both the sha256sums=() and b2sums=() sections. This tells makepkg to not do checksums on the patch file. You could use the sha256sum and b2sum commands on the patch file to generate those sums, but since you're manually downloading it, you don't really need to check it for validity.
  7. makepkg -Cs. Build the packages.
  8. You may run into some GPG key signing issues like I did. You'll need to add Greh Kroah -Hartman (kernel maintainer) and Jan Alexander Steffen's (Arch maintainer) keys. Locate keys with gpg2 --locate-keys [username]@kernel.org and add them using gpg --recv-keys <key id>. After you build, you can safely remove them if you want.
  9. After packages are built, they'll be in the linux folder. Install them with sudo pacman -U <pkgfile>

Source: https://www.reddit.com/r/archlinux/comments/1bpmpqp/anyone_bt_stopped_working_after_the_patch_today/kxgnflq/

From 1c3366abdbe884be62e5a7502b4db758aa3974c6 Mon Sep 17 00:00:00 2001
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Date: Tue, 26 Mar 2024 12:43:17 -0400
Subject: Bluetooth: hci_sync: Fix not checking error on
hci_cmd_sync_cancel_sync
hci_cmd_sync_cancel_sync shall check the error passed to it since it
will be propagated using req_result which is __u32 it needs to be
properly set to a positive value if it was passed as negative othertise
IS_ERR will not trigger as -(errno) would be converted to a positive
value.
Fixes: 63298d6e752f ("Bluetooth: hci_core: Cancel request on command timeout")
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Reported-and-tested-by: Thorsten Leemhuis <linux@leemhuis.info>
Closes: https://lore.kernel.org/all/08275279-7462-4f4a-a0ee-8aa015f829bc@leemhuis.info/
---
net/bluetooth/hci_core.c | 6 +++---
net/bluetooth/hci_sync.c | 5 ++++-
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 1690ae57a09db..a7028d38c1f5c 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -2874,7 +2874,7 @@ static void hci_cancel_cmd_sync(struct hci_dev *hdev, int err)
cancel_delayed_work_sync(&hdev->ncmd_timer);
atomic_set(&hdev->cmd_cnt, 1);
- hci_cmd_sync_cancel_sync(hdev, -err);
+ hci_cmd_sync_cancel_sync(hdev, err);
}
/* Suspend HCI device */
@@ -2894,7 +2894,7 @@ int hci_suspend_dev(struct hci_dev *hdev)
return 0;
/* Cancel potentially blocking sync operation before suspend */
- hci_cancel_cmd_sync(hdev, -EHOSTDOWN);
+ hci_cancel_cmd_sync(hdev, EHOSTDOWN);
hci_req_sync_lock(hdev);
ret = hci_suspend_sync(hdev);
@@ -4210,7 +4210,7 @@ static void hci_send_cmd_sync(struct hci_dev *hdev, struct sk_buff *skb)
err = hci_send_frame(hdev, skb);
if (err < 0) {
- hci_cmd_sync_cancel_sync(hdev, err);
+ hci_cmd_sync_cancel_sync(hdev, -err);
return;
}
diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index 639090b9f4b85..8fe02921adf15 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -617,7 +617,10 @@ void hci_cmd_sync_cancel_sync(struct hci_dev *hdev, int err)
bt_dev_dbg(hdev, "err 0x%2.2x", err);
if (hdev->req_status == HCI_REQ_PEND) {
- hdev->req_result = err;
+ /* req_result is __u32 so error must be positive to be properly
+ * propagated.
+ */
+ hdev->req_result = err < 0 ? -err : err;
hdev->req_status = HCI_REQ_CANCELED;
wake_up_interruptible(&hdev->req_wait_q);
--
cgit 1.2.3-korg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment