From 33ddd79e26f9b9c30675780263744cb22bb2fdd9 Mon Sep 17 00:00:00 2001 From: Aditya R Date: Mon, 13 Nov 2023 21:48:09 +0530 Subject: [PATCH] qemu,parseUSB: minor refactor Some comments from https://github.com/containers/podman/pull/20540 [NO NEW TESTS NEEDED] Signed-off-by: Aditya R --- pkg/machine/qemu/config.go | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/pkg/machine/qemu/config.go b/pkg/machine/qemu/config.go index 1bdfe82a61..eef4653702 100644 --- a/pkg/machine/qemu/config.go +++ b/pkg/machine/qemu/config.go @@ -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 @@ -107,7 +99,7 @@ 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 @@ -115,12 +107,12 @@ func parseUSBs(usbs []string) ([]machine.USBConfig, error) { 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{