hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/bluetooth/hci_ldisc.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 *
34 * Bluetooth HCI UART driver
....@@ -5,22 +6,6 @@
56 * Copyright (C) 2000-2001 Qualcomm Incorporated
67 * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
78 * Copyright (C) 2004-2005 Marcel Holtmann <marcel@holtmann.org>
8
- *
9
- *
10
- * This program is free software; you can redistribute it and/or modify
11
- * it under the terms of the GNU General Public License as published by
12
- * the Free Software Foundation; either version 2 of the License, or
13
- * (at your option) any later version.
14
- *
15
- * This program is distributed in the hope that it will be useful,
16
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
- * GNU General Public License for more details.
19
- *
20
- * You should have received a copy of the GNU General Public License
21
- * along with this program; if not, write to the Free Software
22
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
- *
249 */
2510
2611 #include <linux/module.h>
....@@ -142,10 +127,9 @@
142127 if (!test_bit(HCI_UART_PROTO_READY, &hu->flags))
143128 goto no_schedule;
144129
145
- if (test_and_set_bit(HCI_UART_SENDING, &hu->tx_state)) {
146
- set_bit(HCI_UART_TX_WAKEUP, &hu->tx_state);
130
+ set_bit(HCI_UART_TX_WAKEUP, &hu->tx_state);
131
+ if (test_and_set_bit(HCI_UART_SENDING, &hu->tx_state))
147132 goto no_schedule;
148
- }
149133
150134 BT_DBG("");
151135
....@@ -194,10 +178,11 @@
194178 kfree_skb(skb);
195179 }
196180
181
+ clear_bit(HCI_UART_SENDING, &hu->tx_state);
197182 if (test_bit(HCI_UART_TX_WAKEUP, &hu->tx_state))
198183 goto restart;
199184
200
- clear_bit(HCI_UART_SENDING, &hu->tx_state);
185
+ wake_up_bit(&hu->tx_state, HCI_UART_SENDING);
201186 }
202187
203188 void hci_uart_init_work(struct work_struct *work)
....@@ -231,6 +216,13 @@
231216 schedule_work(&hu->init_ready);
232217
233218 return 0;
219
+}
220
+
221
+int hci_uart_wait_until_sent(struct hci_uart *hu)
222
+{
223
+ return wait_on_bit_timeout(&hu->tx_state, HCI_UART_SENDING,
224
+ TASK_INTERRUPTIBLE,
225
+ msecs_to_jiffies(2000));
234226 }
235227
236228 /* ------- Interface to HCI layer ------ */
....@@ -295,9 +287,6 @@
295287 percpu_up_read(&hu->proto_lock);
296288 return -EUNATCH;
297289 }
298
-
299
- if (!test_bit(HCI_UART_PROTO_READY, &hu->flags))
300
- return -EUNATCH;
301290
302291 hu->proto->enqueue(hu, skb);
303292 percpu_up_read(&hu->proto_lock);
....@@ -506,6 +495,11 @@
506495 BT_ERR("Can't allocate control structure");
507496 return -ENFILE;
508497 }
498
+ if (percpu_init_rwsem(&hu->proto_lock)) {
499
+ BT_ERR("Can't allocate semaphore structure");
500
+ kfree(hu);
501
+ return -ENOMEM;
502
+ }
509503
510504 tty->disc_data = hu;
511505 hu->tty = tty;
....@@ -517,8 +511,6 @@
517511
518512 INIT_WORK(&hu->init_ready, hci_uart_init_work);
519513 INIT_WORK(&hu->write_work, hci_uart_write_work);
520
-
521
- percpu_init_rwsem(&hu->proto_lock);
522514
523515 /* Flush any pending characters in the driver */
524516 tty_driver_flush_buffer(tty);
....@@ -817,7 +809,8 @@
817809 * We don't provide read/write/poll interface for user space.
818810 */
819811 static ssize_t hci_uart_tty_read(struct tty_struct *tty, struct file *file,
820
- unsigned char __user *buf, size_t nr)
812
+ unsigned char *buf, size_t nr,
813
+ void **cookie, unsigned long offset)
821814 {
822815 return 0;
823816 }
....@@ -834,28 +827,28 @@
834827 return 0;
835828 }
836829
830
+static struct tty_ldisc_ops hci_uart_ldisc = {
831
+ .owner = THIS_MODULE,
832
+ .magic = TTY_LDISC_MAGIC,
833
+ .name = "n_hci",
834
+ .open = hci_uart_tty_open,
835
+ .close = hci_uart_tty_close,
836
+ .read = hci_uart_tty_read,
837
+ .write = hci_uart_tty_write,
838
+ .ioctl = hci_uart_tty_ioctl,
839
+ .compat_ioctl = hci_uart_tty_ioctl,
840
+ .poll = hci_uart_tty_poll,
841
+ .receive_buf = hci_uart_tty_receive,
842
+ .write_wakeup = hci_uart_tty_wakeup,
843
+};
844
+
837845 static int __init hci_uart_init(void)
838846 {
839
- static struct tty_ldisc_ops hci_uart_ldisc;
840847 int err;
841848
842849 BT_INFO("HCI UART driver ver %s", VERSION);
843850
844851 /* Register the tty discipline */
845
-
846
- memset(&hci_uart_ldisc, 0, sizeof(hci_uart_ldisc));
847
- hci_uart_ldisc.magic = TTY_LDISC_MAGIC;
848
- hci_uart_ldisc.name = "n_hci";
849
- hci_uart_ldisc.open = hci_uart_tty_open;
850
- hci_uart_ldisc.close = hci_uart_tty_close;
851
- hci_uart_ldisc.read = hci_uart_tty_read;
852
- hci_uart_ldisc.write = hci_uart_tty_write;
853
- hci_uart_ldisc.ioctl = hci_uart_tty_ioctl;
854
- hci_uart_ldisc.poll = hci_uart_tty_poll;
855
- hci_uart_ldisc.receive_buf = hci_uart_tty_receive;
856
- hci_uart_ldisc.write_wakeup = hci_uart_tty_wakeup;
857
- hci_uart_ldisc.owner = THIS_MODULE;
858
-
859852 err = tty_register_ldisc(N_HCI, &hci_uart_ldisc);
860853 if (err) {
861854 BT_ERR("HCI line discipline registration failed. (%d)", err);