hc
2024-02-19 1c055e55a242a33e574e48be530e06770a210dcd
kernel/net/bluetooth/hidp/core.c
....@@ -101,6 +101,7 @@
101101 {
102102 struct sk_buff *skb;
103103 struct sock *sk = sock->sk;
104
+ int ret;
104105
105106 BT_DBG("session %p data %p size %d", session, data, size);
106107
....@@ -114,13 +115,17 @@
114115 }
115116
116117 skb_put_u8(skb, hdr);
117
- if (data && size > 0)
118
+ if (data && size > 0) {
118119 skb_put_data(skb, data, size);
120
+ ret = size;
121
+ } else {
122
+ ret = 0;
123
+ }
119124
120125 skb_queue_tail(transmit, skb);
121126 wake_up_interruptible(sk_sleep(sk));
122127
123
- return 0;
128
+ return ret;
124129 }
125130
126131 static int hidp_send_ctrl_message(struct hidp_session *session,
....@@ -262,7 +267,7 @@
262267 set_bit(HIDP_WAITING_FOR_RETURN, &session->flags);
263268 data[0] = report_number;
264269 ret = hidp_send_ctrl_message(session, report_type, data, 1);
265
- if (ret)
270
+ if (ret < 0)
266271 goto err;
267272
268273 /* Wait for the return of the report. The returned report
....@@ -338,7 +343,7 @@
338343 data[0] = reportnum;
339344 set_bit(HIDP_WAITING_FOR_SEND_ACK, &session->flags);
340345 ret = hidp_send_ctrl_message(session, report_type, data, count);
341
- if (ret)
346
+ if (ret < 0)
342347 goto err;
343348
344349 /* Wait for the ACK from the device. */
....@@ -428,7 +433,7 @@
428433 static void hidp_del_timer(struct hidp_session *session)
429434 {
430435 if (session->idle_to > 0)
431
- del_timer(&session->timer);
436
+ del_timer_sync(&session->timer);
432437 }
433438
434439 static void hidp_process_report(struct hidp_session *session, int type,
....@@ -649,7 +654,7 @@
649654 }
650655
651656 static int hidp_setup_input(struct hidp_session *session,
652
- struct hidp_connadd_req *req)
657
+ const struct hidp_connadd_req *req)
653658 {
654659 struct input_dev *input;
655660 int i;
....@@ -748,7 +753,7 @@
748753 /* This function sets up the hid device. It does not add it
749754 to the HID system. That is done in hidp_add_connection(). */
750755 static int hidp_setup_hid(struct hidp_session *session,
751
- struct hidp_connadd_req *req)
756
+ const struct hidp_connadd_req *req)
752757 {
753758 struct hid_device *hid;
754759 int err;
....@@ -775,7 +780,7 @@
775780 hid->version = req->version;
776781 hid->country = req->country;
777782
778
- strncpy(hid->name, req->name, sizeof(hid->name));
783
+ strscpy(hid->name, req->name, sizeof(hid->name));
779784
780785 snprintf(hid->phys, sizeof(hid->phys), "%pMR",
781786 &l2cap_pi(session->ctrl_sock->sk)->chan->src);
....@@ -807,7 +812,7 @@
807812
808813 /* initialize session devices */
809814 static int hidp_session_dev_init(struct hidp_session *session,
810
- struct hidp_connadd_req *req)
815
+ const struct hidp_connadd_req *req)
811816 {
812817 int ret;
813818
....@@ -906,7 +911,7 @@
906911 static int hidp_session_new(struct hidp_session **out, const bdaddr_t *bdaddr,
907912 struct socket *ctrl_sock,
908913 struct socket *intr_sock,
909
- struct hidp_connadd_req *req,
914
+ const struct hidp_connadd_req *req,
910915 struct l2cap_conn *conn)
911916 {
912917 struct hidp_session *session;
....@@ -1074,6 +1079,10 @@
10741079 static void hidp_session_terminate(struct hidp_session *session)
10751080 {
10761081 atomic_inc(&session->terminate);
1082
+ /*
1083
+ * See the comment preceding the call to wait_woken()
1084
+ * in hidp_session_run().
1085
+ */
10771086 wake_up_interruptible(&hidp_session_wq);
10781087 }
10791088
....@@ -1193,8 +1202,6 @@
11931202 * thread is woken up by ->sk_state_changed().
11941203 */
11951204
1196
- /* Ensure session->terminate is updated */
1197
- smp_mb__before_atomic();
11981205 if (atomic_read(&session->terminate))
11991206 break;
12001207
....@@ -1228,14 +1235,15 @@
12281235 hidp_process_transmit(session, &session->ctrl_transmit,
12291236 session->ctrl_sock);
12301237
1238
+ /*
1239
+ * wait_woken() performs the necessary memory barriers
1240
+ * for us; see the header comment for this primitive.
1241
+ */
12311242 wait_woken(&wait, TASK_INTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT);
12321243 }
12331244 remove_wait_queue(&hidp_session_wq, &wait);
12341245
12351246 atomic_inc(&session->terminate);
1236
-
1237
- /* Ensure session->terminate is updated */
1238
- smp_mb__after_atomic();
12391247 }
12401248
12411249 static int hidp_session_wake_function(wait_queue_entry_t *wait,
....@@ -1271,7 +1279,7 @@
12711279 add_wait_queue(sk_sleep(session->intr_sock->sk), &intr_wait);
12721280 /* This memory barrier is paired with wq_has_sleeper(). See
12731281 * sock_poll_wait() for more information why this is needed. */
1274
- smp_mb();
1282
+ smp_mb__before_atomic();
12751283
12761284 /* notify synchronous startup that we're ready */
12771285 atomic_inc(&session->state);
....@@ -1335,7 +1343,7 @@
13351343 return 0;
13361344 }
13371345
1338
-int hidp_connection_add(struct hidp_connadd_req *req,
1346
+int hidp_connection_add(const struct hidp_connadd_req *req,
13391347 struct socket *ctrl_sock,
13401348 struct socket *intr_sock)
13411349 {