Skip to content

Commit 57a53a0

Browse files
committed
Merge branch 'for-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next
Johan Hedberg says: ==================== pull request: bluetooth-next 2017-07-01 Here are some more Bluetooth patches for the 4.13 kernel: - Added support for Broadcom BCM43430 controllers - Added sockaddr length checks before accessing sa_family - Fixed possible "might sleep" errors in bnep, cmtp and hidp modules - A few other minor fixes Please let me know if there are any issues pulling. Thanks. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 2cb5c8e + feb1672 commit 57a53a0

File tree

10 files changed

+60
-39
lines changed

10 files changed

+60
-39
lines changed

drivers/bluetooth/btbcm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ static const struct {
295295
{ 0x410e, "BCM43341B0" }, /* 002.001.014 */
296296
{ 0x4406, "BCM4324B3" }, /* 002.004.006 */
297297
{ 0x610c, "BCM4354" }, /* 003.001.012 */
298+
{ 0x2209, "BCM43430A1" }, /* 001.002.009 */
298299
{ }
299300
};
300301

drivers/bluetooth/hci_bcm.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,7 @@ static int bcm_setup(struct hci_uart *hu)
419419
if (err)
420420
return err;
421421

422-
err = bcm_request_irq(bcm);
423-
if (!err)
422+
if (!bcm_request_irq(bcm))
424423
err = bcm_setup_sleep(hu);
425424

