util: remove unneeded cleanup labels

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Daniel Henrique Barboza 2019-10-21 15:19:04 -03:00 committed by Ján Tomko
parent 5b05d99dab
commit 93af79fba3
17 changed files with 117 additions and 235 deletions

View File

@ -696,7 +696,6 @@ virCgroupV1AddTask(virCgroupPtr group,
pid_t pid, pid_t pid,
unsigned int flags) unsigned int flags)
{ {
int ret = -1;
size_t i; size_t i;
for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
@ -712,12 +711,10 @@ virCgroupV1AddTask(virCgroupPtr group,
continue; continue;
if (virCgroupSetValueI64(group, i, "tasks", pid) < 0) if (virCgroupSetValueI64(group, i, "tasks", pid) < 0)
goto cleanup; return -1;
} }
ret = 0; return 0;
cleanup:
return ret;
} }
@ -1818,18 +1815,13 @@ static int
virCgroupV1AllowAllDevices(virCgroupPtr group, virCgroupV1AllowAllDevices(virCgroupPtr group,
int perms) int perms)
{ {
int ret = -1;
if (virCgroupV1AllowDevice(group, 'b', -1, -1, perms) < 0) if (virCgroupV1AllowDevice(group, 'b', -1, -1, perms) < 0)
goto cleanup; return -1;
if (virCgroupV1AllowDevice(group, 'c', -1, -1, perms) < 0) if (virCgroupV1AllowDevice(group, 'c', -1, -1, perms) < 0)
goto cleanup; return -1;
ret = 0; return 0;
cleanup:
return ret;
} }

View File

@ -417,8 +417,6 @@ virCommandHandshakeChild(virCommandPtr cmd)
static int static int
virExecCommon(virCommandPtr cmd, gid_t *groups, int ngroups) virExecCommon(virCommandPtr cmd, gid_t *groups, int ngroups)
{ {
int ret = -1;
if (cmd->uid != (uid_t)-1 || cmd->gid != (gid_t)-1 || if (cmd->uid != (uid_t)-1 || cmd->gid != (gid_t)-1 ||
cmd->capabilities || (cmd->flags & VIR_EXEC_CLEAR_CAPS)) { cmd->capabilities || (cmd->flags & VIR_EXEC_CLEAR_CAPS)) {
VIR_DEBUG("Setting child uid:gid to %d:%d with caps %llx", VIR_DEBUG("Setting child uid:gid to %d:%d with caps %llx",
@ -426,7 +424,7 @@ virExecCommon(virCommandPtr cmd, gid_t *groups, int ngroups)
if (virSetUIDGIDWithCaps(cmd->uid, cmd->gid, groups, ngroups, if (virSetUIDGIDWithCaps(cmd->uid, cmd->gid, groups, ngroups,
cmd->capabilities, cmd->capabilities,
!!(cmd->flags & VIR_EXEC_CLEAR_CAPS)) < 0) !!(cmd->flags & VIR_EXEC_CLEAR_CAPS)) < 0)
goto cleanup; return -1;
} }
if (cmd->pwd) { if (cmd->pwd) {
@ -434,13 +432,10 @@ virExecCommon(virCommandPtr cmd, gid_t *groups, int ngroups)
if (chdir(cmd->pwd) < 0) { if (chdir(cmd->pwd) < 0) {
virReportSystemError(errno, virReportSystemError(errno,
_("Unable to change to %s"), cmd->pwd); _("Unable to change to %s"), cmd->pwd);
goto cleanup; return -1;
} }
} }
ret = 0; return 0;
cleanup:
return ret;
} }
# ifdef __linux__ # ifdef __linux__

View File

@ -1191,7 +1191,6 @@ int virDBusMessageDecodeArgs(DBusMessage* msg,
va_list args) va_list args)
{ {
DBusMessageIter iter; DBusMessageIter iter;
int ret = -1;
if (!dbus_message_iter_init(msg, &iter)) { if (!dbus_message_iter_init(msg, &iter)) {
if (*types != '\0') { if (*types != '\0') {
@ -1199,15 +1198,12 @@ int virDBusMessageDecodeArgs(DBusMessage* msg,
_("No args present for signature %s"), _("No args present for signature %s"),
types); types);
} else { } else {
ret = 0; return 0;
} }
goto cleanup; return -1;
} }
ret = virDBusMessageIterDecode(&iter, types, args); return virDBusMessageIterDecode(&iter, types, args);
cleanup:
return ret;
} }
@ -1396,25 +1392,21 @@ int virDBusCreateMethodV(DBusMessage **call,
const char *types, const char *types,
va_list args) va_list args)
{ {
int ret = -1;
if (!(*call = dbus_message_new_method_call(destination, if (!(*call = dbus_message_new_method_call(destination,
path, path,
iface, iface,
member))) { member))) {
virReportOOMError(); virReportOOMError();
goto cleanup; return -1;
} }
if (virDBusMessageEncodeArgs(*call, types, args) < 0) { if (virDBusMessageEncodeArgs(*call, types, args) < 0) {
virDBusMessageUnref(*call); virDBusMessageUnref(*call);
*call = NULL; *call = NULL;
goto cleanup; return -1;
} }
ret = 0; return 0;
cleanup:
return ret;
} }
@ -1468,22 +1460,18 @@ int virDBusCreateReplyV(DBusMessage **reply,
const char *types, const char *types,
va_list args) va_list args)
{ {
int ret = -1;
if (!(*reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN))) { if (!(*reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN))) {
virReportOOMError(); virReportOOMError();
goto cleanup; return -1;
} }
if (virDBusMessageEncodeArgs(*reply, types, args) < 0) { if (virDBusMessageEncodeArgs(*reply, types, args) < 0) {
virDBusMessageUnref(*reply); virDBusMessageUnref(*reply);
*reply = NULL; *reply = NULL;
goto cleanup; return -1;
} }
ret = 0; return 0;
cleanup:
return ret;
} }

