forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/usb/core/config.c
....@@ -298,10 +298,10 @@
298298 goto skip_to_next_endpoint_or_interface_descriptor;
299299 }
300300
301
- /* Ignore blacklisted endpoints */
302
- if (udev->quirks & USB_QUIRK_ENDPOINT_BLACKLIST) {
303
- if (usb_endpoint_is_blacklisted(udev, ifp, d)) {
304
- dev_warn(ddev, "config %d interface %d altsetting %d has a blacklisted endpoint with address 0x%X, skipping\n",
301
+ /* Ignore some endpoints */
302
+ if (udev->quirks & USB_QUIRK_ENDPOINT_IGNORE) {
303
+ if (usb_endpoint_is_ignored(udev, ifp, d)) {
304
+ dev_warn(ddev, "config %d interface %d altsetting %d has an ignored endpoint with address 0x%X, skipping\n",
305305 cfgno, inum, asnum,
306306 d->bEndpointAddress);
307307 goto skip_to_next_endpoint_or_interface_descriptor;
....@@ -322,7 +322,7 @@
322322 j = 255;
323323 if (usb_endpoint_xfer_int(d)) {
324324 i = 1;
325
- switch (to_usb_device(ddev)->speed) {
325
+ switch (udev->speed) {
326326 case USB_SPEED_SUPER_PLUS:
327327 case USB_SPEED_SUPER:
328328 case USB_SPEED_HIGH:
....@@ -343,8 +343,7 @@
343343 /*
344344 * This quirk fixes bIntervals reported in ms.
345345 */
346
- if (to_usb_device(ddev)->quirks &
347
- USB_QUIRK_LINEAR_FRAME_INTR_BINTERVAL) {
346
+ if (udev->quirks & USB_QUIRK_LINEAR_FRAME_INTR_BINTERVAL) {
348347 n = clamp(fls(d->bInterval) + 3, i, j);
349348 i = j = n;
350349 }
....@@ -352,8 +351,7 @@
352351 * This quirk fixes bIntervals reported in
353352 * linear microframes.
354353 */
355
- if (to_usb_device(ddev)->quirks &
356
- USB_QUIRK_LINEAR_UFRAME_INTR_BINTERVAL) {
354
+ if (udev->quirks & USB_QUIRK_LINEAR_UFRAME_INTR_BINTERVAL) {
357355 n = clamp(fls(d->bInterval), i, j);
358356 i = j = n;
359357 }
....@@ -370,7 +368,7 @@
370368 } else if (usb_endpoint_xfer_isoc(d)) {
371369 i = 1;
372370 j = 16;
373
- switch (to_usb_device(ddev)->speed) {
371
+ switch (udev->speed) {
374372 case USB_SPEED_HIGH:
375373 n = 7; /* 8 ms = 2^(7-1) uframes */
376374 break;
....@@ -392,8 +390,7 @@
392390 * explicitly forbidden by the USB spec. In an attempt to make
393391 * them usable, we will try treating them as Interrupt endpoints.
394392 */
395
- if (to_usb_device(ddev)->speed == USB_SPEED_LOW &&
396
- usb_endpoint_xfer_bulk(d)) {
393
+ if (udev->speed == USB_SPEED_LOW && usb_endpoint_xfer_bulk(d)) {
397394 dev_warn(ddev, "config %d interface %d altsetting %d "
398395 "endpoint 0x%X is Bulk; changing to Interrupt\n",
399396 cfgno, inum, asnum, d->bEndpointAddress);
....@@ -417,7 +414,7 @@
417414
418415 /* Find the highest legal maxpacket size for this endpoint */
419416 i = 0; /* additional transactions per microframe */
420
- switch (to_usb_device(ddev)->speed) {
417
+ switch (udev->speed) {
421418 case USB_SPEED_LOW:
422419 maxpacket_maxes = low_speed_maxpacket_maxes;
423420 break;
....@@ -430,7 +427,7 @@
430427 i = maxp & USB_EP_MAXP_MULT_MASK;
431428 maxp &= ~i;
432429 }
433
- /* fallthrough */
430
+ fallthrough;
434431 default:
435432 maxpacket_maxes = high_speed_maxpacket_maxes;
436433 break;
....@@ -453,8 +450,7 @@
453450 * maxpacket sizes other than 512. High speed HCDs may not
454451 * be able to handle that particular bug, so let's warn...
455452 */
456
- if (to_usb_device(ddev)->speed == USB_SPEED_HIGH
457
- && usb_endpoint_xfer_bulk(d)) {
453
+ if (udev->speed == USB_SPEED_HIGH && usb_endpoint_xfer_bulk(d)) {
458454 if (maxp != 512)
459455 dev_warn(ddev, "config %d interface %d altsetting %d "
460456 "bulk endpoint 0x%X has invalid maxpacket %d\n",
....@@ -463,7 +459,7 @@
463459 }
464460
465461 /* Parse a possible SuperSpeed endpoint companion descriptor */
466
- if (to_usb_device(ddev)->speed >= USB_SPEED_SUPER)
462
+ if (udev->speed >= USB_SPEED_SUPER)
467463 usb_parse_ss_endpoint_companion(ddev, cfgno,
468464 inum, asnum, endpoint, buffer, size);
469465
....@@ -618,7 +614,7 @@
618614 unsigned char *buffer2;
619615 int size2;
620616 struct usb_descriptor_header *header;
621
- int len, retval;
617
+ int retval;
622618 u8 inums[USB_MAXINTERFACES], nalts[USB_MAXINTERFACES];
623619 unsigned iad_num = 0;
624620
....@@ -773,8 +769,8 @@
773769 nalts[i] = j = USB_MAXALTSETTING;
774770 }
775771
776
- len = sizeof(*intfc) + sizeof(struct usb_host_interface) * j;
777
- config->intf_cache[i] = intfc = kzalloc(len, GFP_KERNEL);
772
+ intfc = kzalloc(struct_size(intfc, altsetting, j), GFP_KERNEL);
773
+ config->intf_cache[i] = intfc;
778774 if (!intfc)
779775 return -ENOMEM;
780776 kref_init(&intfc->ref);
....@@ -866,13 +862,11 @@
866862 {
867863 struct device *ddev = &dev->dev;
868864 int ncfg = dev->descriptor.bNumConfigurations;
869
- int result = 0;
870865 unsigned int cfgno, length;
871866 unsigned char *bigbuffer;
872867 struct usb_config_descriptor *desc;
868
+ int result;
873869
874
- cfgno = 0;
875
- result = -ENOMEM;
876870 if (ncfg > USB_MAXCONFIG) {
877871 dev_warn(ddev, "too many configurations: %d, "
878872 "using maximum allowed: %d\n", ncfg, USB_MAXCONFIG);
....@@ -887,19 +881,18 @@
887881 length = ncfg * sizeof(struct usb_host_config);
888882 dev->config = kzalloc(length, GFP_KERNEL);
889883 if (!dev->config)
890
- goto err2;
884
+ return -ENOMEM;
891885
892886 length = ncfg * sizeof(char *);
893887 dev->rawdescriptors = kzalloc(length, GFP_KERNEL);
894888 if (!dev->rawdescriptors)
895
- goto err2;
889
+ return -ENOMEM;
896890
897891 desc = kmalloc(USB_DT_CONFIG_SIZE, GFP_KERNEL);
898892 if (!desc)
899
- goto err2;
893
+ return -ENOMEM;
900894
901
- result = 0;
902
- for (; cfgno < ncfg; cfgno++) {
895
+ for (cfgno = 0; cfgno < ncfg; cfgno++) {
903896 /* We grab just the first descriptor so we know how long
904897 * the whole configuration is */
905898 result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno,
....@@ -955,14 +948,11 @@
955948 goto err;
956949 }
957950 }
958
- result = 0;
959951
960952 err:
961953 kfree(desc);
962954 dev->descriptor.bNumConfigurations = cfgno;
963
-err2:
964
- if (result == -ENOMEM)
965
- dev_err(ddev, "out of memory\n");
955
+
966956 return result;
967957 }
968958
....@@ -1086,15 +1076,6 @@
10861076 case USB_PTM_CAP_TYPE:
10871077 dev->bos->ptm_cap =
10881078 (struct usb_ptm_cap_descriptor *)buffer;
1089
- break;
1090
- case USB_CAP_TYPE_CONFIG_SUMMARY:
1091
- /* one such desc per function */
1092
- if (!dev->bos->num_config_summary_desc)
1093
- dev->bos->config_summary =
1094
- (struct usb_config_summary_descriptor *)buffer;
1095
-
1096
- dev->bos->num_config_summary_desc++;
1097
- break;
10981079 default:
10991080 break;
11001081 }