Skip to content

Commit 46decc8

Browse files
Linyu Yuangregkh
authored andcommitted
usb: gadget: unconditionally allocate hs/ss descriptor in bind operation
Take f_midi_bind() for example, when composite layer call it, it will allocate hs descriptor by calling gadget_is_dualspeed() API to check gadget max support speed capability, but most other gadget function didn't do like this. To follow other function drivers, it is safe to remove the check which mean support all possible link speed by default in function driver. Similar change apply to midi2 and uvc. Also in midi and midi2, as there is no descriptor difference between super speed and super speed plus, follow other gadget function drivers, do not allocate descriptor for super speed plus, composite layer will handle it properly. Signed-off-by: Linyu Yuan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 3c5b006 commit 46decc8

File tree

3 files changed

+51
-75
lines changed

3 files changed

+51
-75
lines changed

drivers/usb/gadget/function/f_midi.c

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,40 +1023,30 @@ static int f_midi_bind(struct usb_configuration *c, struct usb_function *f)
10231023
if (!f->fs_descriptors)
10241024
goto fail_f_midi;
10251025

1026-
if (gadget_is_dualspeed(c->cdev->gadget)) {
1027-
bulk_in_desc.wMaxPacketSize = cpu_to_le16(512);
1028-
bulk_out_desc.wMaxPacketSize = cpu_to_le16(512);
1029-
f->hs_descriptors = usb_copy_descriptors(midi_function);
1030-
if (!f->hs_descriptors)
1031-
goto fail_f_midi;
1032-
}
1026+
bulk_in_desc.wMaxPacketSize = cpu_to_le16(512);
1027+
bulk_out_desc.wMaxPacketSize = cpu_to_le16(512);
1028+
f->hs_descriptors = usb_copy_descriptors(midi_function);
1029+
if (!f->hs_descriptors)
1030+
goto fail_f_midi;
10331031

1034-
if (gadget_is_superspeed(c->cdev->gadget)) {
1035-
bulk_in_desc.wMaxPacketSize = cpu_to_le16(1024);
1036-
bulk_out_desc.wMaxPacketSize = cpu_to_le16(1024);
1037-
i = endpoint_descriptor_index;
1038-
midi_function[i++] = (struct usb_descriptor_header *)
1039-
&bulk_out_desc;
1040-
midi_function[i++] = (struct usb_descriptor_header *)
1041-
&bulk_out_ss_comp_desc;
1042-
midi_function[i++] = (struct usb_descriptor_header *)
1043-
&ms_out_desc;
1044-
midi_function[i++] = (struct usb_descriptor_header *)
1045-
&bulk_in_desc;
1046-
midi_function[i++] = (struct usb_descriptor_header *)
1047-
&bulk_in_ss_comp_desc;
1048-
midi_function[i++] = (struct usb_descriptor_header *)
1049-
&ms_in_desc;
1050-
f->ss_descriptors = usb_copy_descriptors(midi_function);
1051-
if (!f->ss_descriptors)
1052-
goto fail_f_midi;
1053-
1054-
if (gadget_is_superspeed_plus(c->cdev->gadget)) {
1055-
f->ssp_descriptors = usb_copy_descriptors(midi_function);
1056-
if (!f->ssp_descriptors)
1057-
goto fail_f_midi;
1058-
}
1059-
}
1032+
bulk_in_desc.wMaxPacketSize = cpu_to_le16(1024);
1033+
bulk_out_desc.wMaxPacketSize = cpu_to_le16(1024);
1034+
i = endpoint_descriptor_index;
1035+
midi_function[i++] = (struct usb_descriptor_header *)
1036+
&bulk_out_desc;
1037+
midi_function[i++] = (struct usb_descriptor_header *)
1038+
&bulk_out_ss_comp_desc;
1039+
midi_function[i++] = (struct usb_descriptor_header *)
1040+
&ms_out_desc;
1041+
midi_function[i++] = (struct usb_descriptor_header *)
1042+
&bulk_in_desc;
1043+
midi_function[i++] = (struct usb_descriptor_header *)
1044+
&bulk_in_ss_comp_desc;
1045+
midi_function[i++] = (struct usb_descriptor_header *)
1046+
&ms_in_desc;
1047+
f->ss_descriptors = usb_copy_descriptors(midi_function);
1048+
if (!f->ss_descriptors)
1049+
goto fail_f_midi;
10601050

10611051
kfree(midi_function);
10621052

