From patchwork Tue Jan 3 18:16:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 638759 Delivered-To: patch@linaro.org Received: by 2002:a17:522:f3c4:b0:4b4:3859:abed with SMTP id in4csp1394457pvb; Tue, 3 Jan 2023 10:28:19 -0800 (PST) X-Google-Smtp-Source: AMrXdXua36NyX14ekd93KWfdo6XTk1FF+w4GNaVQ1L/9hLNohUqxQRVr2DO9KrusOgpRbrq9Pw5v X-Received: by 2002:a0c:e506:0:b0:531:968c:c234 with SMTP id l6-20020a0ce506000000b00531968cc234mr39590070qvm.7.1672770499150; Tue, 03 Jan 2023 10:28:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672770499; cv=none; d=google.com; s=arc-20160816; b=jC3hS+vlQ8RDcdlMqrTtxw01kih9rAk4zsudw2EWdhOKKC4FXpUACNHo0lTYMSWV8/ 3VlXGD5H1GeeoVf9LCKVsNX2hY1/ZUpvDkE31687z4D1pO8HXLLt/AaF+I/shKWDfkpI LrdO8XpmEWhpUAuiSoSb0TGAuLTvS4yw2Lm0gwc3fB4yuvVQrCuAfv38qx6P9SMmXn9h JmBogoRoQPddG0LkShTQgdZ0U1R9d/0jjxlLrVMBPUeaNwYlQ9B8rC3/LKnx1udM071P 6MoNKP0+kb8Vadx+KbooNvnJHEIgDie3pq+zYwDhu0nFmBfyZfHO0bATDwp16K9k4FyC BuCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jTR0azPO570PZCFggyVak8jaWAO6whlTR6a7W48WgFQ=; b=dHeFhdgFnW4+ZeHivjlClpjWncOw2TzgB/B9cVg7wxXpbu97v79lqIxw3v6A2gOXm/ K0hSIba7FrJ3zJ2FZSw1n7y1DoEObF5cCcwNXKtIbyt/wM+SEq6sGJXcbmzq9tP7FIVj n8K3T/Ax2KbBe4/nkAhBe5nNryjaIRi6mP/dpZLYgvtZaa1H3o7bWBUEhKvy7vTWElah oFjRfSYvoECGooJ3O9hO4Idke+qv2MKY+zCoALW4ImwW5JN5uuwmv5fChrwRPYPR2iN6 jiB33olPGHWXxoBmy8YhdP4QdM4Mi6W0Asw1Ns3DRO/L8vFuRrKgrVspALtNhXIQIbeg 6S/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="L1/y+7Ag"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d191-20020a3768c8000000b006cf592faf2bsi16277631qkc.345.2023.01.03.10.28.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Jan 2023 10:28:19 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="L1/y+7Ag"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pClrb-00009Q-EU; Tue, 03 Jan 2023 13:18:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pClqM-0008Fg-9z for qemu-devel@nongnu.org; Tue, 03 Jan 2023 13:17:20 -0500 Received: from mail-yw1-x112d.google.com ([2607:f8b0:4864:20::112d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pClqK-00056v-PM for qemu-devel@nongnu.org; Tue, 03 Jan 2023 13:16:58 -0500 Received: by mail-yw1-x112d.google.com with SMTP id 00721157ae682-3e45d25de97so447213447b3.6 for ; Tue, 03 Jan 2023 10:16:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jTR0azPO570PZCFggyVak8jaWAO6whlTR6a7W48WgFQ=; b=L1/y+7Agns7IVeuJcr/dic2/cjMrxjhPjuHGCB0Yh/ylNwfmRwqDn1avwfvJOWuphy wXZIw4SzPf24VuLkUrY/BWXqafSAc6bSZWmNXqzFIqQ6qnYpyMRmnrH+tuUs+7HJg4iO dfoashWEc+HgqAt3FARxy01lqz+m+459obA28U6RJGXuBjUVIFVux9cF2Ue9R3Uyrzjw EnLwflSnak8JGP3wUMdxfTslR0Jn9y3Bcy0Dym1AHspVpklGz5rtvywRphnlkLycwOX9 Mh2fHCEniyaKueF9fAep7SlCOuWo+SsJmiu3db/h/IVXyE1OCdEYqKnL8nrSwBCSGdAc sm7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jTR0azPO570PZCFggyVak8jaWAO6whlTR6a7W48WgFQ=; b=igqqTg7jWaqLzz3a3iLcjo1fwqYW2znZeRNip1GcNFBOouIGhFTyWM8ZKeIDT5gJdT qGO7WoSw5rQx5OlD+XRzAQfxISCuZ+3YiQlNbUUErj4XoB8mVA+WiHrQKTHRIwYaQMi/ 8/oWViDTNcmgIkfrOsNQXoxJcpAgoa7XiBC+OglkTwn9WplkGaYA97VghG6fmhMN8ilX S+ms2Jb1K5eZmO6tELctqawFkIfS2fPzmarG+R4ZUxPiE+jiij381/eg3imX3F7WIMAk 8nJHIkUvwCPEwDJqpoUDmtMutAdPnValwLvWmtoPFdi8X9wnfqUVAAxwvsujsUzDM/61 Oyvw== X-Gm-Message-State: AFqh2kpHPw1ooSFcl3DRCz/UEWM+98+Bx8sbr74tgWR7rcBk8tXILlCz EM4NgVMmDStvZ44muw2252x1Vh1S11oR+R1d8ac= X-Received: by 2002:a05:690c:e1a:b0:46a:f5c0:7ba2 with SMTP id cp26-20020a05690c0e1a00b0046af5c07ba2mr36968769ywb.23.1672769814850; Tue, 03 Jan 2023 10:16:54 -0800 (PST) Received: from stoup.. ([2607:fb90:8060:51a2:184b:6e49:c396:be2]) by smtp.gmail.com with ESMTPSA id v2-20020a05620a440200b006fed2788751sm23042354qkp.76.2023.01.03.10.16.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 10:16:54 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, berrange@redhat.com, eduardo@habkost.net, armbru@redhat.com, ajones@ventanamicro.com, alex.bennee@linaro.org Subject: [RFC PATCH 01/40] qdev: Don't always force the global property array non-null Date: Tue, 3 Jan 2023 10:16:07 -0800 Message-Id: <20230103181646.55711-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230103181646.55711-1-richard.henderson@linaro.org> References: <20230103181646.55711-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::112d; envelope-from=richard.henderson@linaro.org; helo=mail-yw1-x112d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Only qdev_prop_register_global requires a non-null array. The other instances can simply exit early. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- hw/core/qdev-properties.c | 43 ++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 357b8761b5..f7775d0ea4 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -739,29 +739,31 @@ void qdev_prop_set_enum(DeviceState *dev, const char *name, int value) &error_abort); } -static GPtrArray *global_props(void) -{ - static GPtrArray *gp; - - if (!gp) { - gp = g_ptr_array_new(); - } - - return gp; -} +static GPtrArray *global_properties; void qdev_prop_register_global(GlobalProperty *prop) { - g_ptr_array_add(global_props(), prop); + GPtrArray *props = global_properties; + + if (!props) { + props = g_ptr_array_new(); + global_properties = props; + } + + g_ptr_array_add(props, prop); } const GlobalProperty *qdev_find_global_prop(Object *obj, const char *name) { - GPtrArray *props = global_props(); + GPtrArray *props = global_properties; const GlobalProperty *p; int i; + if (!props) { + return NULL; + } + for (i = 0; i < props->len; i++) { p = g_ptr_array_index(props, i); if (object_dynamic_cast(obj, p->driver) @@ -774,14 +776,19 @@ const GlobalProperty *qdev_find_global_prop(Object *obj, int qdev_prop_check_globals(void) { + GPtrArray *props = global_properties; int i, ret = 0; - for (i = 0; i < global_props()->len; i++) { + if (!props) { + return 0; + } + + for (i = 0; i < props->len; i++) { GlobalProperty *prop; ObjectClass *oc; DeviceClass *dc; - prop = g_ptr_array_index(global_props(), i); + prop = g_ptr_array_index(props, i); if (prop->used) { continue; } @@ -806,8 +813,12 @@ int qdev_prop_check_globals(void) void qdev_prop_set_globals(DeviceState *dev) { - object_apply_global_props(OBJECT(dev), global_props(), - dev->hotplugged ? NULL : &error_fatal); + GPtrArray *props = global_properties; + + if (props) { + object_apply_global_props(OBJECT(dev), props, + dev->hotplugged ? NULL : &error_fatal); + } } /* --- 64bit unsigned int 'size' type --- */