From 64377dc83618696e67f1379f1ce030518e450f0c Mon Sep 17 00:00:00 2001 From: Simon Deziel Date: Tue, 12 Nov 2024 15:27:52 -0500 Subject: [PATCH 1/3] shared/usbid/parse: Match id's type to Protocol and ClassCode Signed-off-by: Simon Deziel --- shared/usbid/parse.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/shared/usbid/parse.go b/shared/usbid/parse.go index 46426be79aab..7399e68a4c67 100644 --- a/shared/usbid/parse.go +++ b/shared/usbid/parse.go @@ -77,7 +77,7 @@ 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) @@ -105,7 +105,7 @@ func ParseIDs(r io.Reader) (map[ID]*Vendor, map[ClassCode]*Class, error) { return } - id = i + id = uint16(i) return } @@ -114,7 +114,7 @@ func ParseIDs(r io.Reader) (map[ID]*Vendor, map[ClassCode]*Class, error) { 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 { @@ -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{ From 6f1714712a0c33c0b9865e0bbcabe704eadfae3d Mon Sep 17 00:00:00 2001 From: Simon Deziel Date: Tue, 12 Nov 2024 16:41:13 -0500 Subject: [PATCH 2/3] shared/usbid/parse: Use return expressions (revive) Signed-off-by: Simon Deziel --- shared/usbid/parse.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shared/usbid/parse.go b/shared/usbid/parse.go index 7399e68a4c67..ab2ed3a37060 100644 --- a/shared/usbid/parse.go +++ b/shared/usbid/parse.go @@ -81,7 +81,7 @@ func ParseIDs(r io.Reader) (map[ID]*Vendor, map[ClassCode]*Class, 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 @@ -102,12 +102,12 @@ 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 = uint16(i) - return + return kind, level, id, name, err } // Hold the interim values From a262fd032db8939671d9ac4b8942e6eb278451bb Mon Sep 17 00:00:00 2001 From: Simon Deziel Date: Tue, 12 Nov 2024 16:41:43 -0500 Subject: [PATCH 3/3] shared/usbid/parse: Comment spacing (revive) Signed-off-by: Simon Deziel --- shared/usbid/parse.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared/usbid/parse.go b/shared/usbid/parse.go index ab2ed3a37060..39a47803a2e0 100644 --- a/shared/usbid/parse.go +++ b/shared/usbid/parse.go @@ -209,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