hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/usb/gadget/function/f_ncm.c
....@@ -85,7 +85,9 @@
8585 /* peak (theoretical) bulk transfer rate in bits-per-second */
8686 static inline unsigned ncm_bitrate(struct usb_gadget *g)
8787 {
88
- if (gadget_is_superspeed(g) && g->speed >= USB_SPEED_SUPER_PLUS)
88
+ if (!g)
89
+ return 0;
90
+ else if (gadget_is_superspeed(g) && g->speed >= USB_SPEED_SUPER_PLUS)
8991 return 4250000000U;
9092 else if (gadget_is_superspeed(g) && g->speed == USB_SPEED_SUPER)
9193 return 3750000000U;
....@@ -1178,7 +1180,8 @@
11781180 struct sk_buff_head *list)
11791181 {
11801182 struct f_ncm *ncm = func_to_ncm(&port->func);
1181
- __le16 *tmp = (void *) skb->data;
1183
+ unsigned char *ntb_ptr = skb->data;
1184
+ __le16 *tmp;
11821185 unsigned index, index2;
11831186 int ndp_index;
11841187 unsigned dg_len, dg_len2;
....@@ -1191,6 +1194,10 @@
11911194 const struct ndp_parser_opts *opts = ncm->parser_opts;
11921195 unsigned crc_len = ncm->is_crc ? sizeof(uint32_t) : 0;
11931196 int dgram_counter;
1197
+ int to_process = skb->len;
1198
+
1199
+parse_ntb:
1200
+ tmp = (__le16 *)ntb_ptr;
11941201
11951202 /* dwSignature */
11961203 if (get_unaligned_le32(tmp) != opts->nth_sign) {
....@@ -1237,7 +1244,7 @@
12371244 * walk through NDP
12381245 * dwSignature
12391246 */
1240
- tmp = (void *)(skb->data + ndp_index);
1247
+ tmp = (__le16 *)(ntb_ptr + ndp_index);
12411248 if (get_unaligned_le32(tmp) != ncm->ndp_sign) {
12421249 INFO(port->func.config->cdev, "Wrong NDP SIGN\n");
12431250 goto err;
....@@ -1294,11 +1301,11 @@
12941301 if (ncm->is_crc) {
12951302 uint32_t crc, crc2;
12961303
1297
- crc = get_unaligned_le32(skb->data +
1304
+ crc = get_unaligned_le32(ntb_ptr +
12981305 index + dg_len -
12991306 crc_len);
13001307 crc2 = ~crc32_le(~0,
1301
- skb->data + index,
1308
+ ntb_ptr + index,
13021309 dg_len - crc_len);
13031310 if (crc != crc2) {
13041311 INFO(port->func.config->cdev,
....@@ -1325,7 +1332,7 @@
13251332 dg_len - crc_len);
13261333 if (skb2 == NULL)
13271334 goto err;
1328
- skb_put_data(skb2, skb->data + index,
1335
+ skb_put_data(skb2, ntb_ptr + index,
13291336 dg_len - crc_len);
13301337
13311338 skb_queue_tail(list, skb2);
....@@ -1338,10 +1345,17 @@
13381345 } while (ndp_len > 2 * (opts->dgram_item_len * 2));
13391346 } while (ndp_index);
13401347
1341
- dev_consume_skb_any(skb);
1342
-
13431348 VDBG(port->func.config->cdev,
13441349 "Parsed NTB with %d frames\n", dgram_counter);
1350
+
1351
+ to_process -= block_len;
1352
+ if (to_process != 0) {
1353
+ ntb_ptr = (unsigned char *)(ntb_ptr + block_len);
1354
+ goto parse_ntb;
1355
+ }
1356
+
1357
+ dev_consume_skb_any(skb);
1358
+
13451359 return 0;
13461360 err:
13471361 skb_queue_purge(list);