]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virIndexToDiskName: Make 'idx' unsigned and remove check
authorPeter Krempa <pkrempa@redhat.com>
Wed, 3 Mar 2021 09:20:00 +0000 (10:20 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 5 Mar 2021 14:33:34 +0000 (15:33 +0100)
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@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/util/virutil.c
src/util/virutil.h
src/vmx/vmx.c
src/vz/vz_sdk.c

index 0f3cf986130fc45256a8b849649e939a0ca7f3bf..4c98e3f4bcb573130576d2aeccf34fab3436a5d5 100644 (file)
@@ -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);
index 46328727c1700e39f3de887e4ffcaeece27b50ee..854b4948906721af3619785cfd2978df0501e2da 100644 (file)
@@ -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
index 73bf7c4f3d62b73475ba8a92c76db290c6621c15..76d01a36de2cebda289d2b8bcf419918f6b0dc5e 100644 (file)
@@ -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'"),
index 6f712c7a31dd7cda932e925a4445df0b7007a4f1..d8548e5a3cfad14d19ca4611f878dc5610e1b265 100644 (file)
@@ -626,9 +626,6 @@ prlsdkGetDiskId(PRL_HANDLE disk, int *bus, char **dst)
         return -1;
     }
 
-    if (NULL == *dst)
-        return -1;
-
     return 0;
 }