提交 1ab3d8b4 编写于 作者: M Michal Privoznik

virPCIDeviceNew: Prefer VIR_RETURN_PTR

This function declares @ret variable and then uses
VIR_STEAL_PTR() to avoid freeing temporary variable @dev which is
constructed. Well, as of 267f1e6d we have VIR_RETURN_PTR()
macro so that we can avoid this pattern.
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 1737d11e
...@@ -1749,7 +1749,6 @@ virPCIDeviceNew(unsigned int domain, ...@@ -1749,7 +1749,6 @@ virPCIDeviceNew(unsigned int domain,
unsigned int slot, unsigned int slot,
unsigned int function) unsigned int function)
{ {
virPCIDevicePtr ret = NULL;
VIR_AUTOPTR(virPCIDevice) dev = NULL; VIR_AUTOPTR(virPCIDevice) dev = NULL;
VIR_AUTOFREE(char *) vendor = NULL; VIR_AUTOFREE(char *) vendor = NULL;
VIR_AUTOFREE(char *) product = NULL; VIR_AUTOFREE(char *) product = NULL;
...@@ -1767,17 +1766,17 @@ virPCIDeviceNew(unsigned int domain, ...@@ -1767,17 +1766,17 @@ virPCIDeviceNew(unsigned int domain,
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("dev->name buffer overflow: %.4x:%.2x:%.2x.%.1x"), _("dev->name buffer overflow: %.4x:%.2x:%.2x.%.1x"),
domain, bus, slot, function); domain, bus, slot, function);
goto cleanup; return NULL;
} }
if (virAsprintf(&dev->path, PCI_SYSFS "devices/%s/config", if (virAsprintf(&dev->path, PCI_SYSFS "devices/%s/config",
dev->name) < 0) dev->name) < 0)
goto cleanup; return NULL;
if (!virFileExists(dev->path)) { if (!virFileExists(dev->path)) {
virReportSystemError(errno, virReportSystemError(errno,
_("Device %s not found: could not access %s"), _("Device %s not found: could not access %s"),
dev->name, dev->path); dev->name, dev->path);
goto cleanup; return NULL;
} }
vendor = virPCIDeviceReadID(dev, "vendor"); vendor = virPCIDeviceReadID(dev, "vendor");
...@@ -1787,7 +1786,7 @@ virPCIDeviceNew(unsigned int domain, ...@@ -1787,7 +1786,7 @@ virPCIDeviceNew(unsigned int domain,
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to read product/vendor ID for %s"), _("Failed to read product/vendor ID for %s"),
dev->name); dev->name);
goto cleanup; return NULL;
} }
/* strings contain '0x' prefix */ /* strings contain '0x' prefix */
...@@ -1796,15 +1795,12 @@ virPCIDeviceNew(unsigned int domain, ...@@ -1796,15 +1795,12 @@ virPCIDeviceNew(unsigned int domain,
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("dev->id buffer overflow: %s %s"), _("dev->id buffer overflow: %s %s"),
&vendor[2], &product[2]); &vendor[2], &product[2]);
goto cleanup; return NULL;
} }
VIR_DEBUG("%s %s: initialized", dev->id, dev->name); VIR_DEBUG("%s %s: initialized", dev->id, dev->name);
VIR_STEAL_PTR(ret, dev); VIR_RETURN_PTR(dev);
cleanup:
return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册