Re: [PATCH v3 4/4] qemu: Fix integer/boolean logic in qemuSetUnprivSGIO

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

 



On Wed, Jul 08, 2015 at 15:30:28 -0400, John Ferlan wrote:
> Setting of 'val' is a boolean expression, so handle it that way and
> adjust the check/return logic to be clearer
> 
> Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
> ---
>  src/qemu/qemu_conf.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
> index ddaf7f8..2ab5494 100644
> --- a/src/qemu/qemu_conf.c
> +++ b/src/qemu/qemu_conf.c
> @@ -1433,7 +1433,7 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
>      virDomainHostdevDefPtr hostdev = NULL;
>      char *sysfs_path = NULL;
>      const char *path = NULL;
> -    int val = -1;
> +    bool val;
>      int ret = -1;
>  
>      /* "sgio" is only valid for block disk; cdrom
> @@ -1475,8 +1475,12 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
>       * whitelist is enabled.  But if requesting unfiltered access, always call
>       * virSetDeviceUnprivSGIO, to report an error for unsupported unpriv_sgio.
>       */
> -    if ((virFileExists(sysfs_path) || val == 1) &&
> -        virSetDeviceUnprivSGIO(path, NULL, val) < 0)
> +    if (!val || !virFileExists(sysfs_path)) {

With this control flow the @val variable can be entirely avoided since
it's just set once and read once.

> +        ret = 0;
> +        goto cleanup;
> +    }
> +
> +    if (virSetDeviceUnprivSGIO(path, NULL, 1) < 0)
>          goto cleanup;
>  
>      ret = 0;

ACK regardles if you choose to optimize @val out.

Peter

Attachment: signature.asc
Description: Digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[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]