From e817de5d0b229975d46f85ce665b38a7615d4c6b Mon Sep 17 00:00:00 2001 From: Hsin-chen Chuang Date: Wed, 8 Jan 2025 20:24:44 +0800 Subject: [PATCH] FROMGIT: Bluetooth: Allow reset via sysfs Allow sysfs to trigger hdev reset. This is required to recover devices that are not responsive from userspace. Signed-off-by: Hsin-chen Chuang Signed-off-by: Luiz Augusto von Dentz Bug: 376104075 (cherry picked from commit 0f8a0013741163459fc6cf4610bb9ed2ec25fb94 https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master) Change-Id: I1e91db62db03ca6afbe97cf785402cf6fa274ed1 Signed-off-by: Hsin-chen Chuang --- net/bluetooth/hci_sysfs.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c index 4b54dbbf0729..041ce9adc378 100644 --- a/net/bluetooth/hci_sysfs.c +++ b/net/bluetooth/hci_sysfs.c @@ -90,9 +90,28 @@ static void bt_host_release(struct device *dev) module_put(THIS_MODULE); } +static ssize_t reset_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct hci_dev *hdev = to_hci_dev(dev); + + if (hdev->reset) + hdev->reset(hdev); + + return count; +} +static DEVICE_ATTR_WO(reset); + +static struct attribute *bt_host_attrs[] = { + &dev_attr_reset.attr, + NULL, +}; +ATTRIBUTE_GROUPS(bt_host); + static const struct device_type bt_host = { .name = "host", .release = bt_host_release, + .groups = bt_host_groups, }; void hci_init_sysfs(struct hci_dev *hdev)