From nobody Sat Nov 23 19:41:23 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1731691626; cv=none; d=zohomail.com; s=zohoarc; b=l/7UaRbE0BH78hU7jICAY5C1otapNpCUxgTl+DRLe2tl8rof75OAwzqD09sXYq2bvEtMw8/Hdu7+qRiIUW3fksLJHayvIIU71Cl6/W/vUgguB5g4mXbAYZBDd6f214tlevkEps5AffRpeNRLN958mlK6vSHhTlwXwtf/4ud1dVc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731691626; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=iM/IEvnr121ZAVLNB7YYGElME2ngtP8fjYEvWEWPm9k=; b=cit/AyW12DSDT1HautK1CJbJUui2qWW+XYxIIgZnAvbVG3wnGwtqYeTzFKVniWSdfb//YR6j9rzN6m/XAnjWdM9d6Fv/9zjREnfO6X4iuhZJyf0zNintwpN4PJtam5Eu4TdmVc4kDSAKRlu6MxLWPrnvP5VBWRNLd1yzoPZV44w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1731691626179246.38747626199086; Fri, 15 Nov 2024 09:27:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tC04c-000423-7X; Fri, 15 Nov 2024 12:25:34 -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 1tC04a-00040z-7h for qemu-devel@nongnu.org; Fri, 15 Nov 2024 12:25:32 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tC04Y-0001Vi-HY for qemu-devel@nongnu.org; Fri, 15 Nov 2024 12:25:32 -0500 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-637-G5myefujMZiqFFa5KeMbWA-1; Fri, 15 Nov 2024 12:25:28 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D07CB1977319 for ; Fri, 15 Nov 2024 17:25:27 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.102]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E9EC83003B74; Fri, 15 Nov 2024 17:25:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731691529; 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=iM/IEvnr121ZAVLNB7YYGElME2ngtP8fjYEvWEWPm9k=; b=UNshaZCzNM3qz9s4NEOVVn6RMlTKDSAz6qVRYasEW6cIaB2fWCiTgHW2ZGxLLafP611Ree iaorQbrGukyvQLZa3Mr6hxCEYlS45Ojn6w95f+tgLhZy0hvY93zMF2j1kerEqFUzvM7zxm y4frgPdex917RM0HQXrF3sCxAU8h9DY= X-MC-Unique: G5myefujMZiqFFa5KeMbWA-1 X-Mimecast-MFC-AGG-ID: G5myefujMZiqFFa5KeMbWA From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Peter Xu , Markus Armbruster , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v3 1/9] hw: eliminate qdev_try_new, isa_try_new & usb_try_new Date: Fri, 15 Nov 2024 17:25:13 +0000 Message-ID: <20241115172521.504102-2-berrange@redhat.com> In-Reply-To: <20241115172521.504102-1-berrange@redhat.com> References: <20241115172521.504102-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.12, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.658, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1731691626697116600 These functions all return NULL rather than asserting, if the requested type is not registered and also cannot be dynamically loaded. In several cases their usage is pointless, since the caller then just reports an error & exits anyway. Easier to just let qdev_new fail with &error_fatal. In other cases, the desired semantics are clearer to understand if the caller directly checks module_object_class_by_name(), before calling the regular qdev_new (or specialized equiv) function. Signed-off-by: Daniel P. Berrang=C3=A9 --- hw/core/qdev.c | 9 --------- hw/i386/pc.c | 22 ++++++++++------------ hw/isa/isa-bus.c | 5 ----- hw/s390x/s390-pci-bus.c | 6 +----- hw/usb/bus.c | 6 ++---- include/hw/isa/isa.h | 1 - include/hw/net/ne2000-isa.h | 16 ++++++---------- include/hw/qdev-core.h | 12 ------------ include/hw/usb.h | 5 ----- 9 files changed, 19 insertions(+), 63 deletions(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 5f13111b77..960a704a96 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -149,15 +149,6 @@ DeviceState *qdev_new(const char *name) return DEVICE(object_new(name)); } =20 -DeviceState *qdev_try_new(const char *name) -{ - ObjectClass *oc =3D module_object_class_by_name(name); - if (!oc) { - return NULL; - } - return DEVICE(object_new_with_class(oc)); -} - static QTAILQ_HEAD(, DeviceListener) device_listeners =3D QTAILQ_HEAD_INITIALIZER(device_listeners); =20 diff --git a/hw/i386/pc.c b/hw/i386/pc.c index f9147fecbd..d668970bee 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -596,9 +596,11 @@ static gboolean pc_init_ne2k_isa(ISABus *bus, NICInfo = *nd, Error **errp) "maximum number of ISA NE2000 devices exceeded"); return false; } - isa_ne2000_init(bus, ne2000_io[nb_ne2k], - ne2000_irq[nb_ne2k], nd); - nb_ne2k++; + if (module_object_class_by_name(TYPE_ISA_NE2000)) { + isa_ne2000_init(bus, ne2000_io[nb_ne2k], + ne2000_irq[nb_ne2k], nd); + nb_ne2k++; + } return true; } =20 @@ -1087,7 +1089,7 @@ static void pc_superio_init(ISABus *isa_bus, bool cre= ate_fdctrl, int i; DriveInfo *fd[MAX_FD]; qemu_irq *a20_line; - ISADevice *i8042, *port92, *vmmouse; + ISADevice *i8042, *port92, *vmmouse =3D NULL; =20 serial_hds_isa_init(isa_bus, 0, MAX_ISA_SERIAL_PORTS); parallel_hds_isa_init(isa_bus, MAX_PARALLEL_PORTS); @@ -1117,9 +1119,9 @@ static void pc_superio_init(ISABus *isa_bus, bool cre= ate_fdctrl, i8042 =3D isa_create_simple(isa_bus, TYPE_I8042); if (!no_vmport) { isa_create_simple(isa_bus, TYPE_VMPORT); - vmmouse =3D isa_try_new("vmmouse"); - } else { - vmmouse =3D NULL; + if (module_object_class_by_name("vmmouse")) { + vmmouse =3D isa_new("vmmouse"); + } } if (vmmouse) { object_property_set_link(OBJECT(vmmouse), TYPE_I8042, OBJECT(i8042= ), @@ -1163,11 +1165,7 @@ void pc_basic_device_init(struct PCMachineState *pcm= s, if (pcms->hpet_enabled) { qemu_irq rtc_irq; =20 - hpet =3D qdev_try_new(TYPE_HPET); - if (!hpet) { - error_report("couldn't create HPET device"); - exit(1); - } + hpet =3D qdev_new(TYPE_HPET); /* * For pc-piix-*, hpet's intcap is always IRQ2. For pc-q35-*, * use IRQ16~23, IRQ8 and IRQ2. If the user has already set diff --git a/hw/isa/isa-bus.c b/hw/isa/isa-bus.c index f1e0f14007..8aaf44a3ef 100644 --- a/hw/isa/isa-bus.c +++ b/hw/isa/isa-bus.c @@ -158,11 +158,6 @@ ISADevice *isa_new(const char *name) return ISA_DEVICE(qdev_new(name)); } =20 -ISADevice *isa_try_new(const char *name) -{ - return ISA_DEVICE(qdev_try_new(name)); -} - ISADevice *isa_create_simple(ISABus *bus, const char *name) { ISADevice *dev; diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c index 40b2567aa7..558f17d3ba 100644 --- a/hw/s390x/s390-pci-bus.c +++ b/hw/s390x/s390-pci-bus.c @@ -922,11 +922,7 @@ static S390PCIBusDevice *s390_pci_device_new(S390pciSt= ate *s, Error *local_err =3D NULL; DeviceState *dev; =20 - dev =3D qdev_try_new(TYPE_S390_PCI_DEVICE); - if (!dev) { - error_setg(errp, "zPCI device could not be created"); - return NULL; - } + dev =3D qdev_new(TYPE_S390_PCI_DEVICE); =20 if (!object_property_set_str(OBJECT(dev), "target", target, &local_err= )) { object_unparent(OBJECT(dev)); diff --git a/hw/usb/bus.c b/hw/usb/bus.c index bfab2807d7..002f7737e4 100644 --- a/hw/usb/bus.c +++ b/hw/usb/bus.c @@ -394,7 +394,6 @@ void usb_claim_port(USBDevice *dev, Error **errp) { USBBus *bus =3D usb_bus_from_device(dev); USBPort *port; - USBDevice *hub; =20 assert(dev->port =3D=3D NULL); =20 @@ -412,9 +411,8 @@ void usb_claim_port(USBDevice *dev, Error **errp) } else { if (bus->nfree =3D=3D 1 && strcmp(object_get_typename(OBJECT(dev))= , "usb-hub") !=3D 0) { /* Create a new hub and chain it on */ - hub =3D usb_try_new("usb-hub"); - if (hub) { - usb_realize_and_unref(hub, bus, NULL); + if (module_object_class_by_name("usb-hub")) { + usb_realize_and_unref(usb_new("usb-hub"), bus, NULL); } } if (bus->nfree =3D=3D 0) { diff --git a/include/hw/isa/isa.h b/include/hw/isa/isa.h index 40d6224a4e..8475120849 100644 --- a/include/hw/isa/isa.h +++ b/include/hw/isa/isa.h @@ -81,7 +81,6 @@ IsaDma *isa_bus_get_dma(ISABus *bus, int nchan); */ qemu_irq isa_bus_get_irq(ISABus *bus, unsigned irqnum); ISADevice *isa_new(const char *name); -ISADevice *isa_try_new(const char *name); bool isa_realize_and_unref(ISADevice *dev, ISABus *bus, Error **errp); ISADevice *isa_create_simple(ISABus *bus, const char *name); =20 diff --git a/include/hw/net/ne2000-isa.h b/include/hw/net/ne2000-isa.h index 73bae10ad1..aeb3e2bfd5 100644 --- a/include/hw/net/ne2000-isa.h +++ b/include/hw/net/ne2000-isa.h @@ -20,17 +20,13 @@ static inline ISADevice *isa_ne2000_init(ISABus *bus, int base, int irq, NICInfo *nd) { - ISADevice *d; + ISADevice *d =3D isa_new(TYPE_ISA_NE2000); + DeviceState *dev =3D DEVICE(d); =20 - d =3D isa_try_new(TYPE_ISA_NE2000); - if (d) { - DeviceState *dev =3D DEVICE(d); - - qdev_prop_set_uint32(dev, "iobase", base); - qdev_prop_set_uint32(dev, "irq", irq); - qdev_set_nic_properties(dev, nd); - isa_realize_and_unref(d, bus, &error_fatal); - } + qdev_prop_set_uint32(dev, "iobase", base); + qdev_prop_set_uint32(dev, "irq", irq); + qdev_set_nic_properties(dev, nd); + isa_realize_and_unref(d, bus, &error_fatal); return d; } =20 diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 5be9844412..020417d027 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -443,18 +443,6 @@ compat_props_add(GPtrArray *arr, */ DeviceState *qdev_new(const char *name); =20 -/** - * qdev_try_new: Try to create a device on the heap - * @name: device type to create - * - * This is like qdev_new(), except it returns %NULL when type @name - * does not exist, rather than asserting. - * - * Return: a derived DeviceState object with a reference count of 1 or - * NULL if type @name does not exist. - */ -DeviceState *qdev_try_new(const char *name); - /** * qdev_is_realized() - check if device is realized * @dev: The device to check. diff --git a/include/hw/usb.h b/include/hw/usb.h index d46d96779a..bb778cb844 100644 --- a/include/hw/usb.h +++ b/include/hw/usb.h @@ -584,11 +584,6 @@ static inline USBDevice *usb_new(const char *name) return USB_DEVICE(qdev_new(name)); } =20 -static inline USBDevice *usb_try_new(const char *name) -{ - return USB_DEVICE(qdev_try_new(name)); -} - static inline bool usb_realize_and_unref(USBDevice *dev, USBBus *bus, Erro= r **errp) { return qdev_realize_and_unref(&dev->qdev, &bus->qbus, errp); --=20 2.46.0