USB spec 9.4.10 says devices don't need this and are free to STALL the request if the interface only has one alternate setting
Created attachment 220564 [details] patch to fix this bug.
A commit references this bug: Author: hselasky Date: Tue Dec 15 11:51:18 UTC 2020 New revision: 368658 URL: https://svnweb.freebsd.org/changeset/base/368658 Log: Improve handling of alternate settings in the USB stack. Limit the number of alternate settings to 256. Else the alternate index variable may wrap around. PR: 251856 MFC after: 1 week Submitted by: Ma, Horse <Shichun.Ma@dell.com> Sponsored by: Mellanox Technologies // NVIDIA Networking Changes: head/sys/dev/usb/usb_parse.c
A commit references this bug: Author: hselasky Date: Tue Dec 15 12:05:08 UTC 2020 New revision: 368659 URL: https://svnweb.freebsd.org/changeset/base/368659 Log: Improve handling of alternate settings in the USB stack. Allow setting the alternate interface number to fail when there is only one alternate setting present, to comply with the USB specification. Refactor how iface->num_altsetting is computed. Bump the __FreeBSD_version due to change of core USB structure. PR: 251856 MFC after: 1 week Submitted by: Ma, Horse <Shichun.Ma@dell.com> Sponsored by: Mellanox Technologies // NVIDIA Networking Changes: head/sys/compat/linuxkpi/common/src/linux_usb.c head/sys/dev/usb/usb_device.c head/sys/dev/usb/usb_request.c head/sys/dev/usb/usbdi.h head/sys/sys/param.h
I changed the patch a bit before submitting. Please test! --HPS
It works with the improved patch. Could you comment on the reason why update iface->num_altsetting everytime? from theroy, it's just need set value when first initial. with the current latest code, this vaule will set even do alt setting to one interface.
The update is only done when you configure. That's why there is an if() check before that. For all alternate setting operations the iface_index is different from the ANY value.
got, thanks!
A commit references this bug: Author: hselasky Date: Tue Dec 15 15:36:42 UTC 2020 New revision: 368664 URL: https://svnweb.freebsd.org/changeset/base/368664 Log: Improve handling of alternate settings in the USB stack. Move initialization of num_altsetting under USB_CFG_INIT, else there will be a page fault when enumerating USB devices. PR: 251856 MFC after: 1 week Submitted by: Ma, Horse <Shichun.Ma@dell.com> Sponsored by: Mellanox Technologies // NVIDIA Networking Changes: head/sys/dev/usb/usb_device.c
A commit in branch stable/11 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=59ded046d5ed159b334337166dc5dd0509531d1c commit 59ded046d5ed159b334337166dc5dd0509531d1c Author: Hans Petter Selasky <hselasky@FreeBSD.org> AuthorDate: 2020-12-15 11:51:17 +0000 Commit: Hans Petter Selasky <hselasky@FreeBSD.org> CommitDate: 2020-12-28 12:51:31 +0000 MFC r368658: Improve handling of alternate settings in the USB stack. Limit the number of alternate settings to 256. Else the alternate index variable may wrap around. PR: 251856 Submitted by: Ma, Horse <Shichun.Ma@dell.com> Sponsored by: Mellanox Technologies // NVIDIA Networking sys/dev/usb/usb_parse.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
A commit in branch stable/12 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=4f89b6f56fb65c0b4a41875e21967a11ec28d837 commit 4f89b6f56fb65c0b4a41875e21967a11ec28d837 Author: Hans Petter Selasky <hselasky@FreeBSD.org> AuthorDate: 2020-12-15 11:51:17 +0000 Commit: Hans Petter Selasky <hselasky@FreeBSD.org> CommitDate: 2020-12-28 12:53:47 +0000 MFC r368658: Improve handling of alternate settings in the USB stack. Limit the number of alternate settings to 256. Else the alternate index variable may wrap around. PR: 251856 Submitted by: Ma, Horse <Shichun.Ma@dell.com> Sponsored by: Mellanox Technologies // NVIDIA Networking sys/dev/usb/usb_parse.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
A commit in branch stable/11 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=d511b855ed55bf72e88f7b00fa1268379f30a792 commit d511b855ed55bf72e88f7b00fa1268379f30a792 Author: Hans Petter Selasky <hselasky@FreeBSD.org> AuthorDate: 2020-12-15 12:05:07 +0000 Commit: Hans Petter Selasky <hselasky@FreeBSD.org> CommitDate: 2020-12-28 13:00:42 +0000 MFC r368659 and r368664: Improve handling of alternate settings in the USB stack. Allow setting the alternate interface number to fail when there is only one alternate setting present, to comply with the USB specification. Refactor how iface->num_altsetting is computed. Bump the __FreeBSD_version due to change of core USB structure. PR: 251856 Submitted by: Ma, Horse <Shichun.Ma@dell.com> Sponsored by: Mellanox Technologies // NVIDIA Networking sys/compat/linuxkpi/common/src/linux_usb.c | 5 ----- sys/dev/usb/usb_device.c | 6 +++++- sys/dev/usb/usb_request.c | 15 +++++++++++++-- sys/dev/usb/usbdi.h | 4 +++- sys/sys/param.h | 2 +- 5 files changed, 22 insertions(+), 10 deletions(-)
A commit in branch stable/12 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=f3d75bed5475b15f21edf4052665b1212b548bd0 commit f3d75bed5475b15f21edf4052665b1212b548bd0 Author: Hans Petter Selasky <hselasky@FreeBSD.org> AuthorDate: 2020-12-15 12:05:07 +0000 Commit: Hans Petter Selasky <hselasky@FreeBSD.org> CommitDate: 2020-12-28 13:04:56 +0000 MFC r368659 and r368664: Improve handling of alternate settings in the USB stack. Allow setting the alternate interface number to fail when there is only one alternate setting present, to comply with the USB specification. Refactor how iface->num_altsetting is computed. Bump the __FreeBSD_version due to change of core USB structure. PR: 251856 Submitted by: Ma, Horse <Shichun.Ma@dell.com> Sponsored by: Mellanox Technologies // NVIDIA Networking sys/compat/linuxkpi/common/src/linux_usb.c | 5 ----- sys/dev/usb/usb_device.c | 6 +++++- sys/dev/usb/usb_request.c | 15 +++++++++++++-- sys/dev/usb/usbdi.h | 4 +++- sys/sys/param.h | 2 +- 5 files changed, 22 insertions(+), 10 deletions(-)