| From a319018d4b19bccc98832b0f6b602251099a6967 Mon Sep 17 00:00:00 2001 |
| From: Abhishek Pandit-Subedi <abhishekpandit@chromium.org> |
| Date: Thu, 2 Jun 2022 09:46:50 -0700 |
| Subject: [PATCH] BACKPORT: FROMGIT: Bluetooth: Unregister suspend with |
| userchannel |
| |
| When HCI_USERCHANNEL is used, unregister the suspend notifier when |
| binding and register when releasing. The userchannel socket should be |
| left alone after open is completed. |
| |
| Signed-off-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org> |
| Signed-off-by: Marcel Holtmann <marcel@holtmann.org> |
| |
| (cherry picked from commit d6bb2a91f95bf5f3276cd88e9e2baf74871b07e8 |
| git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master) |
| |
| Conflicts: |
| net/bluetooth/hci_core.c |
| |
| BUG=b:228515847 |
| TEST=Manual test on Floss w/ Zork |
| |
| Change-Id: I4c60836cc1a5445c852fe0e71e62c13acfc6ff9c |
| Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/3696248 |
| Commit-Queue: Abhishek Pandit-Subedi <abhishekpandit@google.com> |
| Tested-by: Abhishek Pandit-Subedi <abhishekpandit@google.com> |
| Reviewed-by: Alain Michaud <alainm@chromium.org> |
| --- |
| include/net/bluetooth/hci_core.h | 2 ++ |
| net/bluetooth/hci_core.c | 34 ++++++++++++++++++++++++-------- |
| net/bluetooth/hci_sock.c | 3 +++ |
| 3 files changed, 31 insertions(+), 8 deletions(-) |
| |
| diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h |
| index 975bf981a4cb..6df9dcdc5156 100644 |
| --- a/include/net/bluetooth/hci_core.h |
| +++ b/include/net/bluetooth/hci_core.h |
| @@ -1291,6 +1291,8 @@ void hci_free_dev(struct hci_dev *hdev); |
| int hci_register_dev(struct hci_dev *hdev); |
| void hci_unregister_dev(struct hci_dev *hdev); |
| void hci_release_dev(struct hci_dev *hdev); |
| +int hci_register_suspend_notifier(struct hci_dev *hdev); |
| +int hci_unregister_suspend_notifier(struct hci_dev *hdev); |
| int hci_suspend_dev(struct hci_dev *hdev); |
| int hci_resume_dev(struct hci_dev *hdev); |
| int hci_reset_dev(struct hci_dev *hdev); |
| diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c |
| index c79cfe460ee0..afe6071c2c28 100644 |
| --- a/net/bluetooth/hci_core.c |
| +++ b/net/bluetooth/hci_core.c |
| @@ -2643,12 +2643,8 @@ int hci_register_dev(struct hci_dev *hdev) |
| hci_sock_dev_event(hdev, HCI_DEV_REG); |
| hci_dev_hold(hdev); |
| |
| - if (!test_bit(HCI_QUIRK_NO_SUSPEND_NOTIFIER, &hdev->quirks)) { |
| - hdev->suspend_notifier.notifier_call = hci_suspend_notifier; |
| - error = register_pm_notifier(&hdev->suspend_notifier); |
| - if (error) |
| - goto err_wqueue; |
| - } |
| + if (hci_register_suspend_notifier(hdev)) |
| + goto err_wqueue; |
| |
| queue_work(hdev->req_workqueue, &hdev->power_on); |
| |
| @@ -2681,8 +2677,7 @@ void hci_unregister_dev(struct hci_dev *hdev) |
| |
| hci_cmd_sync_clear(hdev); |
| |
| - if (!test_bit(HCI_QUIRK_NO_SUSPEND_NOTIFIER, &hdev->quirks)) |
| - unregister_pm_notifier(&hdev->suspend_notifier); |
| + hci_unregister_suspend_notifier(hdev); |
| |
| msft_unregister(hdev); |
| |
| @@ -2746,6 +2741,29 @@ void hci_release_dev(struct hci_dev *hdev) |
| } |
| EXPORT_SYMBOL(hci_release_dev); |
| |
| +int hci_register_suspend_notifier(struct hci_dev *hdev) |
| +{ |
| + int ret = 0; |
| + |
| + if (!test_bit(HCI_QUIRK_NO_SUSPEND_NOTIFIER, &hdev->quirks)) { |
| + hdev->suspend_notifier.notifier_call = hci_suspend_notifier; |
| + ret = register_pm_notifier(&hdev->suspend_notifier); |
| + } |
| + |
| + return ret; |
| +} |
| + |
| +int hci_unregister_suspend_notifier(struct hci_dev *hdev) |
| +{ |
| + int ret = 0; |
| + |
| + if (!test_bit(HCI_QUIRK_NO_SUSPEND_NOTIFIER, &hdev->quirks)) { |
| + ret = unregister_pm_notifier(&hdev->suspend_notifier); |
| + } |
| + |
| + return ret; |
| +} |
| + |
| /* Suspend HCI device */ |
| int hci_suspend_dev(struct hci_dev *hdev) |
| { |
| diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c |
| index bd8358b44aa4..0d015d4a8e41 100644 |
| --- a/net/bluetooth/hci_sock.c |
| +++ b/net/bluetooth/hci_sock.c |
| @@ -887,6 +887,7 @@ static int hci_sock_release(struct socket *sock) |
| */ |
| hci_dev_do_close(hdev); |
| hci_dev_clear_flag(hdev, HCI_USER_CHANNEL); |
| + hci_register_suspend_notifier(hdev); |
| mgmt_index_added(hdev); |
| } |
| |
| @@ -1215,6 +1216,7 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr, |
| } |
| |
| mgmt_index_removed(hdev); |
| + hci_unregister_suspend_notifier(hdev); |
| |
| err = hci_dev_open(hdev->id); |
| if (err) { |
| @@ -1229,6 +1231,7 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr, |
| err = 0; |
| } else { |
| hci_dev_clear_flag(hdev, HCI_USER_CHANNEL); |
| + hci_register_suspend_notifier(hdev); |
| mgmt_index_added(hdev); |
| hci_dev_put(hdev); |
| goto done; |
| -- |
| 2.36.1.476.g0c4daa206d-goog |
| |