From nobody Tue Feb 10 06:08:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1644335671838107.24111613299203; Tue, 8 Feb 2022 07:54:31 -0800 (PST) Received: from localhost ([::1]:50624 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHSp4-0001lQ-Dx for importer@patchew.org; Tue, 08 Feb 2022 10:54:30 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58578) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHRjy-00048u-N4 for qemu-devel@nongnu.org; Tue, 08 Feb 2022 09:45:10 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:44590) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHRjv-0001ht-EK for qemu-devel@nongnu.org; Tue, 08 Feb 2022 09:45:09 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-504-khO2MFcTNXuBxLaMHnHFWQ-1; Tue, 08 Feb 2022 09:45:02 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 86F7794DD4; Tue, 8 Feb 2022 14:45:01 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id EEFDB7D3CE; Tue, 8 Feb 2022 14:45:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644331505; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MBLSF4wMVv/UfkJb2xcYNzkciWKslCxtAdXAzNNthZ4=; b=a0U/+b/JKXLcoqFGM6CemBFblRRGYL36w6VLwNrqMtrp4YkhVjf87dnc99fBUTLzeb3Ynk HqtjEofTqCH8oIbLqRREodJX0HiR2NbT+xW+7h/sAc4ndngzR5nZw7/4mYz6AtPnk01dHr dAPr2SGpheR8kDLrv0ZI/e/oorLMec4= X-MC-Unique: khO2MFcTNXuBxLaMHnHFWQ-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [RFC PATCH 2/3] net: initialize global variables early Date: Tue, 8 Feb 2022 09:44:57 -0500 Message-Id: <20220208144458.1079634-3-pbonzini@redhat.com> In-Reply-To: <20220208144458.1079634-1-pbonzini@redhat.com> References: <20220208144458.1079634-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: damien.hedde@greensocs.com, berrange@redhat.com, mark.burton@greensocs.com, armbru@redhat.com, f4bug@amsat.org, mirela.grujic@greensocs.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1644335672383100005 Content-Type: text/plain; charset="utf-8" Initialize global variables separately from net_init_clients, so that calling net_cleanup does not crash miserably. Signed-off-by: Paolo Bonzini Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/net/xen_nic.c | 20 ++++++++++---------- include/net/net.h | 1 + net/net.c | 5 ++++- softmmu/runstate.c | 1 + 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/hw/net/xen_nic.c b/hw/net/xen_nic.c index 5c815b4f0c..cd8f1edb29 100644 --- a/hw/net/xen_nic.c +++ b/hw/net/xen_nic.c @@ -275,7 +275,7 @@ static NetClientInfo net_xen_info =3D { .receive =3D net_rx_packet, }; =20 -static int net_init(struct XenLegacyDevice *xendev) +static int xen_net_init(struct XenLegacyDevice *xendev) { struct XenNetDev *netdev =3D container_of(xendev, struct XenNetDev, xe= ndev); =20 @@ -307,7 +307,7 @@ static int net_init(struct XenLegacyDevice *xendev) return 0; } =20 -static int net_connect(struct XenLegacyDevice *xendev) +static int xen_net_connect(struct XenLegacyDevice *xendev) { struct XenNetDev *netdev =3D container_of(xendev, struct XenNetDev, xe= ndev); int rx_copy; @@ -362,7 +362,7 @@ static int net_connect(struct XenLegacyDevice *xendev) return 0; } =20 -static void net_disconnect(struct XenLegacyDevice *xendev) +static void xen_net_disconnect(struct XenLegacyDevice *xendev) { struct XenNetDev *netdev =3D container_of(xendev, struct XenNetDev, xe= ndev); =20 @@ -378,14 +378,14 @@ static void net_disconnect(struct XenLegacyDevice *xe= ndev) } } =20 -static void net_event(struct XenLegacyDevice *xendev) +static void xen_net_event(struct XenLegacyDevice *xendev) { struct XenNetDev *netdev =3D container_of(xendev, struct XenNetDev, xe= ndev); net_tx_packets(netdev); qemu_flush_queued_packets(qemu_get_queue(netdev->nic)); } =20 -static int net_free(struct XenLegacyDevice *xendev) +static int xen_net_free(struct XenLegacyDevice *xendev) { struct XenNetDev *netdev =3D container_of(xendev, struct XenNetDev, xe= ndev); =20 @@ -403,9 +403,9 @@ static int net_free(struct XenLegacyDevice *xendev) struct XenDevOps xen_netdev_ops =3D { .size =3D sizeof(struct XenNetDev), .flags =3D DEVOPS_FLAG_NEED_GNTDEV, - .init =3D net_init, - .initialise =3D net_connect, - .event =3D net_event, - .disconnect =3D net_disconnect, - .free =3D net_free, + .init =3D xen_net_init, + .initialise =3D xen_net_connect, + .event =3D xen_net_event, + .disconnect =3D xen_net_disconnect, + .free =3D xen_net_free, }; diff --git a/include/net/net.h b/include/net/net.h index 523136c7ac..463a2c6de5 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -216,6 +216,7 @@ extern const char *host_net_devices[]; /* from net.c */ int net_client_parse(QemuOptsList *opts_list, const char *str); void show_netdevs(void); +void net_init(void); int net_init_clients(Error **errp); void net_check_clients(void); void net_cleanup(void); diff --git a/net/net.c b/net/net.c index f0d14dbfc1..82406a1851 100644 --- a/net/net.c +++ b/net/net.c @@ -1551,13 +1551,16 @@ out: return ret; } =20 -int net_init_clients(Error **errp) +void net_init(void) { net_change_state_entry =3D qemu_add_vm_change_state_handler(net_vm_change_state_handler, NULL= ); =20 QTAILQ_INIT(&net_clients); +} =20 +int net_init_clients(Error **errp) +{ if (qemu_opts_foreach(qemu_find_opts("netdev"), net_init_netdev, NULL, errp)) { return -1; diff --git a/softmmu/runstate.c b/softmmu/runstate.c index 10d9b7365a..0ba7828155 100644 --- a/softmmu/runstate.c +++ b/softmmu/runstate.c @@ -776,6 +776,7 @@ void qemu_init_subsystems(void) =20 bdrv_init_with_whitelist(); socket_init(); + net_init(); } =20 =20 --=20 2.31.1