From nobody Wed Dec 17 09:18:33 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1614768358; cv=none; d=zohomail.com; s=zohoarc; b=Fv1O/JIeeBuDWJoIxiu8qsUByOkjk/Dihhu/pXnWDzGMQ9atzkxddDOr/3P345IVd4dx1insGTjWoctFKoi8eiq0AC6lf+9vJpMICEAk0DS66QRr31uPEWGEQPuSLA8LqFn+xw94iK+8azbRmhHD2Ozu7AzzO+elgsFfLZ0aPo0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614768358; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rDJVmM+ReO17f1gwkTcMwf+Bm/vGTid7+EwJPbvvIL0=; b=L0fGsf8ZIkbXjR0Ie9pGUbJXy39R//stSCAtmWGJ6NmAXqQl/6yG3omuvW1W5uDAXgNovu+sdG6t6UfZCGRB0i51SkC/f9Wzf1yJsEiaBDQuMzEWqTtzgwOP2q1Vwad8t5U3bT4EtCWtn5EJlEepnjTGmL4rfYExBlJdz16atrU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 161476835801136.31637757813178; Wed, 3 Mar 2021 02:45:58 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-566-iTEPcsOGMNieLWP2__rAhw-1; Wed, 03 Mar 2021 05:45:54 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 10A1D189C447; Wed, 3 Mar 2021 10:45:48 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E05506F7EA; Wed, 3 Mar 2021 10:45:47 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 9363058079; Wed, 3 Mar 2021 10:45:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 123Ajhno027918 for ; Wed, 3 Mar 2021 05:45:43 -0500 Received: by smtp.corp.redhat.com (Postfix) id 583E4669EC; Wed, 3 Mar 2021 10:45:43 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id B8ADB66FFF for ; Wed, 3 Mar 2021 10:45:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614768356; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=rDJVmM+ReO17f1gwkTcMwf+Bm/vGTid7+EwJPbvvIL0=; b=HzILJButu4xqGSv3lMJHFlssXLNk9rVh0iYdhYJPar6jYSeDjKoeNaIXlYsJKSawpOvMqS FTB2rc0aw3yx9zLHUyF+De/99HNFG2QlK7WTVyTr7yWhd0ad9bxBE02zp2lnfMz44yQYGg uBsaib5POAZV+hapeTGGn/CQxzjzsZU= X-MC-Unique: iTEPcsOGMNieLWP2__rAhw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/5] virIndexToDiskName: Make 'idx' unsigned and remove check Date: Wed, 3 Mar 2021 11:45:33 +0100 Message-Id: <9db0d6c68a591b71455b317e07c394b0eb4e4eb4.1614768104.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" 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 --- 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 =3D 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 =3D 0, ctr =3D idx; ctr >=3D 0; ++i, ctr =3D ctr / 26 - 1) { } offset =3D 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, virDomainXMLOptio= nPtr xmlopt, virConfPtr con (*def)->dst =3D virIndexToDiskName (controllerOrBus * 15 + (unit < 7 ? unit : unit - 1), "sd= "); - - if ((*def)->dst =3D=3D NULL) - goto cleanup; } else if (busType =3D=3D VIR_DOMAIN_DISK_BUS_SATA) { if (controllerOrBus < 0 || controllerOrBus > 3) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -2238,9 +2235,6 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptio= nPtr xmlopt, virConfPtr con prefix =3D g_strdup_printf("sata%d:%d", controllerOrBus, unit); (*def)->dst =3D virIndexToDiskName(controllerOrBus * 30 + unit= , "sd"); - - if ((*def)->dst =3D=3D NULL) - goto cleanup; } else if (busType =3D=3D VIR_DOMAIN_DISK_BUS_IDE) { if (controllerOrBus < 0 || controllerOrBus > 1) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -2258,9 +2252,6 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptio= nPtr xmlopt, virConfPtr con prefix =3D g_strdup_printf("ide%d:%d", controllerOrBus, unit); (*def)->dst =3D virIndexToDiskName(controllerOrBus * 2 + unit,= "hd"); - - if ((*def)->dst =3D=3D NULL) - goto cleanup; } else { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported bus type '%s' for device type '%= s'"), @@ -2287,9 +2278,6 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptio= nPtr xmlopt, virConfPtr con prefix =3D g_strdup_printf("floppy%d", unit); (*def)->dst =3D virIndexToDiskName(unit, "fd"); - - if ((*def)->dst =3D=3D 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 =3D=3D *dst) - return -1; - return 0; } --=20 2.29.2