View File

@ -3598,27 +3598,25 @@ int
virFileGetHugepageSize(const char *path, virFileGetHugepageSize(const char *path,
unsigned long long *size) unsigned long long *size)
{ {
int ret = -1;
struct statfs fs; struct statfs fs;
if (statfs(path, &fs) < 0) { if (statfs(path, &fs) < 0) {
virReportSystemError(errno, virReportSystemError(errno,
_("cannot determine filesystem for '%s'"), _("cannot determine filesystem for '%s'"),
path); path);
goto cleanup; return -1;
} }
if (fs.f_type != HUGETLBFS_MAGIC) { if (fs.f_type != HUGETLBFS_MAGIC) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("not a hugetlbfs mount: '%s'"), _("not a hugetlbfs mount: '%s'"),
path); path);
goto cleanup; return -1;
} }
*size = fs.f_bsize / 1024; /* we are storing size in KiB */ *size = fs.f_bsize / 1024; /* we are storing size in KiB */
ret = 0;
cleanup: return 0;
return ret;
} }
# define PROC_MEMINFO "/proc/meminfo" # define PROC_MEMINFO "/proc/meminfo"
@ -3790,12 +3788,11 @@ virFileSetupDev(const char *path,
{ {
const unsigned long mount_flags = MS_NOSUID; const unsigned long mount_flags = MS_NOSUID;
const char *mount_fs = "tmpfs"; const char *mount_fs = "tmpfs";
int ret = -1;
if (virFileMakePath(path) < 0) { if (virFileMakePath(path) < 0) {
virReportSystemError(errno, virReportSystemError(errno,
_("Failed to make path %s"), path); _("Failed to make path %s"), path);
goto cleanup; return -1;
} }
VIR_DEBUG("Mount devfs on %s type=tmpfs flags=0x%lx, opts=%s", VIR_DEBUG("Mount devfs on %s type=tmpfs flags=0x%lx, opts=%s",
@ -3804,12 +3801,10 @@ virFileSetupDev(const char *path,
virReportSystemError(errno, virReportSystemError(errno,
_("Failed to mount devfs on %s type %s (%s)"), _("Failed to mount devfs on %s type %s (%s)"),
path, mount_fs, mount_options); path, mount_fs, mount_options);
goto cleanup; return -1;
} }
ret = 0; return 0;
cleanup:
return ret;
} }

View File

@ -646,15 +646,13 @@ virHashForEach(virHashTablePtr table, virHashIterator iter, void *data)
ret = iter(entry->payload, entry->name, data); ret = iter(entry->payload, entry->name, data);
if (ret < 0) if (ret < 0)
goto cleanup; return ret;
entry = next; entry = next;
} }
} }
ret = 0; return 0;
cleanup:
return ret;
} }

View File

@ -773,7 +773,6 @@ virHostCPUGetStatsLinux(FILE *procstat,
virNodeCPUStatsPtr params, virNodeCPUStatsPtr params,
int *nparams) int *nparams)
{ {
int ret = -1;
char line[1024]; char line[1024];
unsigned long long usr, ni, sys, idle, iowait; unsigned long long usr, ni, sys, idle, iowait;
unsigned long long irq, softirq, steal, guest, guest_nice; unsigned long long irq, softirq, steal, guest, guest_nice;
@ -782,15 +781,14 @@ virHostCPUGetStatsLinux(FILE *procstat,
if ((*nparams) == 0) { if ((*nparams) == 0) {
/* Current number of cpu stats supported by linux */ /* Current number of cpu stats supported by linux */
*nparams = LINUX_NB_CPU_STATS; *nparams = LINUX_NB_CPU_STATS;
ret = 0; return 0;
goto cleanup;
} }
if ((*nparams) != LINUX_NB_CPU_STATS) { if ((*nparams) != LINUX_NB_CPU_STATS) {
virReportInvalidArg(*nparams, virReportInvalidArg(*nparams,
_("nparams in %s must be equal to %d"), _("nparams in %s must be equal to %d"),
__FUNCTION__, LINUX_NB_CPU_STATS); __FUNCTION__, LINUX_NB_CPU_STATS);
goto cleanup; return -1;
} }
if (cpuNum == VIR_NODE_CPU_STATS_ALL_CPUS) { if (cpuNum == VIR_NODE_CPU_STATS_ALL_CPUS) {
@ -813,22 +811,21 @@ virHostCPUGetStatsLinux(FILE *procstat,
if (virHostCPUStatsAssign(&params[0], VIR_NODE_CPU_STATS_KERNEL, if (virHostCPUStatsAssign(&params[0], VIR_NODE_CPU_STATS_KERNEL,
(sys + irq + softirq) * TICK_TO_NSEC) < 0) (sys + irq + softirq) * TICK_TO_NSEC) < 0)
goto cleanup; return -1;
if (virHostCPUStatsAssign(&params[1], VIR_NODE_CPU_STATS_USER, if (virHostCPUStatsAssign(&params[1], VIR_NODE_CPU_STATS_USER,
(usr + ni) * TICK_TO_NSEC) < 0) (usr + ni) * TICK_TO_NSEC) < 0)
goto cleanup; return -1;
if (virHostCPUStatsAssign(&params[2], VIR_NODE_CPU_STATS_IDLE, if (virHostCPUStatsAssign(&params[2], VIR_NODE_CPU_STATS_IDLE,
idle * TICK_TO_NSEC) < 0) idle * TICK_TO_NSEC) < 0)
goto cleanup; return -1;
if (virHostCPUStatsAssign(&params[3], VIR_NODE_CPU_STATS_IOWAIT, if (virHostCPUStatsAssign(&params[3], VIR_NODE_CPU_STATS_IOWAIT,
iowait * TICK_TO_NSEC) < 0) iowait * TICK_TO_NSEC) < 0)
goto cleanup; return -1;
ret = 0; return 0;
goto cleanup;
} }
} }
@ -836,8 +833,7 @@ virHostCPUGetStatsLinux(FILE *procstat,
_("Invalid cpuNum in %s"), _("Invalid cpuNum in %s"),
__FUNCTION__); __FUNCTION__);
cleanup: return 0;
return ret;
} }

View File

@ -80,7 +80,6 @@ struct virHostdevIsPCINodeDeviceUsedData {
static int virHostdevIsPCINodeDeviceUsed(virPCIDeviceAddressPtr devAddr, void *opaque) static int virHostdevIsPCINodeDeviceUsed(virPCIDeviceAddressPtr devAddr, void *opaque)
{ {
virPCIDevicePtr actual; virPCIDevicePtr actual;
int ret = -1;
struct virHostdevIsPCINodeDeviceUsedData *helperData = opaque; struct virHostdevIsPCINodeDeviceUsedData *helperData = opaque;
actual = virPCIDeviceListFindByIDs(helperData->mgr->activePCIHostdevs, actual = virPCIDeviceListFindByIDs(helperData->mgr->activePCIHostdevs,
@ -106,12 +105,10 @@ static int virHostdevIsPCINodeDeviceUsed(virPCIDeviceAddressPtr devAddr, void *o
virReportError(VIR_ERR_OPERATION_INVALID, virReportError(VIR_ERR_OPERATION_INVALID,
_("PCI device %s is in use"), _("PCI device %s is in use"),
virPCIDeviceGetName(actual)); virPCIDeviceGetName(actual));
goto cleanup; return -1;
} }
iommu_owner: iommu_owner:
ret = 0; return 0;
cleanup:
return ret;
} }
static int virHostdevManagerOnceInit(void) static int virHostdevManagerOnceInit(void)

View File

@ -142,7 +142,6 @@ virHostMemGetStatsLinux(FILE *meminfo,
virNodeMemoryStatsPtr params, virNodeMemoryStatsPtr params,
int *nparams) int *nparams)
{ {
int ret = -1;
size_t i = 0, j = 0, k = 0; size_t i = 0, j = 0, k = 0;
int found = 0; int found = 0;
int nr_param; int nr_param;
@ -169,15 +168,14 @@ virHostMemGetStatsLinux(FILE *meminfo,
if ((*nparams) == 0) { if ((*nparams) == 0) {
/* Current number of memory stats supported by linux */ /* Current number of memory stats supported by linux */
*nparams = nr_param; *nparams = nr_param;
ret = 0; return 0;
goto cleanup;
} }
if ((*nparams) != nr_param) { if ((*nparams) != nr_param) {
virReportInvalidArg(nparams, virReportInvalidArg(nparams,
_("nparams in %s must be %d"), _("nparams in %s must be %d"),
__FUNCTION__, nr_param); __FUNCTION__, nr_param);
goto cleanup; return -1;
} }
while (fgets(line, sizeof(line), meminfo) != NULL) { while (fgets(line, sizeof(line), meminfo) != NULL) {
@ -200,7 +198,7 @@ virHostMemGetStatsLinux(FILE *meminfo,
if (p == NULL) { if (p == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("no prefix found")); "%s", _("no prefix found"));
goto cleanup; return -1;
} }
p++; p++;
} }
@ -219,7 +217,7 @@ virHostMemGetStatsLinux(FILE *meminfo,
if (virStrcpyStatic(param->field, convp->field) < 0) { if (virStrcpyStatic(param->field, convp->field) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Field kernel memory too long for destination")); "%s", _("Field kernel memory too long for destination"));
goto cleanup; return -1;
} }
param->value = val; param->value = val;
found++; found++;
@ -233,13 +231,10 @@ virHostMemGetStatsLinux(FILE *meminfo,
if (found == 0) { if (found == 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("no available memory line found")); "%s", _("no available memory line found"));
goto cleanup; return -1;
} }
ret = 0; return 0;
cleanup:
return ret;
} }
#endif #endif
@ -611,14 +606,12 @@ static int
virHostMemGetInfoFake(unsigned long long *mem, virHostMemGetInfoFake(unsigned long long *mem,
unsigned long long *freeMem) unsigned long long *freeMem)
{ {
int ret = -1;
if (mem) { if (mem) {
double total = physmem_total(); double total = physmem_total();
if (!total) { if (!total) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Cannot determine free memory")); _("Cannot determine free memory"));
goto cleanup; return -1;
} }
*mem = (unsigned long long) total; *mem = (unsigned long long) total;
@ -630,15 +623,13 @@ virHostMemGetInfoFake(unsigned long long *mem,
if (!avail) { if (!avail) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Cannot determine free memory")); _("Cannot determine free memory"));
goto cleanup; return -1;
} }
*freeMem = (unsigned long long) avail; *freeMem = (unsigned long long) avail;
} }
ret = 0; return 0;
cleanup:
return ret;
} }
@ -649,7 +640,6 @@ virHostMemGetCellsFree(unsigned long long *freeMems,
{ {
unsigned long long mem; unsigned long long mem;
int n, lastCell, numCells; int n, lastCell, numCells;
int ret = -1;
int maxCell; int maxCell;
if (!virNumaIsAvailable()) if (!virNumaIsAvailable())
@ -663,7 +653,7 @@ virHostMemGetCellsFree(unsigned long long *freeMems,
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("start cell %d out of range (0-%d)"), _("start cell %d out of range (0-%d)"),
startCell, maxCell); startCell, maxCell);
goto cleanup; return -1;
} }
lastCell = startCell + maxCells - 1; lastCell = startCell + maxCells - 1;
if (lastCell > maxCell) if (lastCell > maxCell)
@ -674,10 +664,7 @@ virHostMemGetCellsFree(unsigned long long *freeMems,
freeMems[numCells++] = mem; freeMems[numCells++] = mem;
} }
ret = numCells; return numCells;
cleanup:
return ret;
} }
int int
@ -725,7 +712,6 @@ virHostMemGetFreePages(unsigned int npages,
unsigned int cellCount, unsigned int cellCount,
unsigned long long *counts) unsigned long long *counts)
{ {
int ret = -1;
int cell, lastCell; int cell, lastCell;
size_t i, ncounts = 0; size_t i, ncounts = 0;
@ -736,7 +722,7 @@ virHostMemGetFreePages(unsigned int npages,
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("start cell %d out of range (0-%d)"), _("start cell %d out of range (0-%d)"),
startCell, lastCell); startCell, lastCell);
goto cleanup; return -1;
} }
lastCell = MIN(lastCell, startCell + (int) cellCount - 1); lastCell = MIN(lastCell, startCell + (int) cellCount - 1);
@ -747,7 +733,7 @@ virHostMemGetFreePages(unsigned int npages,
unsigned long long page_free; unsigned long long page_free;
if (virNumaGetPageInfo(cell, page_size, 0, NULL, &page_free) < 0) if (virNumaGetPageInfo(cell, page_size, 0, NULL, &page_free) < 0)
goto cleanup; return -1;
counts[ncounts++] = page_free; counts[ncounts++] = page_free;
} }
@ -756,12 +742,10 @@ virHostMemGetFreePages(unsigned int npages,
if (!ncounts) { if (!ncounts) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("no suitable info found")); _("no suitable info found"));
goto cleanup; return -1;
} }
ret = ncounts; return ncounts;
cleanup:
return ret;
} }
int int
@ -772,7 +756,6 @@ virHostMemAllocPages(unsigned int npages,
unsigned int cellCount, unsigned int cellCount,
bool add) bool add)
{ {
int ret = -1;
int cell, lastCell; int cell, lastCell;
size_t i, ncounts = 0; size_t i, ncounts = 0;
@ -783,7 +766,7 @@ virHostMemAllocPages(unsigned int npages,
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("start cell %d out of range (0-%d)"), _("start cell %d out of range (0-%d)"),
startCell, lastCell); startCell, lastCell);
goto cleanup; return -1;
} }
lastCell = MIN(lastCell, startCell + (int) cellCount - 1); lastCell = MIN(lastCell, startCell + (int) cellCount - 1);
@ -794,13 +777,11 @@ virHostMemAllocPages(unsigned int npages,
unsigned long long page_count = pageCounts[i]; unsigned long long page_count = pageCounts[i];
if (virNumaSetPagePoolSize(cell, page_size, page_count, add) < 0) if (virNumaSetPagePoolSize(cell, page_size, page_count, add) < 0)
goto cleanup; return -1;
ncounts++; ncounts++;
} }
} }
ret = ncounts; return ncounts;
cleanup:
return ret;
} }

View File

@ -160,7 +160,6 @@ virJSONValueObjectAddVArgs(virJSONValuePtr obj,
{ {
char type; char type;
char *key; char *key;
int ret = -1;
int rc; int rc;
while ((key = va_arg(args, char *)) != NULL) { while ((key = va_arg(args, char *)) != NULL) {
@ -169,7 +168,7 @@ virJSONValueObjectAddVArgs(virJSONValuePtr obj,
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("argument key '%s' is too short, missing type prefix"), _("argument key '%s' is too short, missing type prefix"),
key); key);
goto cleanup; return -1;
} }
type = key[0]; type = key[0];
@ -187,7 +186,7 @@ virJSONValueObjectAddVArgs(virJSONValuePtr obj,
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("argument key '%s' must not have null value"), _("argument key '%s' must not have null value"),
key); key);
goto cleanup; return -1;
} }
rc = virJSONValueObjectAppendString(obj, key, val); rc = virJSONValueObjectAppendString(obj, key, val);
} break; } break;
@ -202,7 +201,7 @@ virJSONValueObjectAddVArgs(virJSONValuePtr obj,
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("argument key '%s' must not be negative"), _("argument key '%s' must not be negative"),
key); key);
goto cleanup; return -1;
} }
if (!val && (type == 'z' || type == 'y')) if (!val && (type == 'z' || type == 'y'))
@ -231,7 +230,7 @@ virJSONValueObjectAddVArgs(virJSONValuePtr obj,
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("argument key '%s' must not be negative"), _("argument key '%s' must not be negative"),
key); key);
goto cleanup; return -1;
} }
if (!val && (type == 'Z' || type == 'Y')) if (!val && (type == 'Z' || type == 'Y'))
@ -296,7 +295,7 @@ virJSONValueObjectAddVArgs(virJSONValuePtr obj,
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("argument key '%s' must not have null value"), _("argument key '%s' must not have null value"),
key); key);
goto cleanup; return -1;
} }
if ((rc = virJSONValueObjectAppend(obj, key, *val)) == 0) if ((rc = virJSONValueObjectAppend(obj, key, *val)) == 0)
@ -315,11 +314,11 @@ virJSONValueObjectAddVArgs(virJSONValuePtr obj,
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("argument key '%s' must not have null value"), _("argument key '%s' must not have null value"),
key); key);
goto cleanup; return -1;
} }
if (!(jsonMap = virJSONValueNewArrayFromBitmap(map))) if (!(jsonMap = virJSONValueNewArrayFromBitmap(map)))
goto cleanup; return -1;
if ((rc = virJSONValueObjectAppend(obj, key, jsonMap)) < 0) if ((rc = virJSONValueObjectAppend(obj, key, jsonMap)) < 0)
virJSONValueFree(jsonMap); virJSONValueFree(jsonMap);
@ -328,23 +327,18 @@ virJSONValueObjectAddVArgs(virJSONValuePtr obj,
default: default:
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("unsupported data type '%c' for arg '%s'"), type, key - 2); _("unsupported data type '%c' for arg '%s'"), type, key - 2);
goto cleanup; return -1;
} }
if (rc < 0) if (rc < 0)
goto cleanup; return -1;
} }
/* verify that we added at least one key-value pair */ /* verify that we added at least one key-value pair */
if (virJSONValueObjectKeysNumber(obj) == 0) { if (virJSONValueObjectKeysNumber(obj) == 0)
ret = 0; return 0;
goto cleanup;
}
ret = 1; return 1;
cleanup:
return ret;
} }

