Re: [libvirt PATCH 4/6] qemu: use a switch when building device addresses

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Apr 06, 2021 at 16:31:35 +0100, Daniel Berrange wrote:
> The compiler can more easily optimize a switch, and more importantly can
> also warn when new address types are added which are not handled.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
> ---
>  src/qemu/qemu_command.c | 37 +++++++++++++++++++++++++++++++------
>  1 file changed, 31 insertions(+), 6 deletions(-)
> 
> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> index d3fcca699a..bf60289786 100644
> --- a/src/qemu/qemu_command.c
> +++ b/src/qemu/qemu_command.c
> @@ -351,7 +351,8 @@ qemuBuildDeviceAddressStr(virBufferPtr buf,
>      bool contIsPHB = false;
>      int contTargetIndex = 0;
>  
> -    if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
> +    switch ((virDomainDeviceAddressType)info->type) {
> +    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI: {
>          size_t i;
>  
>          if (!(devStr = virPCIDeviceAddressAsString(&info->addr.pci)))
> @@ -419,7 +420,9 @@ qemuBuildDeviceAddressStr(virBufferPtr buf,
>          virBufferAsprintf(buf, ",addr=0x%x", info->addr.pci.slot);
>          if (info->addr.pci.function != 0)
>              virBufferAsprintf(buf, ".0x%x", info->addr.pci.function);
> -    } else if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB) {
> +    } break;

break on a separate line please.


Reviewed-by: Peter Krempa <pkrempa@xxxxxxxxxx>




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux