From nobody Mon Feb 9 11:44:19 2026 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=1612359364; cv=none; d=zohomail.com; s=zohoarc; b=MtotMAWMykDNV5InHBZfMoyKKPyqdERqLSSVYTugI/hqilsPdXlH801ZEgj/NptJaxYX8FZuIZPQ8WQu2efQb7Qkt6FuusoaXbf8mNiR7mhswzHW95hnuj0jAOdjRS/5bXZ9e5CMgWlqMB2R2yX2QFpJ4aovq6mNZujo9iNOUbM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612359364; 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=amtt66U17rvp0b1li/9fv1BI9MCiGPvrUDLcLL+d6sk=; b=JuQ9DBEuowun/0NJrbyTpnX3RlTMq8FfeC4nq8OElF+z2mRcJI9DoPsu+FZcHcdiKomDoiDg7/qLIguevVVv26C+xlfYsNtRqrvf+n35F8VTi5YcgA/wvgCHKhHWGpPAFq+K8OGEg/vRKeGVibQGMTviR2Plu0KhDU5Zgx3A/Gs= 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 1612359364315789.9443821818878; Wed, 3 Feb 2021 05:36:04 -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-559-vXPAietCNEa7oKa39HtvUQ-1; Wed, 03 Feb 2021 08:35:10 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3A468107ACF7; Wed, 3 Feb 2021 13:35:04 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 142D45D723; Wed, 3 Feb 2021 13:35:04 +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 CC43F18095CE; Wed, 3 Feb 2021 13:35:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 113DYccf014101 for ; Wed, 3 Feb 2021 08:34:38 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6175B2CFCE; Wed, 3 Feb 2021 13:34:38 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id B2C205C6B8 for ; Wed, 3 Feb 2021 13:34:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612359363; 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=amtt66U17rvp0b1li/9fv1BI9MCiGPvrUDLcLL+d6sk=; b=FA+M+ETE6kzoeCOl9xLCFBgjwaj/k2dM2HTfJ9JKFGd8K4g9NY6YoFeIjXYId8fCARCrOi Ap6kKwXXyRzKeRt4XQlCKnYpZ9Xj8Hv8U0yX46DUYYGhLtUUeovd9Zs68Xk3/oCjOHzJa5 TIJmE3Vdk3/P+MWLYdE4RwnunHRNFeU= X-MC-Unique: vXPAietCNEa7oKa39HtvUQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 6/6] viralloc: Remove VIR_ALLOC_VAR Date: Wed, 3 Feb 2021 14:34:26 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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.15 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" The use case VIR_ALLOC_VAR deals with is very unlikely. We had just 2 legitimate uses, which were reimplemented locally using g_malloc0 and sizeof instead as they used a static number of members of the trailing array. Remove VIR_ALLOC_VAR since in most cases the direct implementation is shorter and clearer and there are no users of it currently. Signed-off-by: Peter Krempa --- src/libvirt_private.syms | 1 - src/util/viralloc.c | 33 --------------------------------- src/util/viralloc.h | 35 ----------------------------------- 3 files changed, 69 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 30589c08ac..0636b0d8c9 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1724,7 +1724,6 @@ vir_g_strdup_vprintf; # util/viralloc.h -virAllocVar; virDeleteElementsN; virExpandN; virInsertElementsN; diff --git a/src/util/viralloc.c b/src/util/viralloc.c index e4dc13b776..1317537c8a 100644 --- a/src/util/viralloc.c +++ b/src/util/viralloc.c @@ -260,36 +260,3 @@ virDeleteElementsN(void *ptrptr, size_t size, size_t a= t, virShrinkN(ptrptr, size, countptr, toremove); return 0; } - -/** - * virAllocVar: - * @ptrptr: pointer to hold address of allocated memory - * @struct_size: size of initial struct - * @element_size: size of array elements - * @count: number of array elements to allocate - * - * Allocate struct_size bytes plus an array of 'count' elements, each - * of size element_size. This sort of allocation is useful for - * receiving the data of certain ioctls and other APIs which return a - * struct in which the last element is an array of undefined length. - * The caller of this type of API is expected to know the length of - * the array that will be returned and allocate a suitable buffer to - * contain the returned data. C99 refers to these variable length - * objects as structs containing flexible array members. - * - * Returns -1 on failure, 0 on success - */ -int virAllocVar(void *ptrptr, - size_t struct_size, - size_t element_size, - size_t count) -{ - size_t alloc_size =3D 0; - - if (VIR_ALLOC_VAR_OVERSIZED(struct_size, count, element_size)) - abort(); - - alloc_size =3D struct_size + (element_size * count); - *(void **)ptrptr =3D g_malloc0(alloc_size); - return 0; -} diff --git a/src/util/viralloc.h b/src/util/viralloc.h index 29e3224818..e3027622c4 100644 --- a/src/util/viralloc.h +++ b/src/util/viralloc.h @@ -49,8 +49,6 @@ int virInsertElementsN(void *ptrptr, size_t size, size_t = at, size_t *countptr, int virDeleteElementsN(void *ptrptr, size_t size, size_t at, size_t *count= ptr, size_t toremove, bool inPlace) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4); -int virAllocVar(void *ptrptr, size_t struct_size, size_t element_size, siz= e_t count) - G_GNUC_WARN_UNUSED_RESULT ATTRIBUTE_NONNULL(1); /** * VIR_REALLOC_N: @@ -292,39 +290,6 @@ int virAllocVar(void *ptrptr, size_t struct_size, size= _t element_size, size_t co #define VIR_DELETE_ELEMENT_INPLACE(ptr, at, count) \ virDeleteElementsN(&(ptr), sizeof(*(ptr)), at, &(count), 1, true) -/** - * VIR_ALLOC_VAR_OVERSIZED: - * @M: size of base structure - * @N: number of array elements in trailing array - * @S: size of trailing array elements - * - * Check to make sure that the requested allocation will not cause - * arithmetic overflow in the allocation size. - */ -#define VIR_ALLOC_VAR_OVERSIZED(M, N, S) ((((size_t)-1) - (M)) / (S) < (N)) - -/** - * VIR_ALLOC_VAR: - * @ptr: pointer to hold address of allocated memory - * @type: element type of trailing array - * @count: number of array elements to allocate - * - * Allocate sizeof(*ptr) bytes plus an array of 'count' elements, each - * sizeof('type'). This sort of allocation is useful for receiving - * the data of certain ioctls and other APIs which return a struct in - * which the last element is an array of undefined length. The caller - * of this type of API is expected to know the length of the array - * that will be returned and allocate a suitable buffer to contain the - * returned data. C99 refers to these variable length objects as - * structs containing flexible array members. - * - * This macro is safe to use on arguments with side effects. - * - * Returns 0 on success, aborts on OOM - */ -#define VIR_ALLOC_VAR(ptr, type, count) \ - virAllocVar(&(ptr), sizeof(*(ptr)), sizeof(type), (count)) - /** * VIR_FREE: * @ptr: pointer holding address to be freed --=20 2.29.2