View File

@ -85,22 +85,18 @@ virMacMapAddLocked(virMacMapPtr mgr,
const char *domain, const char *domain,
const char *mac) const char *mac)
{ {
int ret = -1;
char **macsList = NULL; char **macsList = NULL;
if ((macsList = virHashLookup(mgr->macs, domain)) && if ((macsList = virHashLookup(mgr->macs, domain)) &&
virStringListHasString((const char**) macsList, mac)) { virStringListHasString((const char**) macsList, mac)) {
ret = 0; return 0;
goto cleanup;
} }
if (virStringListAdd(&macsList, mac) < 0 || if (virStringListAdd(&macsList, mac) < 0 ||
virHashUpdateEntry(mgr->macs, domain, macsList) < 0) virHashUpdateEntry(mgr->macs, domain, macsList) < 0)
goto cleanup; return -1;
ret = 0; return 0;
cleanup:
return ret;
} }

View File

@ -270,16 +270,13 @@ virNetDevBridgePortGetLearning(const char *brname,
const char *ifname, const char *ifname,
bool *enable) bool *enable)
{ {
int ret = -1;
unsigned long value; unsigned long value;
if (virNetDevBridgePortGet(brname, ifname, "learning", &value) < 0) if (virNetDevBridgePortGet(brname, ifname, "learning", &value) < 0)
goto cleanup; return -1;
*enable = !!value; *enable = !!value;
ret = 0; return 0;
cleanup:
return ret;
} }
@ -297,16 +294,13 @@ virNetDevBridgePortGetUnicastFlood(const char *brname,
const char *ifname, const char *ifname,
bool *enable) bool *enable)
{ {
int ret = -1;
unsigned long value; unsigned long value;
if (virNetDevBridgePortGet(brname, ifname, "unicast_flood", &value) < 0) if (virNetDevBridgePortGet(brname, ifname, "unicast_flood", &value) < 0)
goto cleanup; return -1;
*enable = !!value; *enable = !!value;
ret = 0; return 0;
cleanup:
return ret;
} }
@ -887,16 +881,13 @@ int
virNetDevBridgeGetVlanFiltering(const char *brname, virNetDevBridgeGetVlanFiltering(const char *brname,
bool *enable) bool *enable)
{ {
int ret = -1;
unsigned long value; unsigned long value;
if (virNetDevBridgeGet(brname, "vlan_filtering", &value) < 0) if (virNetDevBridgeGet(brname, "vlan_filtering", &value) < 0)
goto cleanup; return -1;
*enable = !!value; *enable = !!value;
ret = 0; return 0;
cleanup:
return ret;
} }

View File