drivers/usb/gadget/function/f_midi2.c

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,7 +1731,6 @@ static int f_midi2_create_usb_configs(struct f_midi2 *midi2,
17311731
midi1_out_eps = midi2_midi1_ep_out_descs;
17321732
break;
17331733
case USB_SPEED_SUPER:
1734-
case USB_SPEED_SUPER_PLUS:
17351734
midi2_midi1_ep_out_desc.wMaxPacketSize = cpu_to_le16(1024);
17361735
midi2_midi1_ep_in_desc.wMaxPacketSize = cpu_to_le16(1024);
17371736
for (i = 0; i < midi2->num_eps; i++)
@@ -2001,36 +2000,25 @@ static int f_midi2_bind(struct usb_configuration *c, struct usb_function *f)
20012000
}
20022001
f_midi2_free_usb_configs(&config);
20032002

2004-
if (gadget_is_dualspeed(midi2->gadget)) {
2005-
status = f_midi2_create_usb_configs(midi2, &config, USB_SPEED_HIGH);
2006-
if (status < 0)
2007-
goto fail;
2008-
f->hs_descriptors = usb_copy_descriptors(config.list);
2009-
if (!f->hs_descriptors) {
2010-
status = -ENOMEM;
2011-
goto fail;
2012-
}
2013-
f_midi2_free_usb_configs(&config);
2003+
status = f_midi2_create_usb_configs(midi2, &config, USB_SPEED_HIGH);
2004+
if (status < 0)
2005+
goto fail;
2006+
f->hs_descriptors = usb_copy_descriptors(config.list);
2007+
if (!f->hs_descriptors) {
2008+
status = -ENOMEM;
2009+
goto fail;
20142010
}
2011+
f_midi2_free_usb_configs(&config);
20152012

2016-
if (gadget_is_superspeed(midi2->gadget)) {
2017-
status = f_midi2_create_usb_configs(midi2, &config, USB_SPEED_SUPER);
2018-
if (status < 0)
2019-
goto fail;
2020-
f->ss_descriptors = usb_copy_descriptors(config.list);
2021-
if (!f->ss_descriptors) {
2022-
status = -ENOMEM;
2023-
goto fail;
2024-
}
2025-
if (gadget_is_superspeed_plus(midi2->gadget)) {
2026-
f->ssp_descriptors = usb_copy_descriptors(config.list);
2027-
if (!f->ssp_descriptors) {
2028-
status = -ENOMEM;
2029-
goto fail;
2030-
}
2031-
}
2032-
f_midi2_free_usb_configs(&config);
2013+
status = f_midi2_create_usb_configs(midi2, &config, USB_SPEED_SUPER);
2014+
if (status < 0)
2015+
goto fail;
2016+
f->ss_descriptors = usb_copy_descriptors(config.list);
2017+
if (!f->ss_descriptors) {
2018+
status = -ENOMEM;
2019+
goto fail;
20332020
}
2021+
f_midi2_free_usb_configs(&config);
20342022

20352023
mutex_unlock(&f_midi2_desc_mutex);
20362024
return 0;

drivers/usb/gadget/function/f_uvc.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -780,21 +780,19 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f)
780780
f->fs_descriptors = NULL;
781781
goto error;
782782
}
783-
if (gadget_is_dualspeed(cdev->gadget)) {
784-
f->hs_descriptors = uvc_copy_descriptors(uvc, USB_SPEED_HIGH);
785-
if (IS_ERR(f->hs_descriptors)) {
786-
ret = PTR_ERR(f->hs_descriptors);
787-
f->hs_descriptors = NULL;
788-
goto error;
789-
}
783+
784+
f->hs_descriptors = uvc_copy_descriptors(uvc, USB_SPEED_HIGH);
785+
if (IS_ERR(f->hs_descriptors)) {
786+
ret = PTR_ERR(f->hs_descriptors);
787+
f->hs_descriptors = NULL;
788+
goto error;
790789
}
791-
if (gadget_is_superspeed(c->cdev->gadget)) {
792-
f->ss_descriptors = uvc_copy_descriptors(uvc, USB_SPEED_SUPER);
793-
if (IS_ERR(f->ss_descriptors)) {
794-
ret = PTR_ERR(f->ss_descriptors);
795-
f->ss_descriptors = NULL;
796-
goto error;
797-
}
790+
791+
f->ss_descriptors = uvc_copy_descriptors(uvc, USB_SPEED_SUPER);
792+
if (IS_ERR(f->ss_descriptors)) {
793+
ret = PTR_ERR(f->ss_descriptors);
794+
f->ss_descriptors = NULL;
795+
goto error;
798796
}
799797

800798
/* Preallocate control endpoint request. */

0 commit comments

Comments
 (0)