Re: [PATCH v1 20/40] util: pci: use VIR_AUTOFREE instead of VIR_FREE for scalar types

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

 



On Sat, Jul 21, 2018 at 05:36:52PM +0530, Sukrit Bhatnagar wrote:
> By making use of GNU C's cleanup attribute handled by the
> VIR_AUTOFREE macro for declaring scalar variables, majority
> of the VIR_FREE calls can be dropped, which in turn leads to
> getting rid of most of our cleanup sections.
>
> Signed-off-by: Sukrit Bhatnagar <skrtbhtngr@xxxxxxxxx>
> ---

...

>
> @@ -1278,8 +1247,7 @@ virPCIDeviceUnbindFromStubWithOverride(virPCIDevicePtr dev)
>  static int
>  virPCIDeviceUnbindFromStub(virPCIDevicePtr dev)
>  {
> -    int ret;
> -    char *path;
> +    VIR_AUTOFREE(char *) path = NULL;
>
>      /*
>       * Prefer using the device's driver_override interface, falling back
> @@ -1289,12 +1257,9 @@ virPCIDeviceUnbindFromStub(virPCIDevicePtr dev)
>          return -1;
>
>      if (virFileExists(path))
> -        ret = virPCIDeviceUnbindFromStubWithOverride(dev);
> +        return virPCIDeviceUnbindFromStubWithOverride(dev);
>      else

Drop the 'else' clause, it's not needed anymore.

...

>  static int
>  virPCIDeviceBindToStub(virPCIDevicePtr dev)
>  {
> -    int ret;
> -    char *path;
> +    VIR_AUTOFREE(char *) path = NULL;
>
>      /*
>       * Prefer using the device's driver_override interface, falling back
> @@ -1511,12 +1464,9 @@ virPCIDeviceBindToStub(virPCIDevicePtr dev)
>          return -1;
>
>      if (virFileExists(path))
> -        ret = virPCIDeviceBindToStubWithOverride(dev);
> +        return virPCIDeviceBindToStubWithOverride(dev);
>      else
... here too..

...

> @@ -1755,8 +1701,8 @@ virPCIDeviceNew(unsigned int domain,
>                  unsigned int function)
>  {
>      virPCIDevicePtr dev;

virPCIDevicePtr ret = NULL;
VIR_AUTOPTR(virPCIDevicePtr) tmp = NULL;

> -    char *vendor = NULL;
> -    char *product = NULL;
> +    VIR_AUTOFREE(char *) vendor = NULL;
> +    VIR_AUTOFREE(char *) product = NULL;
>
>      if (VIR_ALLOC(dev) < 0)
>          return NULL;
> @@ -1805,15 +1751,11 @@ virPCIDeviceNew(unsigned int domain,
>
>      VIR_DEBUG("%s %s: initialized", dev->id, dev->name);
>

VIR_STEAL_PTR(ret, dev);

> - cleanup:

Preserve the 'cleanup' label...

> -    VIR_FREE(product);
> -    VIR_FREE(vendor);
>      return dev;
>
>   error:

Drop 'error' label

>      virPCIDeviceFree(dev);

^this can be dropped too...

> -    dev = NULL;
> -    goto cleanup;
> +    return NULL;

^return ret;

Erik

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

  Powered by Linux