@ -93,7 +93,6 @@ virNumaSetupMemoryPolicy(virDomainNumatuneMemMode mode,
{ {
nodemask_t mask; nodemask_t mask;
int node = -1; int node = -1;
int ret = -1;
int bit = 0; int bit = 0;
size_t i; size_t i;
int maxnode = 0; int maxnode = 0;
@ -140,7 +139,7 @@ virNumaSetupMemoryPolicy(virDomainNumatuneMemMode mode,
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("NUMA memory tuning in 'preferred' mode " "%s", _("NUMA memory tuning in 'preferred' mode "
"only supports single node")); "only supports single node"));
goto cleanup; return -1;
} }
numa_set_bind_policy(0); numa_set_bind_policy(0);
@ -155,10 +154,8 @@ virNumaSetupMemoryPolicy(virDomainNumatuneMemMode mode,
case VIR_DOMAIN_NUMATUNE_MEM_LAST: case VIR_DOMAIN_NUMATUNE_MEM_LAST:
break; break;
} }
ret = 0;
cleanup: return 0;
return ret;
} }
bool bool
@ -466,7 +463,6 @@ virNumaGetDistances(int node,
int **distances, int **distances,
int *ndistances) int *ndistances)
{ {
int ret = -1;
int max_node; int max_node;
size_t i; size_t i;
@ -478,10 +474,10 @@ virNumaGetDistances(int node,
} }
if ((max_node = virNumaGetMaxNode()) < 0) if ((max_node = virNumaGetMaxNode()) < 0)
goto cleanup; return -1;
if (VIR_ALLOC_N(*distances, max_node + 1) < 0) if (VIR_ALLOC_N(*distances, max_node + 1) < 0)
goto cleanup; return -1;
*ndistances = max_node + 1; *ndistances = max_node + 1;
@ -492,9 +488,7 @@ virNumaGetDistances(int node,
(*distances)[i] = numa_distance(node, i); (*distances)[i] = numa_distance(node, i);
} }
ret = 0; return 0;
cleanup:
return ret;
} }
#else /* !(WITH_NUMACTL && HAVE_NUMA_BITMASK_ISBITSET) */ #else /* !(WITH_NUMACTL && HAVE_NUMA_BITMASK_ISBITSET) */
@ -685,7 +679,6 @@ virNumaGetPageInfo(int node,
unsigned long long *page_avail, unsigned long long *page_avail,
unsigned long long *page_free) unsigned long long *page_free)
{ {
int ret = -1;
long system_page_size = virGetSystemPageSize(); long system_page_size = virGetSystemPageSize();
/* sysconf() returns page size in bytes, /* sysconf() returns page size in bytes,
@ -697,10 +690,10 @@ virNumaGetPageInfo(int node,
* account. The problem is huge pages cut off regular memory. */ * account. The problem is huge pages cut off regular memory. */
if (node == -1) { if (node == -1) {
if (virHostMemGetInfo(&memsize, &memfree) < 0) if (virHostMemGetInfo(&memsize, &memfree) < 0)
goto cleanup; return -1;
} else { } else {
if (virNumaGetNodeMemory(node, &memsize, &memfree) < 0) if (virNumaGetNodeMemory(node, &memsize, &memfree) < 0)
goto cleanup; return -1;
} }
/* see description above */ /* see description above */
@ -713,12 +706,10 @@ virNumaGetPageInfo(int node,
*page_free = memfree / system_page_size; *page_free = memfree / system_page_size;
} else { } else {
if (virNumaGetHugePageInfo(node, page_size, page_avail, page_free) < 0) if (virNumaGetHugePageInfo(node, page_size, page_avail, page_free) < 0)
goto cleanup; return -1;
} }
ret = 0; return 0;
cleanup:
return ret;
} }

View File

@ -1890,18 +1890,15 @@ virPCIDeviceAddressGetIOMMUGroupAddresses(virPCIDeviceAddressPtr devAddr,
virPCIDeviceAddressPtr **iommuGroupDevices, virPCIDeviceAddressPtr **iommuGroupDevices,
size_t *nIommuGroupDevices) size_t *nIommuGroupDevices)
{ {
int ret = -1;
virPCIDeviceAddressList addrList = { iommuGroupDevices, virPCIDeviceAddressList addrList = { iommuGroupDevices,
nIommuGroupDevices }; nIommuGroupDevices };
if (virPCIDeviceAddressIOMMUGroupIterate(devAddr, if (virPCIDeviceAddressIOMMUGroupIterate(devAddr,
virPCIGetIOMMUGroupAddressesAddOne, virPCIGetIOMMUGroupAddressesAddOne,
&addrList) < 0) &addrList) < 0)
goto cleanup; return -1;
ret = 0; return 0;
cleanup:
return ret;
} }

View File

