Skip to content

Commit

Permalink
Merge pull request #20678 from flouthoc/usb_pass_cleanup
Browse files Browse the repository at this point in the history
qemu,parseUSB: minor refactor
  • Loading branch information
openshift-merge-bot[bot] authored Nov 13, 2023
2 parents 24bf08e + 33ddd79 commit 9c95473
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions pkg/machine/qemu/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,10 @@ func parseUSBs(usbs []string) ([]machine.USBConfig, error) {
return configs, fmt.Errorf("usb: fail to parse: missing '=': %s", str)
}

option := ""
if (left[0] == "bus" && right[0] == "devnum") ||
(right[0] == "bus" && left[0] == "devnum") {
option = "bus_devnum"
}
if (left[0] == "vendor" && right[0] == "product") ||
(right[0] == "vendor" && left[0] == "product") {
option = "vendor_product"
}
option := left[0] + "_" + right[0]

switch option {
case "bus_devnum":
case "bus_devnum", "devnum_bus":
bus, devnumber := left[1], right[1]
if right[0] == "bus" {
bus, devnumber = devnumber, bus
Expand All @@ -107,20 +99,20 @@ func parseUSBs(usbs []string) ([]machine.USBConfig, error) {
Bus: bus,
DevNumber: devnumber,
})
case "vendor_product":
case "vendor_product", "product_vendor":
vendorStr, productStr := left[1], right[1]
if right[0] == "vendor" {
vendorStr, productStr = productStr, vendorStr
}

vendor, err := strconv.ParseInt(vendorStr, 16, 0)
if err != nil {
return configs, fmt.Errorf("fail to convert vendor of %s: %s", str, err)
return configs, fmt.Errorf("usb: fail to convert vendor of %s: %s", str, err)
}

product, err := strconv.ParseInt(productStr, 16, 0)
if err != nil {
return configs, fmt.Errorf("fail to convert product of %s: %s", str, err)
return configs, fmt.Errorf("usb: fail to convert product of %s: %s", str, err)
}

configs = append(configs, machine.USBConfig{
Expand Down

0 comments on commit 9c95473

Please sign in to comment.