]> git.proxmox.com Git - qemu-server.git/commitdiff
usb: get controllers: avoid separate loop for usb 2 devs and improve variable names
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 10 Nov 2022 16:00:58 +0000 (17:00 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 10 Nov 2022 16:02:34 +0000 (17:02 +0100)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/QemuServer/USB.pm

index 82082a177bd1273371685187f82d2618dc1a36e1..283d983395bde2233ea4c4d0dc1e7b082de00c34 100644 (file)
@@ -63,38 +63,29 @@ sub get_usb_controllers {
     } elsif (!PVE::QemuServer::Machine::machine_type_is_q35($conf)) {
         $pciaddr = print_pci_addr("piix3", $bridges, $arch, $machine);
         push @$devices, '-device', "piix3-usb-uhci,id=uhci$pciaddr.0x2";
-
-       if (!$use_qemu_xhci) {
-           my $use_usb2 = 0;
-           for (my $i = 0; $i < $max_usb_devices; $i++)  {
-               next if !$conf->{"usb$i"};
-               my $d = eval { PVE::JSONSchema::parse_property_string($format,$conf->{"usb$i"}) };
-               next if !$d || $d->{usb3}; # do not add usb2 controller if we have only usb3 devices
-               $use_usb2 = 1;
-           }
-           # include usb device config
-           push @$devices, '-readconfig', '/usr/share/qemu-server/pve-usb.cfg' if $use_usb2;
-       }
     }
 
-    # add usb3 controller if needed
-
-    my $use_usb3 = 0;
-    my $use_usb = 0;
+    my ($use_usb2, $use_usb3) = 0;
+    my $any_usb = 0;
     for (my $i = 0; $i < $max_usb_devices; $i++)  {
        next if !$conf->{"usb$i"};
        assert_usb_index_is_useable($i, $use_qemu_xhci);
-       my $d = eval { PVE::JSONSchema::parse_property_string($format,$conf->{"usb$i"}) };
-       next if !$d;
-       $use_usb = 1;
+       my $d = eval { PVE::JSONSchema::parse_property_string($format,$conf->{"usb$i"}) } or next;
+       $any_usb = 1;
        $use_usb3 = 1 if $d->{usb3};
+       $use_usb2 = 1 if !$d->{usb3};
+    }
+
+    if (!$use_qemu_xhci && $use_usb2 && $arch ne 'aarch64') {
+       # include usb device config if still on x86 before-xhci machines and if USB 3 is not used
+       push @$devices, '-readconfig', '/usr/share/qemu-server/pve-usb.cfg';
     }
 
     $pciaddr = print_pci_addr("xhci", $bridges, $arch, $machine);
-    if ($use_qemu_xhci && $use_usb) {
+    if ($use_qemu_xhci && $any_usb) {
        push @$devices, '-device', print_qemu_xhci_controller($pciaddr);
-    } else {
-       push @$devices, '-device', "nec-usb-xhci,id=xhci$pciaddr" if $use_usb3;
+    } elsif ($use_usb3) {
+       push @$devices, '-device', "nec-usb-xhci,id=xhci$pciaddr";
     }
 
     return @$devices;