426425
return err;
@@ -657,6 +656,15 @@ static const struct dmi_system_id bcm_wrong_irq_dmi_table[] = {
657656
},
658657
.driver_data = &acpi_active_low,
659658
},
659+
{
660+
.ident = "Asus T100CHI",
661+
.matches = {
662+
DMI_EXACT_MATCH(DMI_SYS_VENDOR,
663+
"ASUSTeK COMPUTER INC."),
664+
DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100CHI"),
665+
},
666+
.driver_data = &acpi_active_low,
667+
},
660668
{ /* Handle ThinkPad 8 tablets with BCM2E55 chipset ACPI ID */
661669
.ident = "Lenovo ThinkPad 8",
662670
.matches = {

drivers/bluetooth/hci_serdev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
#include "hci_uart.h"
3333

34-
struct serdev_device_ops hci_serdev_client_ops;
34+
static struct serdev_device_ops hci_serdev_client_ops;
3535

3636
static inline void hci_uart_tx_complete(struct hci_uart *hu, int pkt_type)
3737
{
@@ -268,7 +268,7 @@ static int hci_uart_receive_buf(struct serdev_device *serdev, const u8 *data,
268268
return count;
269269
}
270270

271-
struct serdev_device_ops hci_serdev_client_ops = {
271+
static struct serdev_device_ops hci_serdev_client_ops = {
272272
.receive_buf = hci_uart_receive_buf,
273273
.write_wakeup = hci_uart_write_wakeup,
274274
};

net/bluetooth/bnep/core.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -481,16 +481,16 @@ static int bnep_session(void *arg)
481481
struct net_device *dev = s->dev;
482482
struct sock *sk = s->sock->sk;
483483
struct sk_buff *skb;
484-
wait_queue_t wait;
484+
DEFINE_WAIT_FUNC(wait, woken_wake_function);
485485

486486
BT_DBG("");
487487

488488
set_user_nice(current, -15);
489489

490-
init_waitqueue_entry(&wait, current);
491490
add_wait_queue(sk_sleep(sk), &wait);
492491
while (1) {
493-
set_current_state(TASK_INTERRUPTIBLE);
492+
/* Ensure session->terminate is updated */
493+
smp_mb__before_atomic();
494494

495495
if (atomic_read(&s->terminate))
496496
break;
@@ -512,9 +512,8 @@ static int bnep_session(void *arg)
512512
break;
513513
netif_wake_queue(dev);
514514

515-
schedule();
515+
wait_woken(&wait, TASK_INTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT);
516516
}
517-
__set_current_state(TASK_RUNNING);
518517
remove_wait_queue(sk_sleep(sk), &wait);
519518

520519
/* Cleanup session */
@@ -663,7 +662,7 @@ int bnep_del_connection(struct bnep_conndel_req *req)
663662
s = __bnep_get_session(req->dst);
664663
if (s) {
665664
atomic_inc(&s->terminate);
666-
wake_up_process(s->task);
665+
wake_up_interruptible(sk_sleep(s->sock->sk));
667666
} else
668667
err = -ENOENT;
669668

net/bluetooth/cmtp/core.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -280,16 +280,16 @@ static int cmtp_session(void *arg)
280280
struct cmtp_session *session = arg;
281281
struct sock *sk = session->sock->sk;
282282
struct sk_buff *skb;
283-
wait_queue_t wait;
283+
DEFINE_WAIT_FUNC(wait, woken_wake_function);
284284

285285
BT_DBG("session %p", session);
286286

287287
set_user_nice(current, -15);
288288

289-
init_waitqueue_entry(&wait, current);
290289
add_wait_queue(sk_sleep(sk), &wait);
291290
while (1) {
292-
set_current_state(TASK_INTERRUPTIBLE);
291+
/* Ensure session->terminate is updated */
292+
smp_mb__before_atomic();
293293

294294
if (atomic_read(&session->terminate))
295295
break;
@@ -306,9 +306,8 @@ static int cmtp_session(void *arg)
306306

307307
cmtp_process_transmit(session);
308308

309-
schedule();
309+
wait_woken(&wait, TASK_INTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT);
310310
}
311-
__set_current_state(TASK_RUNNING);
312311
remove_wait_queue(sk_sleep(sk), &wait);
313312

314313
down_write(&cmtp_session_sem);
@@ -393,7 +392,7 @@ int cmtp_add_connection(struct cmtp_connadd_req *req, struct socket *sock)
393392
err = cmtp_attach_device(session);
394393
if (err < 0) {
395394
atomic_inc(&session->terminate);
396-
wake_up_process(session->task);
395+
wake_up_interruptible(sk_sleep(session->sock->sk));
397396
up_write(&cmtp_session_sem);
398397
return err;
399398
}
@@ -431,7 +430,11 @@ int cmtp_del_connection(struct cmtp_conndel_req *req)
431430

432431
/* Stop session thread */
433432
atomic_inc(&session->terminate);
434-
wake_up_process(session->task);
433+
434+
/* Ensure session->terminate is updated */
435+
smp_mb__after_atomic();
436+
437+
wake_up_interruptible(sk_sleep(session->sock->sk));
435438
} else
436439
err = -ENOENT;
437440

net/bluetooth/hci_core.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3096,15 +3096,14 @@ int hci_register_dev(struct hci_dev *hdev)
30963096

30973097
BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus);
30983098

3099-
hdev->workqueue = alloc_workqueue("%s", WQ_HIGHPRI | WQ_UNBOUND |
3100-
WQ_MEM_RECLAIM, 1, hdev->name);
3099+
hdev->workqueue = alloc_ordered_workqueue("%s", WQ_HIGHPRI, hdev->name);
31013100
if (!hdev->workqueue) {
31023101
error = -ENOMEM;
31033102
goto err;
31043103
}
31053104

3106-
hdev->req_workqueue = alloc_workqueue("%s", WQ_HIGHPRI | WQ_UNBOUND |
3107-
WQ_MEM_RECLAIM, 1, hdev->name);
3105+
hdev->req_workqueue = alloc_ordered_workqueue("%s", WQ_HIGHPRI,
3106+
hdev->name);
31083107
if (!hdev->req_workqueue) {
31093108
destroy_workqueue(hdev->workqueue);
31103109
error = -ENOMEM;

net/bluetooth/hidp/core.c

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#define VERSION "1.2"
3737

3838
static DECLARE_RWSEM(hidp_session_sem);
39+
static DECLARE_WAIT_QUEUE_HEAD(hidp_session_wq);
3940
static LIST_HEAD(hidp_session_list);
4041

4142
static unsigned char hidp_keycode[256] = {
@@ -1068,12 +1069,12 @@ static int hidp_session_start_sync(struct hidp_session *session)
10681069
* Wake up session thread and notify it to stop. This is asynchronous and
10691070
* returns immediately. Call this whenever a runtime error occurs and you want
10701071
* the session to stop.
1071-
* Note: wake_up_process() performs any necessary memory-barriers for us.
1072+
* Note: wake_up_interruptible() performs any necessary memory-barriers for us.
10721073
*/
10731074
static void hidp_session_terminate(struct hidp_session *session)
10741075
{
10751076
atomic_inc(&session->terminate);
1076-
wake_up_process(session->task);
1077+
wake_up_interruptible(&hidp_session_wq);
10771078
}
10781079

10791080
/*
@@ -1180,20 +1181,20 @@ static void hidp_session_run(struct hidp_session *session)
11801181
struct sock *ctrl_sk = session->ctrl_sock->sk;
11811182
struct sock *intr_sk = session->intr_sock->sk;
11821183
struct sk_buff *skb;
1184+
DEFINE_WAIT_FUNC(wait, woken_wake_function);
11831185

1186+
add_wait_queue(&hidp_session_wq, &wait);
11841187
for (;;) {
11851188
/*
11861189
* This thread can be woken up two ways:
11871190
* - You call hidp_session_terminate() which sets the
11881191
* session->terminate flag and wakes this thread up.
11891192
* - Via modifying the socket state of ctrl/intr_sock. This
11901193
* thread is woken up by ->sk_state_changed().
1191-
*
1192-
* Note: set_current_state() performs any necessary
1193-
* memory-barriers for us.
11941194
*/
1195-
set_current_state(TASK_INTERRUPTIBLE);
11961195

1196+
/* Ensure session->terminate is updated */
1197+
smp_mb__before_atomic();
11971198
if (atomic_read(&session->terminate))
11981199
break;
11991200

@@ -1227,11 +1228,22 @@ static void hidp_session_run(struct hidp_session *session)
12271228
hidp_process_transmit(session, &session->ctrl_transmit,
12281229
session->ctrl_sock);
12291230

1230-
schedule();
1231+
wait_woken(&wait, TASK_INTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT);
12311232
}
1233+
remove_wait_queue(&hidp_session_wq, &wait);
12321234

12331235
atomic_inc(&session->terminate);
1234-
set_current_state(TASK_RUNNING);
1236+
1237+
/* Ensure session->terminate is updated */
1238+
smp_mb__after_atomic();
1239+
}
1240+
1241+
static int hidp_session_wake_function(wait_queue_t *wait,
1242+
unsigned int mode,
1243+
int sync, void *key)
1244+
{
1245+
wake_up_interruptible(&hidp_session_wq);
1246+
return false;
12351247
}
12361248

12371249
/*
@@ -1244,7 +1256,8 @@ static void hidp_session_run(struct hidp_session *session)
12441256
static int hidp_session_thread(void *arg)
12451257
{
12461258
struct hidp_session *session = arg;
1247-
wait_queue_t ctrl_wait, intr_wait;
1259+
DEFINE_WAIT_FUNC(ctrl_wait, hidp_session_wake_function);
1260+
DEFINE_WAIT_FUNC(intr_wait, hidp_session_wake_function);
12481261

12491262
BT_DBG("session %p", session);
12501263

@@ -1254,8 +1267,6 @@ static int hidp_session_thread(void *arg)
12541267
set_user_nice(current, -15);
12551268
hidp_set_timer(session);
12561269

1257-
init_waitqueue_entry(&ctrl_wait, current);
1258-
init_waitqueue_entry(&intr_wait, current);
12591270
add_wait_queue(sk_sleep(session->ctrl_sock->sk), &ctrl_wait);
12601271
add_wait_queue(sk_sleep(session->intr_sock->sk), &intr_wait);
12611272
/* This memory barrier is paired with wq_has_sleeper(). See

net/bluetooth/l2cap_sock.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen)
8787

8888
BT_DBG("sk %p", sk);
8989

90-
if (!addr || addr->sa_family != AF_BLUETOOTH)
90+
if (!addr || alen < offsetofend(struct sockaddr, sa_family) ||
91+
addr->sa_family != AF_BLUETOOTH)
9192
return -EINVAL;
9293

9394
memset(&la, 0, sizeof(la));
@@ -181,7 +182,7 @@ static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr,
181182

182183
BT_DBG("sk %p", sk);
183184

184-
if (!addr || alen < sizeof(addr->sa_family) ||
185+
if (!addr || alen < offsetofend(struct sockaddr, sa_family) ||
185186
addr->sa_family != AF_BLUETOOTH)
186187
return -EINVAL;
187188

net/bluetooth/rfcomm/sock.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ static int rfcomm_sock_bind(struct socket *sock, struct sockaddr *addr, int addr
339339
struct sock *sk = sock->sk;
340340
int len, err = 0;
341341

342-
if (!addr || addr->sa_family != AF_BLUETOOTH)
342+
if (!addr || addr_len < offsetofend(struct sockaddr, sa_family) ||
343+
addr->sa_family != AF_BLUETOOTH)
343344
return -EINVAL;
344345

345346
memset(&sa, 0, sizeof(sa));

net/bluetooth/sco.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -524,10 +524,8 @@ static int sco_sock_bind(struct socket *sock, struct sockaddr *addr,
524524

525525
BT_DBG("sk %p %pMR", sk, &sa->sco_bdaddr);
526526

527-
if (!addr || addr->sa_family != AF_BLUETOOTH)
528-
return -EINVAL;
529-
530-
if (addr_len < sizeof(struct sockaddr_sco))
527+
if (!addr || addr_len < sizeof(struct sockaddr_sco) ||
528+
addr->sa_family != AF_BLUETOOTH)
531529
return -EINVAL;
532530

533531
lock_sock(sk);

0 commit comments

Comments
 (0)