On Tue, Jul 24, 2018 at 09:22:29PM +0530, Sukrit Bhatnagar wrote:
> By making use of GNU C's cleanup attribute handled by the
> VIR_AUTOPTR macro for declaring aggregate pointer variables,
> majority of the calls to *Free functions can be dropped, which
> in turn leads to getting rid of most of our cleanup sections.
>
> Signed-off-by: Sukrit Bhatnagar <skrtbht...@gmail.com>
> Reviewed-by: Erik Skultety <eskul...@redhat.com>
> ---
>  src/util/virscsi.c | 37 +++++++++++++++----------------------
>  1 file changed, 15 insertions(+), 22 deletions(-)
>
> diff --git a/src/util/virscsi.c b/src/util/virscsi.c
> index ba0a688..f97f6b5 100644
> --- a/src/util/virscsi.c
> +++ b/src/util/virscsi.c
> @@ -189,7 +189,8 @@ virSCSIDeviceNew(const char *sysfs_prefix,
>                   bool readonly,
>                   bool shareable)
>  {
> -    virSCSIDevicePtr dev, ret = NULL;
> +    VIR_AUTOPTR(virSCSIDevice) dev = NULL;
> +    virSCSIDevicePtr ret = NULL;
>      VIR_AUTOFREE(char *) sg = NULL;
>      VIR_AUTOFREE(char *) vendor_path = NULL;
>      VIR_AUTOFREE(char *) model_path = NULL;
> @@ -207,46 +208,43 @@ virSCSIDeviceNew(const char *sysfs_prefix,
>      dev->shareable = shareable;
>
>      if (!(sg = virSCSIDeviceGetSgName(prefix, adapter, bus, target, unit)))
> -        goto cleanup;
> +        return NULL;
>
>      if (virSCSIDeviceGetAdapterId(adapter, &dev->adapter) < 0)
> -        goto cleanup;
> +        return NULL;
>
>      if (virAsprintf(&dev->name, "%d:%u:%u:%llu", dev->adapter,
>                      dev->bus, dev->target, dev->unit) < 0 ||
>          virAsprintf(&dev->sg_path, "%s/%s",
>                      sysfs_prefix ? sysfs_prefix : "/dev", sg) < 0)
> -        goto cleanup;
> +        return NULL;
>
>      if (!virFileExists(dev->sg_path)) {
>          virReportSystemError(errno,
>                               _("SCSI device '%s': could not access %s"),
>                               dev->name, dev->sg_path);
> -        goto cleanup;
> +        return NULL;
>      }
>
>      if (virAsprintf(&vendor_path,
>                      "%s/%s/vendor", prefix, dev->name) < 0 ||
>          virAsprintf(&model_path,
>                      "%s/%s/model", prefix, dev->name) < 0)
> -        goto cleanup;
> +        return NULL;
>
>      if (virFileReadAll(vendor_path, 1024, &vendor) < 0)
> -        goto cleanup;
> +        return NULL;
>
>      if (virFileReadAll(model_path, 1024, &model) < 0)
> -        goto cleanup;
> +        return NULL;
>
>      virTrimSpaces(vendor, NULL);
>      virTrimSpaces(model, NULL);
>
>      if (virAsprintf(&dev->id, "%s:%s", vendor, model) < 0)
> -        goto cleanup;
> +        return NULL;
>
> -    ret = dev;
> - cleanup:
> -    if (!ret)
> -        virSCSIDeviceFree(dev);
> +    VIR_STEAL_PTR(ret, dev);
>      return ret;
>  }
>
> @@ -281,21 +279,17 @@ virSCSIDeviceSetUsedBy(virSCSIDevicePtr dev,
>                         const char *drvname,
>                         const char *domname)
>  {
> -    virUsedByInfoPtr copy;
> +    VIR_AUTOPTR(virUsedByInfo) copy = NULL;

I'll add a new line ^here before merging.

Erik

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

Reply via email to