Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve USB ID type handling #14453

Merged
merged 3 commits into from
Nov 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions shared/usbid/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ func ParseIDs(r io.Reader) (map[ID]*Vendor, map[ClassCode]*Class, error) {
vendors := make(map[ID]*Vendor, 2800)
classes := make(map[ClassCode]*Class) // TODO(kevlar): count

split := func(s string) (kind string, level int, id uint64, name string, err error) {
split := func(s string) (kind string, level int, id uint16, name string, err error) {
pieces := strings.SplitN(s, " ", 2)
if len(pieces) != 2 {
err = fmt.Errorf("malformatted line %q", s)
return
return kind, level, id, name, err
}

// Save the name
Expand All @@ -102,19 +102,19 @@ func ParseIDs(r io.Reader) (map[ID]*Vendor, map[ClassCode]*Class, error) {
i, err := strconv.ParseUint(pieces[0], 16, 16)
if err != nil {
err = fmt.Errorf("malformatted id %q: %w", pieces[0], err)
return
return kind, level, id, name, err
}

id = i
id = uint16(i)

return
return kind, level, id, name, err
}

// Hold the interim values
var vendor *Vendor
var device *Product

parseVendor := func(level int, raw uint64, name string) error {
parseVendor := func(level int, raw uint16, name string) error {
id := ID(raw)

switch level {
Expand Down Expand Up @@ -162,7 +162,11 @@ func ParseIDs(r io.Reader) (map[ID]*Vendor, map[ClassCode]*Class, error) {
var class *Class
var subclass *SubClass

parseClass := func(level int, id uint64, name string) error {
parseClass := func(level int, id uint16, name string) error {
if id > 255 {
return fmt.Errorf("integer overflow")
}

switch level {
case 0:
class = &Class{
Expand Down Expand Up @@ -205,8 +209,8 @@ func ParseIDs(r io.Reader) (map[ID]*Vendor, map[ClassCode]*Class, error) {
}

// TODO(kevlar): Parse class information, etc
//var class *Class
//var subclass *SubClass
// var class *Class
// var subclass *SubClass

var kind string

Expand Down
Loading