@ -349,7 +349,6 @@ int
virProcessKillPainfullyDelay(pid_t pid, bool force, unsigned int extradelay) virProcessKillPainfullyDelay(pid_t pid, bool force, unsigned int extradelay)
{ {
size_t i; size_t i;
int ret = -1;
/* This is in 1/5th seconds since polling is on a 0.2s interval */ /* This is in 1/5th seconds since polling is on a 0.2s interval */
unsigned int polldelay = (force ? 200 : 75) + (extradelay*5); unsigned int polldelay = (force ? 200 : 75) + (extradelay*5);
const char *signame = "TERM"; const char *signame = "TERM";
@ -393,10 +392,9 @@ virProcessKillPainfullyDelay(pid_t pid, bool force, unsigned int extradelay)
virReportSystemError(errno, virReportSystemError(errno,
_("Failed to terminate process %lld with SIG%s"), _("Failed to terminate process %lld with SIG%s"),
(long long)pid, signame); (long long)pid, signame);
goto cleanup; return -1;
} }
ret = signum == SIGTERM ? 0 : 1; return signum == SIGTERM ? 0 : 1;
goto cleanup; /* process is dead */
} }
g_usleep(200 * 1000); g_usleep(200 * 1000);
@ -406,8 +404,7 @@ virProcessKillPainfullyDelay(pid_t pid, bool force, unsigned int extradelay)
_("Failed to terminate process %lld with SIG%s"), _("Failed to terminate process %lld with SIG%s"),
(long long)pid, signame); (long long)pid, signame);
cleanup: return 0;
return ret;
} }
@ -1177,23 +1174,19 @@ virProcessRunInFork(virProcessForkCallback cb,
int int
virProcessSetupPrivateMountNS(void) virProcessSetupPrivateMountNS(void)
{ {
int ret = -1;
if (unshare(CLONE_NEWNS) < 0) { if (unshare(CLONE_NEWNS) < 0) {
virReportSystemError(errno, "%s", virReportSystemError(errno, "%s",
_("Cannot unshare mount namespace")); _("Cannot unshare mount namespace"));
goto cleanup; return -1;
} }
if (mount("", "/", "none", MS_SLAVE|MS_REC, NULL) < 0) { if (mount("", "/", "none", MS_SLAVE|MS_REC, NULL) < 0) {
virReportSystemError(errno, "%s", virReportSystemError(errno, "%s",
_("Failed to switch root mount into slave mode")); _("Failed to switch root mount into slave mode"));
goto cleanup; return -1;
} }
ret = 0; return 0;
cleanup:
return ret;
} }
#else /* !defined(HAVE_SYS_MOUNT_H) || !defined(HAVE_UNSHARE) */ #else /* !defined(HAVE_SYS_MOUNT_H) || !defined(HAVE_UNSHARE) */

View File

@ -871,7 +871,6 @@ virResctrlInfoGetCache(virResctrlInfoPtr resctrl,
virResctrlInfoPerLevelPtr i_level = NULL; virResctrlInfoPerLevelPtr i_level = NULL;
virResctrlInfoPerTypePtr i_type = NULL; virResctrlInfoPerTypePtr i_type = NULL;
size_t i = 0; size_t i = 0;
int ret = -1;
if (virResctrlInfoIsEmpty(resctrl)) if (virResctrlInfoIsEmpty(resctrl))
return 0; return 0;
@ -928,14 +927,12 @@ virResctrlInfoGetCache(virResctrlInfoPtr resctrl,
memcpy((*controls)[*ncontrols - 1], &i_type->control, sizeof(i_type->control)); memcpy((*controls)[*ncontrols - 1], &i_type->control, sizeof(i_type->control));
} }
ret = 0; return 0;
cleanup:
return ret;
error: error:
while (*ncontrols) while (*ncontrols)
VIR_FREE((*controls)[--*ncontrols]); VIR_FREE((*controls)[--*ncontrols]);
VIR_FREE(*controls); VIR_FREE(*controls);
goto cleanup; return -1;
} }

View File

@ -601,11 +601,10 @@ vmdk4GetBackingStore(char **res,
static const char prefix[] = "parentFileNameHint=\""; static const char prefix[] = "parentFileNameHint=\"";
char *start, *end; char *start, *end;
size_t len; size_t len;
int ret = BACKING_STORE_ERROR;
g_autofree char *desc = NULL; g_autofree char *desc = NULL;
if (VIR_ALLOC_N(desc, VIR_STORAGE_MAX_HEADER) < 0) if (VIR_ALLOC_N(desc, VIR_STORAGE_MAX_HEADER) < 0)
goto cleanup; return BACKING_STORE_ERROR;
*res = NULL; *res = NULL;
/* /*
@ -617,10 +616,9 @@ vmdk4GetBackingStore(char **res,
*/ */
*format = VIR_STORAGE_FILE_AUTO; *format = VIR_STORAGE_FILE_AUTO;
if (buf_size <= 0x200) { if (buf_size <= 0x200)
ret = BACKING_STORE_INVALID; return BACKING_STORE_INVALID;
goto cleanup;
}
len = buf_size - 0x200; len = buf_size - 0x200;
if (len > VIR_STORAGE_MAX_HEADER) if (len > VIR_STORAGE_MAX_HEADER)
len = VIR_STORAGE_MAX_HEADER; len = VIR_STORAGE_MAX_HEADER;
@ -629,27 +627,21 @@ vmdk4GetBackingStore(char **res,
start = strstr(desc, prefix); start = strstr(desc, prefix);
if (start == NULL) { if (start == NULL) {
*format = VIR_STORAGE_FILE_NONE; *format = VIR_STORAGE_FILE_NONE;
ret = BACKING_STORE_OK; return BACKING_STORE_OK;
goto cleanup;
} }
start += strlen(prefix); start += strlen(prefix);
end = strchr(start, '"'); end = strchr(start, '"');
if (end == NULL) { if (end == NULL)
ret = BACKING_STORE_INVALID; return BACKING_STORE_INVALID;
goto cleanup;
}
if (end == start) { if (end == start) {
*format = VIR_STORAGE_FILE_NONE; *format = VIR_STORAGE_FILE_NONE;
ret = BACKING_STORE_OK; return BACKING_STORE_OK;
goto cleanup;
} }
*end = '\0'; *end = '\0';
*res = g_strdup(start); *res = g_strdup(start);
ret = BACKING_STORE_OK; return BACKING_STORE_OK;
cleanup:
return ret;
} }
static int static int
@ -2382,20 +2374,15 @@ virStorageSourceInitChainElement(virStorageSourcePtr newelem,
virStorageSourcePtr old, virStorageSourcePtr old,
bool transferLabels) bool transferLabels)
{ {
int ret = -1;
if (transferLabels && if (transferLabels &&
!newelem->seclabels && !newelem->seclabels &&
virStorageSourceSeclabelsCopy(newelem, old) < 0) virStorageSourceSeclabelsCopy(newelem, old) < 0)
goto cleanup; return -1;
newelem->shared = old->shared; newelem->shared = old->shared;
newelem->readonly = old->readonly; newelem->readonly = old->readonly;
ret = 0; return 0;
cleanup:
return ret;
} }
@ -3426,7 +3413,6 @@ virStorageSourceParseBackingJSONRBD(virStorageSourcePtr src,
virJSONValuePtr servers = virJSONValueObjectGetArray(json, "server"); virJSONValuePtr servers = virJSONValueObjectGetArray(json, "server");
size_t nservers; size_t nservers;
size_t i; size_t i;
int ret = -1;
src->type = VIR_STORAGE_TYPE_NETWORK; src->type = VIR_STORAGE_TYPE_NETWORK;
src->protocol = VIR_STORAGE_NET_PROTOCOL_RBD; src->protocol = VIR_STORAGE_NET_PROTOCOL_RBD;
@ -3451,20 +3437,18 @@ virStorageSourceParseBackingJSONRBD(virStorageSourcePtr src,
nservers = virJSONValueArraySize(servers); nservers = virJSONValueArraySize(servers);
if (VIR_ALLOC_N(src->hosts, nservers) < 0) if (VIR_ALLOC_N(src->hosts, nservers) < 0)
goto cleanup; return -1;
src->nhosts = nservers; src->nhosts = nservers;
for (i = 0; i < nservers; i++) { for (i = 0; i < nservers; i++) {
if (virStorageSourceParseBackingJSONInetSocketAddress(src->hosts + i, if (virStorageSourceParseBackingJSONInetSocketAddress(src->hosts + i,
virJSONValueArrayGet(servers, i)) < 0) virJSONValueArrayGet(servers, i)) < 0)
goto cleanup; return -1;
} }
} }
ret = 0; return 0;
cleanup:
return ret;
} }
static int static int

