On Sat, Jul 21, 2018 at 05:36:44PM +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(a)gmail.com>
---
...
@@ -218,34 +208,30 @@ virMediatedDeviceGetPath(virMediatedDevicePtr
dev)
char *
virMediatedDeviceGetIOMMUGroupDev(const char *uuidstr)
{
- char *result_path = NULL;
- char *iommu_path = NULL;
+ VIR_AUTOFREE(char *) result_path = NULL;
+ VIR_AUTOFREE(char *) iommu_path = NULL;
+ VIR_AUTOFREE(char *) dev_path = virMediatedDeviceGetSysfsPath(uuidstr);
char *vfio_path = NULL;
- char *dev_path = virMediatedDeviceGetSysfsPath(uuidstr);
if (!dev_path)
return NULL;
if (virAsprintf(&iommu_path, "%s/iommu_group", dev_path) < 0)
- goto cleanup;
+ return NULL;
if (!virFileExists(iommu_path)) {
virReportSystemError(errno, _("failed to access '%s'"),
iommu_path);
- goto cleanup;
+ return NULL;
}
if (virFileResolveLink(iommu_path, &result_path) < 0) {
virReportSystemError(errno, _("failed to resolve '%s'"),
iommu_path);
- goto cleanup;
+ return NULL;
}
if (virAsprintf(&vfio_path, "/dev/vfio/%s",
last_component(result_path)) < 0)
- goto cleanup;
+ return vfio_path;
I'd rather you returned NULL ^here.
With that:
Reviewed-by: Erik Skultety <eskultet(a)redhat.com>