Bug 251856 - set interface command doesn't follow USB spec 9.4.10
Summary: set interface command doesn't follow USB spec 9.4.10
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: usb (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Many People
Assignee: Hans Petter Selasky
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-12-15 02:51 UTC by Horse Ma
Modified: 2020-12-28 13:06 UTC (History)
2 users (show)

See Also:


Attachments
patch to fix this bug. (2.70 KB, patch)
2020-12-15 02:57 UTC, Horse Ma
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Horse Ma 2020-12-15 02:51:22 UTC
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
Comment 1 Horse Ma 2020-12-15 02:57:35 UTC
Created attachment 220564 [details]
patch to fix this bug.
Comment 2 commit-hook freebsd_committer freebsd_triage 2020-12-15 11:52:04 UTC
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
Comment 3 commit-hook freebsd_committer freebsd_triage 2020-12-15 12:06:08 UTC
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
Comment 4 Hans Petter Selasky freebsd_committer freebsd_triage 2020-12-15 12:07:04 UTC
I changed the patch a bit before submitting.

Please test!

--HPS
Comment 5 Horse Ma 2020-12-15 13:17:23 UTC
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.
Comment 6 Hans Petter Selasky freebsd_committer freebsd_triage 2020-12-15 13:26:32 UTC
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.
Comment 7 Horse Ma 2020-12-15 13:29:28 UTC
got, thanks!
Comment 8 commit-hook freebsd_committer freebsd_triage 2020-12-15 15:37:36 UTC
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
Comment 9 commit-hook freebsd_committer freebsd_triage 2020-12-28 12:53:15 UTC
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(-)
Comment 10 commit-hook freebsd_committer freebsd_triage 2020-12-28 12:55:16 UTC
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(-)
Comment 11 commit-hook freebsd_committer freebsd_triage 2020-12-28 13:02:18 UTC
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(-)
Comment 12 commit-hook freebsd_committer freebsd_triage 2020-12-28 13:06:20 UTC
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(-)