From: Ján Tomko Date: Fri, 3 Jun 2016 08:21:23 +0000 (+0200) Subject: Initialize ret to -1 in nodeStateInitialize X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=b2a55dfd1f7702e34322022fe54ff3ff072d047e;p=libvirt.git Initialize ret to -1 in nodeStateInitialize Most of the code paths had to reset it to -1 and returning 0 was only possible if we made it to the end of the function. Initialize it to -1 and only set it to 0 if we reach the end, as we do in most of libvirt code. --- diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c index 6bff5bac73..86862d68d1 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1680,7 +1680,7 @@ static int nodeStateInitialize(bool privileged, { udevPrivate *priv = NULL; struct udev *udev = NULL; - int ret = 0; + int ret = -1; #if defined __s390__ || defined __s390x_ /* On s390(x) system there is no PCI bus. @@ -1696,23 +1696,19 @@ static int nodeStateInitialize(bool privileged, char ebuf[256]; VIR_ERROR(_("Failed to initialize libpciaccess: %s"), virStrerror(pciret, ebuf, sizeof(ebuf))); - ret = -1; goto out; } } #endif - if (VIR_ALLOC(priv) < 0) { - ret = -1; + if (VIR_ALLOC(priv) < 0) goto out; - } priv->watch = -1; priv->privileged = privileged; if (VIR_ALLOC(driver) < 0) { VIR_FREE(priv); - ret = -1; goto out; } @@ -1720,7 +1716,6 @@ static int nodeStateInitialize(bool privileged, VIR_ERROR(_("Failed to initialize mutex for driver")); VIR_FREE(priv); VIR_FREE(driver); - ret = -1; goto out; } @@ -1742,7 +1737,6 @@ static int nodeStateInitialize(bool privileged, if (priv->udev_monitor == NULL) { VIR_FREE(priv); VIR_ERROR(_("udev_monitor_new_from_netlink returned NULL")); - ret = -1; goto out_unlock; } @@ -1762,23 +1756,19 @@ static int nodeStateInitialize(bool privileged, priv->watch = virEventAddHandle(udev_monitor_get_fd(priv->udev_monitor), VIR_EVENT_HANDLE_READABLE, udevEventHandleCallback, NULL, NULL); - if (priv->watch == -1) { - ret = -1; + if (priv->watch == -1) goto out_unlock; - } /* Create a fictional 'computer' device to root the device tree. */ - if (udevSetupSystemDev() != 0) { - ret = -1; + if (udevSetupSystemDev() != 0) goto out_unlock; - } /* Populate with known devices */ - if (udevEnumerateDevices(udev) != 0) { - ret = -1; + if (udevEnumerateDevices(udev) != 0) goto out_unlock; - } + + ret = 0; out_unlock: nodeDeviceUnlock();