View File

@ -1331,7 +1331,7 @@ virSetUIDGIDWithCaps(uid_t uid, gid_t gid, gid_t *groups, int ngroups,
unsigned long long capBits, bool clearExistingCaps) unsigned long long capBits, bool clearExistingCaps)
{ {
size_t i; size_t i;
int capng_ret, ret = -1; int capng_ret;
bool need_setgid = false; bool need_setgid = false;
bool need_setuid = false; bool need_setuid = false;
bool need_setpcap = false; bool need_setpcap = false;
@ -1383,7 +1383,7 @@ virSetUIDGIDWithCaps(uid_t uid, gid_t gid, gid_t *groups, int ngroups,
if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0)) { if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0)) {
virReportSystemError(errno, "%s", virReportSystemError(errno, "%s",
_("prctl failed to set KEEPCAPS")); _("prctl failed to set KEEPCAPS"));
goto cleanup; return -1;
} }
/* Change to the temp capabilities */ /* Change to the temp capabilities */
@ -1401,18 +1401,18 @@ virSetUIDGIDWithCaps(uid_t uid, gid_t gid, gid_t *groups, int ngroups,
} else { } else {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot apply process capabilities %d"), capng_ret); _("cannot apply process capabilities %d"), capng_ret);
goto cleanup; return -1;
} }
} }
if (virSetUIDGID(uid, gid, groups, ngroups) < 0) if (virSetUIDGID(uid, gid, groups, ngroups) < 0)
goto cleanup; return -1;
/* Tell it we are done keeping capabilities */ /* Tell it we are done keeping capabilities */
if (prctl(PR_SET_KEEPCAPS, 0, 0, 0, 0)) { if (prctl(PR_SET_KEEPCAPS, 0, 0, 0, 0)) {
virReportSystemError(errno, "%s", virReportSystemError(errno, "%s",
_("prctl failed to reset KEEPCAPS")); _("prctl failed to reset KEEPCAPS"));
goto cleanup; return -1;
} }
# ifdef PR_CAP_AMBIENT # ifdef PR_CAP_AMBIENT
@ -1430,7 +1430,7 @@ virSetUIDGIDWithCaps(uid_t uid, gid_t gid, gid_t *groups, int ngroups,
_("prctl failed to enable '%s' in the " _("prctl failed to enable '%s' in the "
"AMBIENT set"), "AMBIENT set"),
capstr); capstr);
goto cleanup; return -1;
} }
} }
} }
@ -1454,13 +1454,10 @@ virSetUIDGIDWithCaps(uid_t uid, gid_t gid, gid_t *groups, int ngroups,
if (((capng_ret = capng_apply(CAPNG_SELECT_CAPS)) < 0)) { if (((capng_ret = capng_apply(CAPNG_SELECT_CAPS)) < 0)) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot apply process capabilities %d"), capng_ret); _("cannot apply process capabilities %d"), capng_ret);
ret = -1; return -1;
goto cleanup;
} }
ret = 0; return 0;
cleanup:
return ret;
} }
#else #else