We can remove the check that 'idx' is negative by forcing callers to pass unsigned numbers, which they do already or have a check that 'idx' is positive. This in turn allows us to remove most return value NULL checks. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/util/virutil.c | 8 +------- src/util/virutil.h | 2 +- src/vmx/vmx.c | 12 ------------ src/vz/vz_sdk.c | 3 --- 4 files changed, 2 insertions(+), 23 deletions(-) diff --git a/src/util/virutil.c b/src/util/virutil.c index a0cd0f1bcd..700ec02725 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -430,19 +430,13 @@ int virDiskNameToIndex(const char *name) return idx; } -char *virIndexToDiskName(int idx, const char *prefix) +char *virIndexToDiskName(unsigned int idx, const char *prefix) { char *name = NULL; size_t i; int ctr; int offset; - if (idx < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Disk index %d is negative"), idx); - return NULL; - } - for (i = 0, ctr = idx; ctr >= 0; ++i, ctr = ctr / 26 - 1) { } offset = strlen(prefix); diff --git a/src/util/virutil.h b/src/util/virutil.h index 46328727c1..854b494890 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -56,7 +56,7 @@ virFormatIntPretty(unsigned long long val, int virDiskNameParse(const char *name, int *disk, int *partition); int virDiskNameToIndex(const char* str); -char *virIndexToDiskName(int idx, const char *prefix); +char *virIndexToDiskName(unsigned int idx, const char *prefix); /* No-op workarounds for functionality missing in mingw. */ #ifndef WITH_GETUID diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index 73bf7c4f3d..76d01a36de 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -2217,9 +2217,6 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con (*def)->dst = virIndexToDiskName (controllerOrBus * 15 + (unit < 7 ? unit : unit - 1), "sd"); - - if ((*def)->dst == NULL) - goto cleanup; } else if (busType == VIR_DOMAIN_DISK_BUS_SATA) { if (controllerOrBus < 0 || controllerOrBus > 3) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -2238,9 +2235,6 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con prefix = g_strdup_printf("sata%d:%d", controllerOrBus, unit); (*def)->dst = virIndexToDiskName(controllerOrBus * 30 + unit, "sd"); - - if ((*def)->dst == NULL) - goto cleanup; } else if (busType == VIR_DOMAIN_DISK_BUS_IDE) { if (controllerOrBus < 0 || controllerOrBus > 1) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -2258,9 +2252,6 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con prefix = g_strdup_printf("ide%d:%d", controllerOrBus, unit); (*def)->dst = virIndexToDiskName(controllerOrBus * 2 + unit, "hd"); - - if ((*def)->dst == NULL) - goto cleanup; } else { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported bus type '%s' for device type '%s'"), @@ -2287,9 +2278,6 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con prefix = g_strdup_printf("floppy%d", unit); (*def)->dst = virIndexToDiskName(unit, "fd"); - - if ((*def)->dst == NULL) - goto cleanup; } else { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported bus type '%s' for device type '%s'"), diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c index 6f712c7a31..d8548e5a3c 100644 --- a/src/vz/vz_sdk.c +++ b/src/vz/vz_sdk.c @@ -626,9 +626,6 @@ prlsdkGetDiskId(PRL_HANDLE disk, int *bus, char **dst) return -1; } - if (NULL == *dst) - return -1; - return 0; } -- 2.29.2