qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/6] Improve consistency of bus init function names
@ 2021-09-23 12:11 Peter Maydell
  2021-09-23 12:11 ` [PATCH 1/6] scsi: Replace scsi_bus_new() with scsi_bus_init(), scsi_bus_init_named() Peter Maydell
                   ` (8 more replies)
  0 siblings, 9 replies; 13+ messages in thread
From: Peter Maydell @ 2021-09-23 12:11 UTC (permalink / raw)
  To: qemu-devel
  Cc: Fam Zheng, Alberto Garcia, Eduardo Habkost, Michael S . Tsirkin,
	Daniel P. Berrange, Markus Armbruster, Paolo Bonzini, John Snow

Currently we have a bit of a mishmash of different function
names for bus creation. There are two basic patterns: you
can have a function that allocates and returns a new bus
object; or you can have a function that takes a pointer to
a bus object and initializes it in-place. We have to some
extent a convention for those: the allocate-and-return
function is 'foo_new()', and the 'init in-place' function
is 'foo_init()'. However many of our bus creation functions
don't follow that; some use 'foo_new' vs 'foo_new_inplace';
some use 'foo_new' for the in-place init version; and
the bottom level qbus functions are 'qbus_create' vs
'qbus_create_inplace'. This series tries to bring at least
scsi, ipack, pci, ide, and qbus into line with the
_new-vs-_init naming convention.

The other issue with bus creation functions is that some
of them take a 'name' argument which can be NULL, and some
do not. Generally "pass in a specific name" should be the
rare case, but our API design here is easy to misuse, and
so a lot of callsites (especially for i2c, sd, ssi) pass
in names when they should not. Untangling that mess is
going to be tricky (see other thread for more), but as
a first step, this series proposes a split between
foo_bus_new() and foo_bus_new_named() where the latter
takes a name parameter and the former does not. I do
this only for scsi (and implicitly ide, whose ide_bus_new
function already doesn't take a name argument) for the
moment, as the other bus types have more of a mess of
"pass name when they should not" callsites, so I didn't
want to put in too much work before finding out if we
had agreement on this as a naming convention.

There are definitely more buses that can be cleaned up
to follow the init vs new convention, but this series is
already touching 70 files and trying to do every bus in
one series seems like a recipe for merge conflicts.
So this seemed like enough to be going on with...

thanks
-- PMM

Peter Maydell (6):
  scsi: Replace scsi_bus_new() with scsi_bus_init(),
    scsi_bus_init_named()
  ipack: Rename ipack_bus_new_inplace() to ipack_bus_init()
  pci: Rename pci_root_bus_new_inplace() to pci_root_bus_init()
  qbus: Rename qbus_create_inplace() to qbus_init()
  qbus: Rename qbus_create() to qbus_new()
  ide: Rename ide_bus_new() to ide_bus_init()

 include/hw/ide/internal.h     |  4 ++--
 include/hw/ipack/ipack.h      |  8 ++++----
 include/hw/pci/pci.h          | 10 +++++-----
 include/hw/qdev-core.h        |  6 +++---
 include/hw/scsi/scsi.h        | 30 ++++++++++++++++++++++++++++--
 hw/audio/intel-hda.c          |  2 +-
 hw/block/fdc.c                |  2 +-
 hw/block/swim.c               |  3 +--
 hw/char/virtio-serial-bus.c   |  4 ++--
 hw/core/bus.c                 | 13 +++++++------
 hw/core/sysbus.c              | 10 ++++++----
 hw/gpio/bcm2835_gpio.c        |  3 +--
 hw/hyperv/vmbus.c             |  2 +-
 hw/i2c/core.c                 |  2 +-
 hw/ide/ahci.c                 |  2 +-
 hw/ide/cmd646.c               |  2 +-
 hw/ide/isa.c                  |  2 +-
 hw/ide/macio.c                |  2 +-
 hw/ide/microdrive.c           |  2 +-
 hw/ide/mmio.c                 |  2 +-
 hw/ide/piix.c                 |  2 +-
 hw/ide/qdev.c                 |  4 ++--
 hw/ide/sii3112.c              |  2 +-
 hw/ide/via.c                  |  2 +-
 hw/ipack/ipack.c              | 10 +++++-----
 hw/ipack/tpci200.c            |  4 ++--
 hw/isa/isa-bus.c              |  2 +-
 hw/misc/auxbus.c              |  2 +-
 hw/misc/mac_via.c             |  4 ++--
 hw/misc/macio/cuda.c          |  4 ++--
 hw/misc/macio/macio.c         |  4 ++--
 hw/misc/macio/pmu.c           |  4 ++--
 hw/nubus/mac-nubus-bridge.c   |  2 +-
 hw/nvme/ctrl.c                |  4 ++--
 hw/nvme/subsys.c              |  3 +--
 hw/pci-host/raven.c           |  4 ++--
 hw/pci-host/versatile.c       |  6 +++---
 hw/pci/pci.c                  | 30 +++++++++++++++---------------
 hw/pci/pci_bridge.c           |  4 ++--
 hw/ppc/spapr_vio.c            |  2 +-
 hw/s390x/ap-bridge.c          |  2 +-
 hw/s390x/css-bridge.c         |  2 +-
 hw/s390x/event-facility.c     |  4 ++--
 hw/s390x/s390-pci-bus.c       |  2 +-
 hw/s390x/virtio-ccw.c         |  3 +--
 hw/scsi/esp-pci.c             |  2 +-
 hw/scsi/esp.c                 |  2 +-
 hw/scsi/lsi53c895a.c          |  2 +-
 hw/scsi/megasas.c             |  3 +--
 hw/scsi/mptsas.c              |  2 +-
 hw/scsi/scsi-bus.c            |  6 +++---
 hw/scsi/spapr_vscsi.c         |  3 +--
 hw/scsi/virtio-scsi.c         |  4 ++--
 hw/scsi/vmw_pvscsi.c          |  3 +--
 hw/sd/allwinner-sdhost.c      |  4 ++--
 hw/sd/bcm2835_sdhost.c        |  4 ++--
 hw/sd/pl181.c                 |  3 +--
 hw/sd/pxa2xx_mmci.c           |  4 ++--
 hw/sd/sdhci.c                 |  3 +--
 hw/sd/ssi-sd.c                |  3 +--
 hw/ssi/ssi.c                  |  2 +-
 hw/usb/bus.c                  |  2 +-
 hw/usb/dev-smartcard-reader.c |  3 +--
 hw/usb/dev-storage-bot.c      |  3 +--
 hw/usb/dev-storage-classic.c  |  4 ++--
 hw/usb/dev-uas.c              |  3 +--
 hw/virtio/virtio-mmio.c       |  3 +--
 hw/virtio/virtio-pci.c        |  3 +--
 hw/xen/xen-bus.c              |  2 +-
 hw/xen/xen-legacy-backend.c   |  2 +-
 70 files changed, 156 insertions(+), 142 deletions(-)

-- 
2.20.1



^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 1/6] scsi: Replace scsi_bus_new() with scsi_bus_init(), scsi_bus_init_named()
  2021-09-23 12:11 [PATCH 0/6] Improve consistency of bus init function names Peter Maydell
@ 2021-09-23 12:11 ` Peter Maydell
  2021-09-28 15:12   ` Paolo Bonzini
  2021-09-23 12:11 ` [PATCH 2/6] ipack: Rename ipack_bus_new_inplace() to ipack_bus_init() Peter Maydell
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 13+ messages in thread
From: Peter Maydell @ 2021-09-23 12:11 UTC (permalink / raw)
  To: qemu-devel
  Cc: Fam Zheng, Alberto Garcia, Eduardo Habkost, Michael S . Tsirkin,
	Daniel P. Berrange, Markus Armbruster, Paolo Bonzini, John Snow

The function scsi_bus_new() creates a new SCSI bus; callers can
either pass in a name argument to specify the name of the new bus, or
they can pass in NULL to allow the bus to be given an automatically
generated unique name.  Almost all callers want to use the
autogenerated name; the only exception is the virtio-scsi device.

Taking a name argument that should almost always be NULL is an
easy-to-misuse API design -- it encourages callers to think perhaps
they should pass in some standard name like "scsi" or "scsi-bus".  We
don't do this anywhere for SCSI, but we do (incorrectly) do it for
other bus types such as i2c.

The function name also implies that it will return a newly allocated
object, when it in fact does in-place allocation.  We more commonly
name such functions foo_init(), with foo_new() being the
allocate-and-return variant.

Replace all the scsi_bus_new() callsites with either:
 * scsi_bus_init() for the usual case where the caller wants
   an autogenerated bus name
 * scsi_bus_init_named() for the rare case where the caller
   needs to specify the bus name

and document that for the _named() version it's then the caller's
responsibility to think about uniqueness of bus names.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 include/hw/scsi/scsi.h       | 30 ++++++++++++++++++++++++++++--
 hw/scsi/esp-pci.c            |  2 +-
 hw/scsi/esp.c                |  2 +-
 hw/scsi/lsi53c895a.c         |  2 +-
 hw/scsi/megasas.c            |  3 +--
 hw/scsi/mptsas.c             |  2 +-
 hw/scsi/scsi-bus.c           |  4 ++--
 hw/scsi/spapr_vscsi.c        |  3 +--
 hw/scsi/virtio-scsi.c        |  4 ++--
 hw/scsi/vmw_pvscsi.c         |  3 +--
 hw/usb/dev-storage-bot.c     |  3 +--
 hw/usb/dev-storage-classic.c |  4 ++--
 hw/usb/dev-uas.c             |  3 +--
 13 files changed, 43 insertions(+), 22 deletions(-)

diff --git a/include/hw/scsi/scsi.h b/include/hw/scsi/scsi.h
index 0b726bc78c6..a567a5ed86b 100644
--- a/include/hw/scsi/scsi.h
+++ b/include/hw/scsi/scsi.h
@@ -146,8 +146,34 @@ struct SCSIBus {
     const SCSIBusInfo *info;
 };
 
-void scsi_bus_new(SCSIBus *bus, size_t bus_size, DeviceState *host,
-                  const SCSIBusInfo *info, const char *bus_name);
+/**
+ * scsi_bus_init_named: Initialize a SCSI bus with the specified name
+ * @bus: SCSIBus object to initialize
+ * @bus_size: size of @bus object
+ * @host: Device which owns the bus (generally the SCSI controller)
+ * @info: structure defining callbacks etc for the controller
+ * @bus_name: Name to use for this bus
+ *
+ * This in-place initializes @bus as a new SCSI bus with a name
+ * provided by the caller. It is the caller's responsibility to make
+ * sure that name does not clash with the name of any other bus in the
+ * system. Unless you need the new bus to have a specific name, you
+ * should use scsi_bus_new() instead.
+ */
+void scsi_bus_init_named(SCSIBus *bus, size_t bus_size, DeviceState *host,
+                         const SCSIBusInfo *info, const char *bus_name);
+
+/**
+ * scsi_bus_init: Initialize a SCSI bus
+ *
+ * This in-place-initializes @bus as a new SCSI bus and gives it
+ * an automatically generated unique name.
+ */
+static inline void scsi_bus_init(SCSIBus *bus, size_t bus_size,
+                                 DeviceState *host, const SCSIBusInfo *info)
+{
+    scsi_bus_init_named(bus, bus_size, host, info, NULL);
+}
 
 static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d)
 {
diff --git a/hw/scsi/esp-pci.c b/hw/scsi/esp-pci.c
index 9db10b1a487..dac054aeed4 100644
--- a/hw/scsi/esp-pci.c
+++ b/hw/scsi/esp-pci.c
@@ -388,7 +388,7 @@ static void esp_pci_scsi_realize(PCIDevice *dev, Error **errp)
     pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &pci->io);
     s->irq = pci_allocate_irq(dev);
 
-    scsi_bus_new(&s->bus, sizeof(s->bus), d, &esp_pci_scsi_info, NULL);
+    scsi_bus_init(&s->bus, sizeof(s->bus), d, &esp_pci_scsi_info);
 }
 
 static void esp_pci_scsi_exit(PCIDevice *d)
diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c
index 4ac21147888..8454ed17735 100644
--- a/hw/scsi/esp.c
+++ b/hw/scsi/esp.c
@@ -1348,7 +1348,7 @@ static void sysbus_esp_realize(DeviceState *dev, Error **errp)
 
     qdev_init_gpio_in(dev, sysbus_esp_gpio_demux, 2);
 
-    scsi_bus_new(&s->bus, sizeof(s->bus), dev, &esp_scsi_info, NULL);
+    scsi_bus_init(&s->bus, sizeof(s->bus), dev, &esp_scsi_info);
 }
 
 static void sysbus_esp_hard_reset(DeviceState *dev)
diff --git a/hw/scsi/lsi53c895a.c b/hw/scsi/lsi53c895a.c
index e2c19180a0d..85e907a7854 100644
--- a/hw/scsi/lsi53c895a.c
+++ b/hw/scsi/lsi53c895a.c
@@ -2309,7 +2309,7 @@ static void lsi_scsi_realize(PCIDevice *dev, Error **errp)
     pci_register_bar(dev, 2, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->ram_io);
     QTAILQ_INIT(&s->queue);
 
-    scsi_bus_new(&s->bus, sizeof(s->bus), d, &lsi_scsi_info, NULL);
+    scsi_bus_init(&s->bus, sizeof(s->bus), d, &lsi_scsi_info);
 }
 
 static void lsi_scsi_exit(PCIDevice *dev)
diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c
index 8f2389d2c6a..4ff51221d4c 100644
--- a/hw/scsi/megasas.c
+++ b/hw/scsi/megasas.c
@@ -2416,8 +2416,7 @@ static void megasas_scsi_realize(PCIDevice *dev, Error **errp)
         s->frames[i].state = s;
     }
 
-    scsi_bus_new(&s->bus, sizeof(s->bus), DEVICE(dev),
-                 &megasas_scsi_info, NULL);
+    scsi_bus_init(&s->bus, sizeof(s->bus), DEVICE(dev), &megasas_scsi_info);
 }
 
 static Property megasas_properties_gen1[] = {
diff --git a/hw/scsi/mptsas.c b/hw/scsi/mptsas.c
index db3219e7d20..f6c77655443 100644
--- a/hw/scsi/mptsas.c
+++ b/hw/scsi/mptsas.c
@@ -1315,7 +1315,7 @@ static void mptsas_scsi_realize(PCIDevice *dev, Error **errp)
 
     s->request_bh = qemu_bh_new(mptsas_fetch_requests, s);
 
-    scsi_bus_new(&s->bus, sizeof(s->bus), &dev->qdev, &mptsas_scsi_info, NULL);
+    scsi_bus_init(&s->bus, sizeof(s->bus), &dev->qdev, &mptsas_scsi_info);
 }
 
 static void mptsas_scsi_uninit(PCIDevice *dev)
diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c
index 2a0a98cac91..e28a6ea053a 100644
--- a/hw/scsi/scsi-bus.c
+++ b/hw/scsi/scsi-bus.c
@@ -134,8 +134,8 @@ void scsi_device_unit_attention_reported(SCSIDevice *s)
 }
 
 /* Create a scsi bus, and attach devices to it.  */
-void scsi_bus_new(SCSIBus *bus, size_t bus_size, DeviceState *host,
-                  const SCSIBusInfo *info, const char *bus_name)
+void scsi_bus_init_named(SCSIBus *bus, size_t bus_size, DeviceState *host,
+                         const SCSIBusInfo *info, const char *bus_name)
 {
     qbus_create_inplace(bus, bus_size, TYPE_SCSI_BUS, host, bus_name);
     bus->busnr = next_scsi_bus++;
diff --git a/hw/scsi/spapr_vscsi.c b/hw/scsi/spapr_vscsi.c
index c210262484a..a07a8e1523f 100644
--- a/hw/scsi/spapr_vscsi.c
+++ b/hw/scsi/spapr_vscsi.c
@@ -1216,8 +1216,7 @@ static void spapr_vscsi_realize(SpaprVioDevice *dev, Error **errp)
 
     dev->crq.SendFunc = vscsi_do_crq;
 
-    scsi_bus_new(&s->bus, sizeof(s->bus), DEVICE(dev),
-                 &vscsi_scsi_info, NULL);
+    scsi_bus_init(&s->bus, sizeof(s->bus), DEVICE(dev), &vscsi_scsi_info);
 
     /* ibmvscsi SCSI bus does not allow hotplug. */
     qbus_set_hotplug_handler(BUS(&s->bus), NULL);
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index 6d807302870..51fd09522ac 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -1019,8 +1019,8 @@ static void virtio_scsi_device_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    scsi_bus_new(&s->bus, sizeof(s->bus), dev,
-                 &virtio_scsi_scsi_info, vdev->bus_name);
+    scsi_bus_init_named(&s->bus, sizeof(s->bus), dev,
+                       &virtio_scsi_scsi_info, vdev->bus_name);
     /* override default SCSI bus hotplug-handler, with virtio-scsi's one */
     qbus_set_hotplug_handler(BUS(&s->bus), OBJECT(dev));
 
diff --git a/hw/scsi/vmw_pvscsi.c b/hw/scsi/vmw_pvscsi.c
index 1f30cb020a1..cd76bd67ab7 100644
--- a/hw/scsi/vmw_pvscsi.c
+++ b/hw/scsi/vmw_pvscsi.c
@@ -1180,8 +1180,7 @@ pvscsi_realizefn(PCIDevice *pci_dev, Error **errp)
 
     s->completion_worker = qemu_bh_new(pvscsi_process_completion_queue, s);
 
-    scsi_bus_new(&s->bus, sizeof(s->bus), DEVICE(pci_dev),
-                 &pvscsi_scsi_info, NULL);
+    scsi_bus_init(&s->bus, sizeof(s->bus), DEVICE(pci_dev), &pvscsi_scsi_info);
     /* override default SCSI bus hotplug-handler, with pvscsi's one */
     qbus_set_hotplug_handler(BUS(&s->bus), OBJECT(s));
     pvscsi_reset_state(s);
diff --git a/hw/usb/dev-storage-bot.c b/hw/usb/dev-storage-bot.c
index 68ebaca10c6..b24b3148c28 100644
--- a/hw/usb/dev-storage-bot.c
+++ b/hw/usb/dev-storage-bot.c
@@ -37,8 +37,7 @@ static void usb_msd_bot_realize(USBDevice *dev, Error **errp)
         s->dev.auto_attach = 0;
     }
 
-    scsi_bus_new(&s->bus, sizeof(s->bus), DEVICE(dev),
-                 &usb_msd_scsi_info_bot, NULL);
+    scsi_bus_init(&s->bus, sizeof(s->bus), DEVICE(dev), &usb_msd_scsi_info_bot);
     usb_msd_handle_reset(dev);
 }
 
diff --git a/hw/usb/dev-storage-classic.c b/hw/usb/dev-storage-classic.c
index 3d017a4e679..00f25bade28 100644
--- a/hw/usb/dev-storage-classic.c
+++ b/hw/usb/dev-storage-classic.c
@@ -65,8 +65,8 @@ static void usb_msd_storage_realize(USBDevice *dev, Error **errp)
     usb_desc_create_serial(dev);
     usb_desc_init(dev);
     dev->flags |= (1 << USB_DEV_FLAG_IS_SCSI_STORAGE);
-    scsi_bus_new(&s->bus, sizeof(s->bus), DEVICE(dev),
-                 &usb_msd_scsi_info_storage, NULL);
+    scsi_bus_init(&s->bus, sizeof(s->bus), DEVICE(dev),
+                 &usb_msd_scsi_info_storage);
     scsi_dev = scsi_bus_legacy_add_drive(&s->bus, blk, 0, !!s->removable,
                                          s->conf.bootindex, s->conf.share_rw,
                                          s->conf.rerror, s->conf.werror,
diff --git a/hw/usb/dev-uas.c b/hw/usb/dev-uas.c
index f6309a5ebfd..599d6b52a01 100644
--- a/hw/usb/dev-uas.c
+++ b/hw/usb/dev-uas.c
@@ -938,8 +938,7 @@ static void usb_uas_realize(USBDevice *dev, Error **errp)
     uas->status_bh = qemu_bh_new(usb_uas_send_status_bh, uas);
 
     dev->flags |= (1 << USB_DEV_FLAG_IS_SCSI_STORAGE);
-    scsi_bus_new(&uas->bus, sizeof(uas->bus), DEVICE(dev),
-                 &usb_uas_scsi_info, NULL);
+    scsi_bus_init(&uas->bus, sizeof(uas->bus), DEVICE(dev), &usb_uas_scsi_info);
 }
 
 static const VMStateDescription vmstate_usb_uas = {
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 2/6] ipack: Rename ipack_bus_new_inplace() to ipack_bus_init()
  2021-09-23 12:11 [PATCH 0/6] Improve consistency of bus init function names Peter Maydell
  2021-09-23 12:11 ` [PATCH 1/6] scsi: Replace scsi_bus_new() with scsi_bus_init(), scsi_bus_init_named() Peter Maydell
@ 2021-09-23 12:11 ` Peter Maydell
  2021-09-23 12:11 ` [PATCH 3/6] pci: Rename pci_root_bus_new_inplace() to pci_root_bus_init() Peter Maydell
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Peter Maydell @ 2021-09-23 12:11 UTC (permalink / raw)
  To: qemu-devel
  Cc: Fam Zheng, Alberto Garcia, Eduardo Habkost, Michael S . Tsirkin,
	Daniel P. Berrange, Markus Armbruster, Paolo Bonzini, John Snow

Rename ipack_bus_new_inplace() to ipack_bus_init(), to bring it in to
line with a "_init for in-place init, _new for allocate-and-return"
convention.  Drop the 'name' argument, because the only caller does
not pass in a name.  If a future caller does need to specify the bus
name, we should create an ipack_bus_init_named() function at that
point.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 include/hw/ipack/ipack.h |  8 ++++----
 hw/ipack/ipack.c         | 10 +++++-----
 hw/ipack/tpci200.c       |  4 ++--
 3 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/include/hw/ipack/ipack.h b/include/hw/ipack/ipack.h
index 75014e74ae1..cbcdda509d3 100644
--- a/include/hw/ipack/ipack.h
+++ b/include/hw/ipack/ipack.h
@@ -73,9 +73,9 @@ extern const VMStateDescription vmstate_ipack_device;
     VMSTATE_STRUCT(_field, _state, 1, vmstate_ipack_device, IPackDevice)
 
 IPackDevice *ipack_device_find(IPackBus *bus, int32_t slot);
-void ipack_bus_new_inplace(IPackBus *bus, size_t bus_size,
-                           DeviceState *parent,
-                           const char *name, uint8_t n_slots,
-                           qemu_irq_handler handler);
+void ipack_bus_init(IPackBus *bus, size_t bus_size,
+                    DeviceState *parent,
+                    uint8_t n_slots,
+                    qemu_irq_handler handler);
 
 #endif
diff --git a/hw/ipack/ipack.c b/hw/ipack/ipack.c
index f19ecaeb1cf..d28e7f6449e 100644
--- a/hw/ipack/ipack.c
+++ b/hw/ipack/ipack.c
@@ -30,12 +30,12 @@ IPackDevice *ipack_device_find(IPackBus *bus, int32_t slot)
     return NULL;
 }
 
-void ipack_bus_new_inplace(IPackBus *bus, size_t bus_size,
-                           DeviceState *parent,
-                           const char *name, uint8_t n_slots,
-                           qemu_irq_handler handler)
+void ipack_bus_init(IPackBus *bus, size_t bus_size,
+                    DeviceState *parent,
+                    uint8_t n_slots,
+                    qemu_irq_handler handler)
 {
-    qbus_create_inplace(bus, bus_size, TYPE_IPACK_BUS, parent, name);
+    qbus_create_inplace(bus, bus_size, TYPE_IPACK_BUS, parent, NULL);
     bus->n_slots = n_slots;
     bus->set_irq = handler;
 }
diff --git a/hw/ipack/tpci200.c b/hw/ipack/tpci200.c
index d107e134c4e..1f764fc85ba 100644
--- a/hw/ipack/tpci200.c
+++ b/hw/ipack/tpci200.c
@@ -611,8 +611,8 @@ static void tpci200_realize(PCIDevice *pci_dev, Error **errp)
     pci_register_bar(&s->dev, 4, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->las2);
     pci_register_bar(&s->dev, 5, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->las3);
 
-    ipack_bus_new_inplace(&s->bus, sizeof(s->bus), DEVICE(pci_dev), NULL,
-                          N_MODULES, tpci200_set_irq);
+    ipack_bus_init(&s->bus, sizeof(s->bus), DEVICE(pci_dev),
+                   N_MODULES, tpci200_set_irq);
 }
 
 static const VMStateDescription vmstate_tpci200 = {
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 3/6] pci: Rename pci_root_bus_new_inplace() to pci_root_bus_init()
  2021-09-23 12:11 [PATCH 0/6] Improve consistency of bus init function names Peter Maydell
  2021-09-23 12:11 ` [PATCH 1/6] scsi: Replace scsi_bus_new() with scsi_bus_init(), scsi_bus_init_named() Peter Maydell
  2021-09-23 12:11 ` [PATCH 2/6] ipack: Rename ipack_bus_new_inplace() to ipack_bus_init() Peter Maydell
@ 2021-09-23 12:11 ` Peter Maydell
  2021-09-23 12:11 ` [PATCH 4/6] qbus: Rename qbus_create_inplace() to qbus_init() Peter Maydell
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Peter Maydell @ 2021-09-23 12:11 UTC (permalink / raw)
  To: qemu-devel
  Cc: Fam Zheng, Alberto Garcia, Eduardo Habkost, Michael S . Tsirkin,
	Daniel P. Berrange, Markus Armbruster, Paolo Bonzini, John Snow

Rename the pci_root_bus_new_inplace() function to
pci_root_bus_init(); this brings the bus type in to line with a
"_init for in-place init, _new for allocate-and-return" convention.
To do this we need to rename the implementation-internal function
that was using the pci_root_bus_init() name to
pci_root_bus_internal_init().

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
I have not attempted to tackle a possible _named vs not
split here because a lot of callsites specify a name when
they arguably should not.
---
 include/hw/pci/pci.h    | 10 +++++-----
 hw/pci-host/raven.c     |  4 ++--
 hw/pci-host/versatile.c |  6 +++---
 hw/pci/pci.c            | 26 +++++++++++++-------------
 4 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index d0f4266e372..7fc90132cf1 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -403,11 +403,11 @@ OBJECT_DECLARE_TYPE(PCIBus, PCIBusClass, PCI_BUS)
 
 bool pci_bus_is_express(PCIBus *bus);
 
-void pci_root_bus_new_inplace(PCIBus *bus, size_t bus_size, DeviceState *parent,
-                              const char *name,
-                              MemoryRegion *address_space_mem,
-                              MemoryRegion *address_space_io,
-                              uint8_t devfn_min, const char *typename);
+void pci_root_bus_init(PCIBus *bus, size_t bus_size, DeviceState *parent,
+                       const char *name,
+                       MemoryRegion *address_space_mem,
+                       MemoryRegion *address_space_io,
+                       uint8_t devfn_min, const char *typename);
 PCIBus *pci_root_bus_new(DeviceState *parent, const char *name,
                          MemoryRegion *address_space_mem,
                          MemoryRegion *address_space_io,
diff --git a/hw/pci-host/raven.c b/hw/pci-host/raven.c
index 3be27f0a14d..6e514f75eb8 100644
--- a/hw/pci-host/raven.c
+++ b/hw/pci-host/raven.c
@@ -300,8 +300,8 @@ static void raven_pcihost_initfn(Object *obj)
     memory_region_add_subregion_overlap(address_space_mem, PCI_IO_BASE_ADDR,
                                         &s->pci_io_non_contiguous, 1);
     memory_region_add_subregion(address_space_mem, 0xc0000000, &s->pci_memory);
-    pci_root_bus_new_inplace(&s->pci_bus, sizeof(s->pci_bus), DEVICE(obj), NULL,
-                             &s->pci_memory, &s->pci_io, 0, TYPE_PCI_BUS);
+    pci_root_bus_init(&s->pci_bus, sizeof(s->pci_bus), DEVICE(obj), NULL,
+                      &s->pci_memory, &s->pci_io, 0, TYPE_PCI_BUS);
 
     /* Bus master address space */
     memory_region_init(&s->bm, obj, "bm-raven", 4 * GiB);
diff --git a/hw/pci-host/versatile.c b/hw/pci-host/versatile.c
index 3553277f941..f66384fa02d 100644
--- a/hw/pci-host/versatile.c
+++ b/hw/pci-host/versatile.c
@@ -405,9 +405,9 @@ static void pci_vpb_realize(DeviceState *dev, Error **errp)
     memory_region_init(&s->pci_io_space, OBJECT(s), "pci_io", 4 * GiB);
     memory_region_init(&s->pci_mem_space, OBJECT(s), "pci_mem", 4 * GiB);
 
-    pci_root_bus_new_inplace(&s->pci_bus, sizeof(s->pci_bus), dev, "pci",
-                             &s->pci_mem_space, &s->pci_io_space,
-                             PCI_DEVFN(11, 0), TYPE_PCI_BUS);
+    pci_root_bus_init(&s->pci_bus, sizeof(s->pci_bus), dev, "pci",
+                      &s->pci_mem_space, &s->pci_io_space,
+                      PCI_DEVFN(11, 0), TYPE_PCI_BUS);
     h->bus = &s->pci_bus;
 
     object_initialize(&s->pci_dev, sizeof(s->pci_dev), TYPE_VERSATILE_PCI_HOST);
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 23d2ae2ab23..19881c84f23 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -432,10 +432,10 @@ bool pci_bus_bypass_iommu(PCIBus *bus)
     return host_bridge->bypass_iommu;
 }
 
-static void pci_root_bus_init(PCIBus *bus, DeviceState *parent,
-                              MemoryRegion *address_space_mem,
-                              MemoryRegion *address_space_io,
-                              uint8_t devfn_min)
+static void pci_root_bus_internal_init(PCIBus *bus, DeviceState *parent,
+                                       MemoryRegion *address_space_mem,
+                                       MemoryRegion *address_space_io,
+                                       uint8_t devfn_min)
 {
     assert(PCI_FUNC(devfn_min) == 0);
     bus->devfn_min = devfn_min;
@@ -460,15 +460,15 @@ bool pci_bus_is_express(PCIBus *bus)
     return object_dynamic_cast(OBJECT(bus), TYPE_PCIE_BUS);
 }
 
-void pci_root_bus_new_inplace(PCIBus *bus, size_t bus_size, DeviceState *parent,
-                              const char *name,
-                              MemoryRegion *address_space_mem,
-                              MemoryRegion *address_space_io,
-                              uint8_t devfn_min, const char *typename)
+void pci_root_bus_init(PCIBus *bus, size_t bus_size, DeviceState *parent,
+                       const char *name,
+                       MemoryRegion *address_space_mem,
+                       MemoryRegion *address_space_io,
+                       uint8_t devfn_min, const char *typename)
 {
     qbus_create_inplace(bus, bus_size, typename, parent, name);
-    pci_root_bus_init(bus, parent, address_space_mem, address_space_io,
-                      devfn_min);
+    pci_root_bus_internal_init(bus, parent, address_space_mem,
+                               address_space_io, devfn_min);
 }
 
 PCIBus *pci_root_bus_new(DeviceState *parent, const char *name,
@@ -479,8 +479,8 @@ PCIBus *pci_root_bus_new(DeviceState *parent, const char *name,
     PCIBus *bus;
 
     bus = PCI_BUS(qbus_create(typename, parent, name));
-    pci_root_bus_init(bus, parent, address_space_mem, address_space_io,
-                      devfn_min);
+    pci_root_bus_internal_init(bus, parent, address_space_mem,
+                               address_space_io, devfn_min);
     return bus;
 }
 
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 4/6] qbus: Rename qbus_create_inplace() to qbus_init()
  2021-09-23 12:11 [PATCH 0/6] Improve consistency of bus init function names Peter Maydell
                   ` (2 preceding siblings ...)
  2021-09-23 12:11 ` [PATCH 3/6] pci: Rename pci_root_bus_new_inplace() to pci_root_bus_init() Peter Maydell
@ 2021-09-23 12:11 ` Peter Maydell
  2021-09-23 12:11 ` [PATCH 5/6] qbus: Rename qbus_create() to qbus_new() Peter Maydell
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Peter Maydell @ 2021-09-23 12:11 UTC (permalink / raw)
  To: qemu-devel
  Cc: Fam Zheng, Alberto Garcia, Eduardo Habkost, Michael S . Tsirkin,
	Daniel P. Berrange, Markus Armbruster, Paolo Bonzini, John Snow

Rename qbus_create_inplace() to qbus_init(); this is more in line
with our usual naming convention for functions that in-place
initialize objects.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 include/hw/qdev-core.h        |  4 ++--
 hw/audio/intel-hda.c          |  2 +-
 hw/block/fdc.c                |  2 +-
 hw/block/swim.c               |  3 +--
 hw/char/virtio-serial-bus.c   |  4 ++--
 hw/core/bus.c                 | 11 ++++++-----
 hw/core/sysbus.c              | 10 ++++++----
 hw/gpio/bcm2835_gpio.c        |  3 +--
 hw/ide/qdev.c                 |  2 +-
 hw/ipack/ipack.c              |  2 +-
 hw/misc/mac_via.c             |  4 ++--
 hw/misc/macio/cuda.c          |  4 ++--
 hw/misc/macio/macio.c         |  4 ++--
 hw/misc/macio/pmu.c           |  4 ++--
 hw/nvme/ctrl.c                |  4 ++--
 hw/nvme/subsys.c              |  3 +--
 hw/pci/pci.c                  |  2 +-
 hw/pci/pci_bridge.c           |  4 ++--
 hw/s390x/event-facility.c     |  4 ++--
 hw/s390x/virtio-ccw.c         |  3 +--
 hw/scsi/scsi-bus.c            |  2 +-
 hw/sd/allwinner-sdhost.c      |  4 ++--
 hw/sd/bcm2835_sdhost.c        |  4 ++--
 hw/sd/pl181.c                 |  3 +--
 hw/sd/pxa2xx_mmci.c           |  4 ++--
 hw/sd/sdhci.c                 |  3 +--
 hw/sd/ssi-sd.c                |  3 +--
 hw/usb/bus.c                  |  2 +-
 hw/usb/dev-smartcard-reader.c |  3 +--
 hw/virtio/virtio-mmio.c       |  3 +--
 hw/virtio/virtio-pci.c        |  3 +--
 31 files changed, 53 insertions(+), 60 deletions(-)

diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 34c8a7506a1..ebca8cf9fca 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -678,8 +678,8 @@ DeviceState *qdev_find_recursive(BusState *bus, const char *id);
 typedef int (qbus_walkerfn)(BusState *bus, void *opaque);
 typedef int (qdev_walkerfn)(DeviceState *dev, void *opaque);
 
-void qbus_create_inplace(void *bus, size_t size, const char *typename,
-                         DeviceState *parent, const char *name);
+void qbus_init(void *bus, size_t size, const char *typename,
+               DeviceState *parent, const char *name);
 BusState *qbus_create(const char *typename, DeviceState *parent, const char *name);
 bool qbus_realize(BusState *bus, Error **errp);
 void qbus_unrealize(BusState *bus);
diff --git a/hw/audio/intel-hda.c b/hw/audio/intel-hda.c
index 4330213fff1..8ce9df64e3e 100644
--- a/hw/audio/intel-hda.c
+++ b/hw/audio/intel-hda.c
@@ -52,7 +52,7 @@ void hda_codec_bus_init(DeviceState *dev, HDACodecBus *bus, size_t bus_size,
                         hda_codec_response_func response,
                         hda_codec_xfer_func xfer)
 {
-    qbus_create_inplace(bus, bus_size, TYPE_HDA_BUS, dev, NULL);
+    qbus_init(bus, bus_size, TYPE_HDA_BUS, dev, NULL);
     bus->response = response;
     bus->xfer = xfer;
 }
diff --git a/hw/block/fdc.c b/hw/block/fdc.c
index 9014cd30b3a..fa933cd3263 100644
--- a/hw/block/fdc.c
+++ b/hw/block/fdc.c
@@ -77,7 +77,7 @@ static const TypeInfo floppy_bus_info = {
 
 static void floppy_bus_create(FDCtrl *fdc, FloppyBus *bus, DeviceState *dev)
 {
-    qbus_create_inplace(bus, sizeof(FloppyBus), TYPE_FLOPPY_BUS, dev, NULL);
+    qbus_init(bus, sizeof(FloppyBus), TYPE_FLOPPY_BUS, dev, NULL);
     bus->fdc = fdc;
 }
 
diff --git a/hw/block/swim.c b/hw/block/swim.c
index 509c2f49003..333da08ce09 100644
--- a/hw/block/swim.c
+++ b/hw/block/swim.c
@@ -421,8 +421,7 @@ static void sysbus_swim_realize(DeviceState *dev, Error **errp)
     Swim *sys = SWIM(dev);
     SWIMCtrl *swimctrl = &sys->ctrl;
 
-    qbus_create_inplace(&swimctrl->bus, sizeof(SWIMBus), TYPE_SWIM_BUS, dev,
-                        NULL);
+    qbus_init(&swimctrl->bus, sizeof(SWIMBus), TYPE_SWIM_BUS, dev, NULL);
     swimctrl->bus.ctrl = swimctrl;
 }
 
diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index dd6bc27b3b5..f01ec2137c9 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -1048,8 +1048,8 @@ static void virtio_serial_device_realize(DeviceState *dev, Error **errp)
                 config_size);
 
     /* Spawn a new virtio-serial bus on which the ports will ride as devices */
-    qbus_create_inplace(&vser->bus, sizeof(vser->bus), TYPE_VIRTIO_SERIAL_BUS,
-                        dev, vdev->bus_name);
+    qbus_init(&vser->bus, sizeof(vser->bus), TYPE_VIRTIO_SERIAL_BUS,
+              dev, vdev->bus_name);
     qbus_set_hotplug_handler(BUS(&vser->bus), OBJECT(vser));
     vser->bus.vser = vser;
     QTAILQ_INIT(&vser->ports);
diff --git a/hw/core/bus.c b/hw/core/bus.c
index 9cfbc3a6877..cec49985024 100644
--- a/hw/core/bus.c
+++ b/hw/core/bus.c
@@ -99,7 +99,8 @@ static void bus_reset_child_foreach(Object *obj, ResettableChildCallback cb,
     }
 }
 
-static void qbus_init(BusState *bus, DeviceState *parent, const char *name)
+static void qbus_init_internal(BusState *bus, DeviceState *parent,
+                               const char *name)
 {
     const char *typename = object_get_typename(OBJECT(bus));
     BusClass *bc;
@@ -151,11 +152,11 @@ static void bus_unparent(Object *obj)
     bus->parent = NULL;
 }
 
-void qbus_create_inplace(void *bus, size_t size, const char *typename,
-                         DeviceState *parent, const char *name)
+void qbus_init(void *bus, size_t size, const char *typename,
+               DeviceState *parent, const char *name)
 {
     object_initialize(bus, size, typename);
-    qbus_init(bus, parent, name);
+    qbus_init_internal(bus, parent, name);
 }
 
 BusState *qbus_create(const char *typename, DeviceState *parent, const char *name)
@@ -163,7 +164,7 @@ BusState *qbus_create(const char *typename, DeviceState *parent, const char *nam
     BusState *bus;
 
     bus = BUS(object_new(typename));
-    qbus_init(bus, parent, name);
+    qbus_init_internal(bus, parent, name);
 
     return bus;
 }
diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
index aaae8e23cc4..05c1da3d311 100644
--- a/hw/core/sysbus.c
+++ b/hw/core/sysbus.c
@@ -340,11 +340,13 @@ static BusState *main_system_bus;
 
 static void main_system_bus_create(void)
 {
-    /* assign main_system_bus before qbus_create_inplace()
-     * in order to make "if (bus != sysbus_get_default())" work */
+    /*
+     * assign main_system_bus before qbus_init()
+     * in order to make "if (bus != sysbus_get_default())" work
+     */
     main_system_bus = g_malloc0(system_bus_info.instance_size);
-    qbus_create_inplace(main_system_bus, system_bus_info.instance_size,
-                        TYPE_SYSTEM_BUS, NULL, "main-system-bus");
+    qbus_init(main_system_bus, system_bus_info.instance_size,
+              TYPE_SYSTEM_BUS, NULL, "main-system-bus");
     OBJECT(main_system_bus)->free = g_free;
 }
 
diff --git a/hw/gpio/bcm2835_gpio.c b/hw/gpio/bcm2835_gpio.c
index abdddbc67c2..c995bba1d9f 100644
--- a/hw/gpio/bcm2835_gpio.c
+++ b/hw/gpio/bcm2835_gpio.c
@@ -299,8 +299,7 @@ static void bcm2835_gpio_init(Object *obj)
     DeviceState *dev = DEVICE(obj);
     SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
 
-    qbus_create_inplace(&s->sdbus, sizeof(s->sdbus),
-                        TYPE_SD_BUS, DEVICE(s), "sd-bus");
+    qbus_init(&s->sdbus, sizeof(s->sdbus), TYPE_SD_BUS, DEVICE(s), "sd-bus");
 
     memory_region_init_io(&s->iomem, obj,
             &bcm2835_gpio_ops, s, "bcm2835_gpio", 0x1000);
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index e70ebc83a07..ca844419106 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -71,7 +71,7 @@ static const TypeInfo ide_bus_info = {
 void ide_bus_new(IDEBus *idebus, size_t idebus_size, DeviceState *dev,
                  int bus_id, int max_units)
 {
-    qbus_create_inplace(idebus, idebus_size, TYPE_IDE_BUS, dev, NULL);
+    qbus_init(idebus, idebus_size, TYPE_IDE_BUS, dev, NULL);
     idebus->bus_id = bus_id;
     idebus->max_units = max_units;
 }
diff --git a/hw/ipack/ipack.c b/hw/ipack/ipack.c
index d28e7f6449e..ae20f36da68 100644
--- a/hw/ipack/ipack.c
+++ b/hw/ipack/ipack.c
@@ -35,7 +35,7 @@ void ipack_bus_init(IPackBus *bus, size_t bus_size,
                     uint8_t n_slots,
                     qemu_irq_handler handler)
 {
-    qbus_create_inplace(bus, bus_size, TYPE_IPACK_BUS, parent, NULL);
+    qbus_init(bus, bus_size, TYPE_IPACK_BUS, parent, NULL);
     bus->n_slots = n_slots;
     bus->set_irq = handler;
 }
diff --git a/hw/misc/mac_via.c b/hw/misc/mac_via.c
index d1abcd97b51..993bac017db 100644
--- a/hw/misc/mac_via.c
+++ b/hw/misc/mac_via.c
@@ -1038,8 +1038,8 @@ static void mos6522_q800_via1_init(Object *obj)
     sysbus_init_mmio(sbd, &v1s->via_mem);
 
     /* ADB */
-    qbus_create_inplace((BusState *)&v1s->adb_bus, sizeof(v1s->adb_bus),
-                        TYPE_ADB_BUS, DEVICE(v1s), "adb.0");
+    qbus_init((BusState *)&v1s->adb_bus, sizeof(v1s->adb_bus),
+              TYPE_ADB_BUS, DEVICE(v1s), "adb.0");
 
     qdev_init_gpio_in(DEVICE(obj), via1_irq_request, VIA1_IRQ_NB);
 }
diff --git a/hw/misc/macio/cuda.c b/hw/misc/macio/cuda.c
index edbd4186b2a..e917a6a095b 100644
--- a/hw/misc/macio/cuda.c
+++ b/hw/misc/macio/cuda.c
@@ -553,8 +553,8 @@ static void cuda_init(Object *obj)
     memory_region_init_io(&s->mem, obj, &mos6522_cuda_ops, s, "cuda", 0x2000);
     sysbus_init_mmio(sbd, &s->mem);
 
-    qbus_create_inplace(&s->adb_bus, sizeof(s->adb_bus), TYPE_ADB_BUS,
-                        DEVICE(obj), "adb.0");
+    qbus_init(&s->adb_bus, sizeof(s->adb_bus), TYPE_ADB_BUS,
+              DEVICE(obj), "adb.0");
 }
 
 static Property cuda_properties[] = {
diff --git a/hw/misc/macio/macio.c b/hw/misc/macio/macio.c
index 4515296e66a..c1fad43f6c6 100644
--- a/hw/misc/macio/macio.c
+++ b/hw/misc/macio/macio.c
@@ -387,8 +387,8 @@ static void macio_instance_init(Object *obj)
 
     memory_region_init(&s->bar, obj, "macio", 0x80000);
 
-    qbus_create_inplace(&s->macio_bus, sizeof(s->macio_bus), TYPE_MACIO_BUS,
-                        DEVICE(obj), "macio.0");
+    qbus_init(&s->macio_bus, sizeof(s->macio_bus), TYPE_MACIO_BUS,
+              DEVICE(obj), "macio.0");
 
     object_initialize_child(OBJECT(s), "dbdma", &s->dbdma, TYPE_MAC_DBDMA);
 
diff --git a/hw/misc/macio/pmu.c b/hw/misc/macio/pmu.c
index 71924d4768c..4ad4f50e08c 100644
--- a/hw/misc/macio/pmu.c
+++ b/hw/misc/macio/pmu.c
@@ -754,8 +754,8 @@ static void pmu_realize(DeviceState *dev, Error **errp)
     timer_mod(s->one_sec_timer, s->one_sec_target);
 
     if (s->has_adb) {
-        qbus_create_inplace(&s->adb_bus, sizeof(s->adb_bus), TYPE_ADB_BUS,
-                            dev, "adb.0");
+        qbus_init(&s->adb_bus, sizeof(s->adb_bus), TYPE_ADB_BUS,
+                  dev, "adb.0");
         adb_register_autopoll_callback(adb_bus, pmu_adb_poll, s);
     }
 }
diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index 6baf9e0420d..6b29d832351 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -6530,8 +6530,8 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)
         return;
     }
 
-    qbus_create_inplace(&n->bus, sizeof(NvmeBus), TYPE_NVME_BUS,
-                        &pci_dev->qdev, n->parent_obj.qdev.id);
+    qbus_init(&n->bus, sizeof(NvmeBus), TYPE_NVME_BUS,
+              &pci_dev->qdev, n->parent_obj.qdev.id);
 
     nvme_init_state(n);
     if (nvme_init_pci(n, pci_dev, errp)) {
diff --git a/hw/nvme/subsys.c b/hw/nvme/subsys.c
index 93c35950d69..495dcff5ebb 100644
--- a/hw/nvme/subsys.c
+++ b/hw/nvme/subsys.c
@@ -50,8 +50,7 @@ static void nvme_subsys_realize(DeviceState *dev, Error **errp)
 {
     NvmeSubsystem *subsys = NVME_SUBSYS(dev);
 
-    qbus_create_inplace(&subsys->bus, sizeof(NvmeBus), TYPE_NVME_BUS, dev,
-                        dev->id);
+    qbus_init(&subsys->bus, sizeof(NvmeBus), TYPE_NVME_BUS, dev, dev->id);
 
     nvme_subsys_setup(subsys);
 }
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 19881c84f23..14cb15a0aa1 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -466,7 +466,7 @@ void pci_root_bus_init(PCIBus *bus, size_t bus_size, DeviceState *parent,
                        MemoryRegion *address_space_io,
                        uint8_t devfn_min, const char *typename)
 {
-    qbus_create_inplace(bus, bus_size, typename, parent, name);
+    qbus_init(bus, bus_size, typename, parent, name);
     pci_root_bus_internal_init(bus, parent, address_space_mem,
                                address_space_io, devfn_min);
 }
diff --git a/hw/pci/pci_bridge.c b/hw/pci/pci_bridge.c
index 3789c17edc2..d1f902ee862 100644
--- a/hw/pci/pci_bridge.c
+++ b/hw/pci/pci_bridge.c
@@ -374,8 +374,8 @@ void pci_bridge_initfn(PCIDevice *dev, const char *typename)
             br->bus_name = dev->qdev.id;
     }
 
-    qbus_create_inplace(sec_bus, sizeof(br->sec_bus), typename, DEVICE(dev),
-                        br->bus_name);
+    qbus_init(sec_bus, sizeof(br->sec_bus), typename, DEVICE(dev),
+              br->bus_name);
     sec_bus->parent_dev = dev;
     sec_bus->map_irq = br->map_irq ? br->map_irq : pci_swizzle_map_irq_fn;
     sec_bus->address_space_mem = &br->address_space_mem;
diff --git a/hw/s390x/event-facility.c b/hw/s390x/event-facility.c
index ed92ce510d9..6fa47b889ca 100644
--- a/hw/s390x/event-facility.c
+++ b/hw/s390x/event-facility.c
@@ -427,8 +427,8 @@ static void init_event_facility(Object *obj)
                              sclp_event_set_allow_all_mask_sizes);
 
     /* Spawn a new bus for SCLP events */
-    qbus_create_inplace(&event_facility->sbus, sizeof(event_facility->sbus),
-                        TYPE_SCLP_EVENTS_BUS, sdev, NULL);
+    qbus_init(&event_facility->sbus, sizeof(event_facility->sbus),
+              TYPE_SCLP_EVENTS_BUS, sdev, NULL);
 
     object_initialize_child(obj, TYPE_SCLP_QUIESCE,
                             &event_facility->quiesce,
diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
index 6a2df1c1e9a..c845a92c3a8 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -1261,8 +1261,7 @@ static void virtio_ccw_bus_new(VirtioBusState *bus, size_t bus_size,
     DeviceState *qdev = DEVICE(dev);
     char virtio_bus_name[] = "virtio-bus";
 
-    qbus_create_inplace(bus, bus_size, TYPE_VIRTIO_CCW_BUS,
-                        qdev, virtio_bus_name);
+    qbus_init(bus, bus_size, TYPE_VIRTIO_CCW_BUS, qdev, virtio_bus_name);
 }
 
 static void virtio_ccw_bus_class_init(ObjectClass *klass, void *data)
diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c
index e28a6ea053a..77325d8cc7a 100644
--- a/hw/scsi/scsi-bus.c
+++ b/hw/scsi/scsi-bus.c
@@ -137,7 +137,7 @@ void scsi_device_unit_attention_reported(SCSIDevice *s)
 void scsi_bus_init_named(SCSIBus *bus, size_t bus_size, DeviceState *host,
                          const SCSIBusInfo *info, const char *bus_name)
 {
-    qbus_create_inplace(bus, bus_size, TYPE_SCSI_BUS, host, bus_name);
+    qbus_init(bus, bus_size, TYPE_SCSI_BUS, host, bus_name);
     bus->busnr = next_scsi_bus++;
     bus->info = info;
     qbus_set_bus_hotplug_handler(BUS(bus));
diff --git a/hw/sd/allwinner-sdhost.c b/hw/sd/allwinner-sdhost.c
index bea6d97ef87..9166d6638de 100644
--- a/hw/sd/allwinner-sdhost.c
+++ b/hw/sd/allwinner-sdhost.c
@@ -738,8 +738,8 @@ static void allwinner_sdhost_init(Object *obj)
 {
     AwSdHostState *s = AW_SDHOST(obj);
 
-    qbus_create_inplace(&s->sdbus, sizeof(s->sdbus),
-                         TYPE_AW_SDHOST_BUS, DEVICE(s), "sd-bus");
+    qbus_init(&s->sdbus, sizeof(s->sdbus),
+              TYPE_AW_SDHOST_BUS, DEVICE(s), "sd-bus");
 
     memory_region_init_io(&s->iomem, obj, &allwinner_sdhost_ops, s,
                            TYPE_AW_SDHOST, 4 * KiB);
diff --git a/hw/sd/bcm2835_sdhost.c b/hw/sd/bcm2835_sdhost.c
index 50f5fdb88bc..088a7ac6ed4 100644
--- a/hw/sd/bcm2835_sdhost.c
+++ b/hw/sd/bcm2835_sdhost.c
@@ -403,8 +403,8 @@ static void bcm2835_sdhost_init(Object *obj)
 {
     BCM2835SDHostState *s = BCM2835_SDHOST(obj);
 
-    qbus_create_inplace(&s->sdbus, sizeof(s->sdbus),
-                        TYPE_BCM2835_SDHOST_BUS, DEVICE(s), "sd-bus");
+    qbus_init(&s->sdbus, sizeof(s->sdbus),
+              TYPE_BCM2835_SDHOST_BUS, DEVICE(s), "sd-bus");
 
     memory_region_init_io(&s->iomem, obj, &bcm2835_sdhost_ops, s,
                           TYPE_BCM2835_SDHOST, 0x1000);
diff --git a/hw/sd/pl181.c b/hw/sd/pl181.c
index 960f1550981..5e554bd4676 100644
--- a/hw/sd/pl181.c
+++ b/hw/sd/pl181.c
@@ -506,8 +506,7 @@ static void pl181_init(Object *obj)
     qdev_init_gpio_out_named(dev, &s->card_readonly, "card-read-only", 1);
     qdev_init_gpio_out_named(dev, &s->card_inserted, "card-inserted", 1);
 
-    qbus_create_inplace(&s->sdbus, sizeof(s->sdbus),
-                        TYPE_PL181_BUS, dev, "sd-bus");
+    qbus_init(&s->sdbus, sizeof(s->sdbus), TYPE_PL181_BUS, dev, "sd-bus");
 }
 
 static void pl181_class_init(ObjectClass *klass, void *data)
diff --git a/hw/sd/pxa2xx_mmci.c b/hw/sd/pxa2xx_mmci.c
index 3dd2fc7a83f..124fbf8bbd4 100644
--- a/hw/sd/pxa2xx_mmci.c
+++ b/hw/sd/pxa2xx_mmci.c
@@ -560,8 +560,8 @@ static void pxa2xx_mmci_instance_init(Object *obj)
     qdev_init_gpio_out_named(dev, &s->rx_dma, "rx-dma", 1);
     qdev_init_gpio_out_named(dev, &s->tx_dma, "tx-dma", 1);
 
-    qbus_create_inplace(&s->sdbus, sizeof(s->sdbus),
-                        TYPE_PXA2XX_MMCI_BUS, DEVICE(obj), "sd-bus");
+    qbus_init(&s->sdbus, sizeof(s->sdbus),
+              TYPE_PXA2XX_MMCI_BUS, DEVICE(obj), "sd-bus");
 }
 
 static void pxa2xx_mmci_class_init(ObjectClass *klass, void *data)
diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
index 5b8678110b0..c9dc065cc52 100644
--- a/hw/sd/sdhci.c
+++ b/hw/sd/sdhci.c
@@ -1337,8 +1337,7 @@ static void sdhci_init_readonly_registers(SDHCIState *s, Error **errp)
 
 void sdhci_initfn(SDHCIState *s)
 {
-    qbus_create_inplace(&s->sdbus, sizeof(s->sdbus),
-                        TYPE_SDHCI_BUS, DEVICE(s), "sd-bus");
+    qbus_init(&s->sdbus, sizeof(s->sdbus), TYPE_SDHCI_BUS, DEVICE(s), "sd-bus");
 
     s->insert_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, sdhci_raise_insertion_irq, s);
     s->transfer_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, sdhci_data_transfer, s);
diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c
index 97ee58e20cf..e60854eeefc 100644
--- a/hw/sd/ssi-sd.c
+++ b/hw/sd/ssi-sd.c
@@ -373,8 +373,7 @@ static void ssi_sd_realize(SSIPeripheral *d, Error **errp)
     DeviceState *carddev;
     DriveInfo *dinfo;
 
-    qbus_create_inplace(&s->sdbus, sizeof(s->sdbus), TYPE_SD_BUS,
-                        DEVICE(d), "sd-bus");
+    qbus_init(&s->sdbus, sizeof(s->sdbus), TYPE_SD_BUS, DEVICE(d), "sd-bus");
 
     /* Create and plug in the sd card */
     /* FIXME use a qdev drive property instead of drive_get_next() */
diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index 07083349f51..5d441a70650 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -82,7 +82,7 @@ const VMStateDescription vmstate_usb_device = {
 void usb_bus_new(USBBus *bus, size_t bus_size,
                  USBBusOps *ops, DeviceState *host)
 {
-    qbus_create_inplace(bus, bus_size, TYPE_USB_BUS, host, NULL);
+    qbus_init(bus, bus_size, TYPE_USB_BUS, host, NULL);
     qbus_set_bus_hotplug_handler(BUS(bus));
     bus->ops = ops;
     bus->busnr = next_usb_bus++;
diff --git a/hw/usb/dev-smartcard-reader.c b/hw/usb/dev-smartcard-reader.c
index f7043075be5..91ffd9f8ae8 100644
--- a/hw/usb/dev-smartcard-reader.c
+++ b/hw/usb/dev-smartcard-reader.c
@@ -1320,8 +1320,7 @@ static void ccid_realize(USBDevice *dev, Error **errp)
 
     usb_desc_create_serial(dev);
     usb_desc_init(dev);
-    qbus_create_inplace(&s->bus, sizeof(s->bus), TYPE_CCID_BUS, DEVICE(dev),
-                        NULL);
+    qbus_init(&s->bus, sizeof(s->bus), TYPE_CCID_BUS, DEVICE(dev), NULL);
     qbus_set_hotplug_handler(BUS(&s->bus), OBJECT(dev));
     s->intr = usb_ep_get(dev, USB_TOKEN_IN, CCID_INT_IN_EP);
     s->bulk = usb_ep_get(dev, USB_TOKEN_IN, CCID_BULK_IN_EP);
diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c
index 1af48a1b044..7b3ebca1781 100644
--- a/hw/virtio/virtio-mmio.c
+++ b/hw/virtio/virtio-mmio.c
@@ -733,8 +733,7 @@ static void virtio_mmio_realizefn(DeviceState *d, Error **errp)
     VirtIOMMIOProxy *proxy = VIRTIO_MMIO(d);
     SysBusDevice *sbd = SYS_BUS_DEVICE(d);
 
-    qbus_create_inplace(&proxy->bus, sizeof(proxy->bus), TYPE_VIRTIO_MMIO_BUS,
-                        d, NULL);
+    qbus_init(&proxy->bus, sizeof(proxy->bus), TYPE_VIRTIO_MMIO_BUS, d, NULL);
     sysbus_init_irq(sbd, &proxy->irq);
 
     if (!kvm_eventfds_enabled()) {
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 6e16e2705ce..750aa47ec14 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -2187,8 +2187,7 @@ static void virtio_pci_bus_new(VirtioBusState *bus, size_t bus_size,
     DeviceState *qdev = DEVICE(dev);
     char virtio_bus_name[] = "virtio-bus";
 
-    qbus_create_inplace(bus, bus_size, TYPE_VIRTIO_PCI_BUS, qdev,
-                        virtio_bus_name);
+    qbus_init(bus, bus_size, TYPE_VIRTIO_PCI_BUS, qdev, virtio_bus_name);
 }
 
 static void virtio_pci_bus_class_init(ObjectClass *klass, void *data)
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 5/6] qbus: Rename qbus_create() to qbus_new()
  2021-09-23 12:11 [PATCH 0/6] Improve consistency of bus init function names Peter Maydell
                   ` (3 preceding siblings ...)
  2021-09-23 12:11 ` [PATCH 4/6] qbus: Rename qbus_create_inplace() to qbus_init() Peter Maydell
@ 2021-09-23 12:11 ` Peter Maydell
  2021-09-23 16:00   ` Corey Minyard
  2021-09-23 12:11 ` [PATCH 6/6] ide: Rename ide_bus_new() to ide_bus_init() Peter Maydell
                   ` (3 subsequent siblings)
  8 siblings, 1 reply; 13+ messages in thread
From: Peter Maydell @ 2021-09-23 12:11 UTC (permalink / raw)
  To: qemu-devel
  Cc: Fam Zheng, Alberto Garcia, Eduardo Habkost, Michael S . Tsirkin,
	Daniel P. Berrange, Markus Armbruster, Paolo Bonzini, John Snow

Rename the "allocate and return" qbus creation function to
qbus_new(), to bring it into line with our _init vs _new convention.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 include/hw/qdev-core.h      | 2 +-
 hw/core/bus.c               | 2 +-
 hw/hyperv/vmbus.c           | 2 +-
 hw/i2c/core.c               | 2 +-
 hw/isa/isa-bus.c            | 2 +-
 hw/misc/auxbus.c            | 2 +-
 hw/nubus/mac-nubus-bridge.c | 2 +-
 hw/pci/pci.c                | 2 +-
 hw/ppc/spapr_vio.c          | 2 +-
 hw/s390x/ap-bridge.c        | 2 +-
 hw/s390x/css-bridge.c       | 2 +-
 hw/s390x/s390-pci-bus.c     | 2 +-
 hw/ssi/ssi.c                | 2 +-
 hw/xen/xen-bus.c            | 2 +-
 hw/xen/xen-legacy-backend.c | 2 +-
 15 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index ebca8cf9fca..4ff19c714bd 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -680,7 +680,7 @@ typedef int (qdev_walkerfn)(DeviceState *dev, void *opaque);
 
 void qbus_init(void *bus, size_t size, const char *typename,
                DeviceState *parent, const char *name);
-BusState *qbus_create(const char *typename, DeviceState *parent, const char *name);
+BusState *qbus_new(const char *typename, DeviceState *parent, const char *name);
 bool qbus_realize(BusState *bus, Error **errp);
 void qbus_unrealize(BusState *bus);
 
diff --git a/hw/core/bus.c b/hw/core/bus.c
index cec49985024..c7831b5293b 100644
--- a/hw/core/bus.c
+++ b/hw/core/bus.c
@@ -159,7 +159,7 @@ void qbus_init(void *bus, size_t size, const char *typename,
     qbus_init_internal(bus, parent, name);
 }
 
-BusState *qbus_create(const char *typename, DeviceState *parent, const char *name)
+BusState *qbus_new(const char *typename, DeviceState *parent, const char *name)
 {
     BusState *bus;
 
diff --git a/hw/hyperv/vmbus.c b/hw/hyperv/vmbus.c
index c9887d5a7bc..dbce3b35fba 100644
--- a/hw/hyperv/vmbus.c
+++ b/hw/hyperv/vmbus.c
@@ -2729,7 +2729,7 @@ static void vmbus_bridge_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    bridge->bus = VMBUS(qbus_create(TYPE_VMBUS, dev, "vmbus"));
+    bridge->bus = VMBUS(qbus_new(TYPE_VMBUS, dev, "vmbus"));
 }
 
 static char *vmbus_bridge_ofw_unit_address(const SysBusDevice *dev)
diff --git a/hw/i2c/core.c b/hw/i2c/core.c
index 416372ad00c..0e7d2763b9e 100644
--- a/hw/i2c/core.c
+++ b/hw/i2c/core.c
@@ -60,7 +60,7 @@ I2CBus *i2c_init_bus(DeviceState *parent, const char *name)
 {
     I2CBus *bus;
 
-    bus = I2C_BUS(qbus_create(TYPE_I2C_BUS, parent, name));
+    bus = I2C_BUS(qbus_new(TYPE_I2C_BUS, parent, name));
     QLIST_INIT(&bus->current_devs);
     vmstate_register(NULL, VMSTATE_INSTANCE_ID_ANY, &vmstate_i2c_bus, bus);
     return bus;
diff --git a/hw/isa/isa-bus.c b/hw/isa/isa-bus.c
index cffaa35e9cf..6c31398dda6 100644
--- a/hw/isa/isa-bus.c
+++ b/hw/isa/isa-bus.c
@@ -64,7 +64,7 @@ ISABus *isa_bus_new(DeviceState *dev, MemoryRegion* address_space,
         sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
     }
 
-    isabus = ISA_BUS(qbus_create(TYPE_ISA_BUS, dev, NULL));
+    isabus = ISA_BUS(qbus_new(TYPE_ISA_BUS, dev, NULL));
     isabus->address_space = address_space;
     isabus->address_space_io = address_space_io;
     return isabus;
diff --git a/hw/misc/auxbus.c b/hw/misc/auxbus.c
index 434ff8d910d..8a8012f5f08 100644
--- a/hw/misc/auxbus.c
+++ b/hw/misc/auxbus.c
@@ -65,7 +65,7 @@ AUXBus *aux_bus_init(DeviceState *parent, const char *name)
     AUXBus *bus;
     Object *auxtoi2c;
 
-    bus = AUX_BUS(qbus_create(TYPE_AUX_BUS, parent, name));
+    bus = AUX_BUS(qbus_new(TYPE_AUX_BUS, parent, name));
     auxtoi2c = object_new_with_props(TYPE_AUXTOI2C, OBJECT(bus), "i2c",
                                      &error_abort, NULL);
 
diff --git a/hw/nubus/mac-nubus-bridge.c b/hw/nubus/mac-nubus-bridge.c
index 7c329300b82..148979dab13 100644
--- a/hw/nubus/mac-nubus-bridge.c
+++ b/hw/nubus/mac-nubus-bridge.c
@@ -16,7 +16,7 @@ static void mac_nubus_bridge_init(Object *obj)
     MacNubusState *s = MAC_NUBUS_BRIDGE(obj);
     SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
 
-    s->bus = NUBUS_BUS(qbus_create(TYPE_NUBUS_BUS, DEVICE(s), NULL));
+    s->bus = NUBUS_BUS(qbus_new(TYPE_NUBUS_BUS, DEVICE(s), NULL));
 
     sysbus_init_mmio(sbd, &s->bus->super_slot_io);
     sysbus_init_mmio(sbd, &s->bus->slot_io);
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 14cb15a0aa1..186758ee11f 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -478,7 +478,7 @@ PCIBus *pci_root_bus_new(DeviceState *parent, const char *name,
 {
     PCIBus *bus;
 
-    bus = PCI_BUS(qbus_create(typename, parent, name));
+    bus = PCI_BUS(qbus_new(typename, parent, name));
     pci_root_bus_internal_init(bus, parent, address_space_mem,
                                address_space_io, devfn_min);
     return bus;
diff --git a/hw/ppc/spapr_vio.c b/hw/ppc/spapr_vio.c
index b59452bcd62..b975ed29cad 100644
--- a/hw/ppc/spapr_vio.c
+++ b/hw/ppc/spapr_vio.c
@@ -577,7 +577,7 @@ SpaprVioBus *spapr_vio_bus_init(void)
     sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
 
     /* Create bus on bridge device */
-    qbus = qbus_create(TYPE_SPAPR_VIO_BUS, dev, "spapr-vio");
+    qbus = qbus_new(TYPE_SPAPR_VIO_BUS, dev, "spapr-vio");
     bus = SPAPR_VIO_BUS(qbus);
     bus->next_reg = SPAPR_VIO_REG_BASE;
 
diff --git a/hw/s390x/ap-bridge.c b/hw/s390x/ap-bridge.c
index 8bcf8ece9dd..ef8fa2b15be 100644
--- a/hw/s390x/ap-bridge.c
+++ b/hw/s390x/ap-bridge.c
@@ -55,7 +55,7 @@ void s390_init_ap(void)
     sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
 
     /* Create bus on bridge device */
-    bus = qbus_create(TYPE_AP_BUS, dev, TYPE_AP_BUS);
+    bus = qbus_new(TYPE_AP_BUS, dev, TYPE_AP_BUS);
 
     /* Enable hotplugging */
     qbus_set_hotplug_handler(bus, OBJECT(dev));
diff --git a/hw/s390x/css-bridge.c b/hw/s390x/css-bridge.c
index 191b29f0771..4017081d49c 100644
--- a/hw/s390x/css-bridge.c
+++ b/hw/s390x/css-bridge.c
@@ -106,7 +106,7 @@ VirtualCssBus *virtual_css_bus_init(void)
     sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
 
     /* Create bus on bridge device */
-    bus = qbus_create(TYPE_VIRTUAL_CSS_BUS, dev, "virtual-css");
+    bus = qbus_new(TYPE_VIRTUAL_CSS_BUS, dev, "virtual-css");
     cbus = VIRTUAL_CSS_BUS(bus);
 
     /* Enable hotplugging */
diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
index 6c0225c3a01..6fafffb029a 100644
--- a/hw/s390x/s390-pci-bus.c
+++ b/hw/s390x/s390-pci-bus.c
@@ -813,7 +813,7 @@ static void s390_pcihost_realize(DeviceState *dev, Error **errp)
     qbus_set_hotplug_handler(bus, OBJECT(dev));
     phb->bus = b;
 
-    s->bus = S390_PCI_BUS(qbus_create(TYPE_S390_PCI_BUS, dev, NULL));
+    s->bus = S390_PCI_BUS(qbus_new(TYPE_S390_PCI_BUS, dev, NULL));
     qbus_set_hotplug_handler(BUS(s->bus), OBJECT(dev));
 
     s->iommu_table = g_hash_table_new_full(g_int64_hash, g_int64_equal,
diff --git a/hw/ssi/ssi.c b/hw/ssi/ssi.c
index e5d7ce95237..003931fb509 100644
--- a/hw/ssi/ssi.c
+++ b/hw/ssi/ssi.c
@@ -107,7 +107,7 @@ DeviceState *ssi_create_peripheral(SSIBus *bus, const char *name)
 SSIBus *ssi_create_bus(DeviceState *parent, const char *name)
 {
     BusState *bus;
-    bus = qbus_create(TYPE_SSI_BUS, parent, name);
+    bus = qbus_new(TYPE_SSI_BUS, parent, name);
     return SSI_BUS(bus);
 }
 
diff --git a/hw/xen/xen-bus.c b/hw/xen/xen-bus.c
index 8c588920d9f..416583f130b 100644
--- a/hw/xen/xen-bus.c
+++ b/hw/xen/xen-bus.c
@@ -1398,7 +1398,7 @@ type_init(xen_register_types)
 void xen_bus_init(void)
 {
     DeviceState *dev = qdev_new(TYPE_XEN_BRIDGE);
-    BusState *bus = qbus_create(TYPE_XEN_BUS, dev, NULL);
+    BusState *bus = qbus_new(TYPE_XEN_BUS, dev, NULL);
 
     sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
     qbus_set_bus_hotplug_handler(bus);
diff --git a/hw/xen/xen-legacy-backend.c b/hw/xen/xen-legacy-backend.c
index dd8ae1452d1..be3cf4a195e 100644
--- a/hw/xen/xen-legacy-backend.c
+++ b/hw/xen/xen-legacy-backend.c
@@ -702,7 +702,7 @@ int xen_be_init(void)
 
     xen_sysdev = qdev_new(TYPE_XENSYSDEV);
     sysbus_realize_and_unref(SYS_BUS_DEVICE(xen_sysdev), &error_fatal);
-    xen_sysbus = qbus_create(TYPE_XENSYSBUS, xen_sysdev, "xen-sysbus");
+    xen_sysbus = qbus_new(TYPE_XENSYSBUS, xen_sysdev, "xen-sysbus");
     qbus_set_bus_hotplug_handler(xen_sysbus);
 
     return 0;
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 6/6] ide: Rename ide_bus_new() to ide_bus_init()
  2021-09-23 12:11 [PATCH 0/6] Improve consistency of bus init function names Peter Maydell
                   ` (4 preceding siblings ...)
  2021-09-23 12:11 ` [PATCH 5/6] qbus: Rename qbus_create() to qbus_new() Peter Maydell
@ 2021-09-23 12:11 ` Peter Maydell
  2021-09-23 18:26   ` John Snow
  2021-09-23 13:36 ` [PATCH 0/6] Improve consistency of bus init function names Philippe Mathieu-Daudé
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 13+ messages in thread
From: Peter Maydell @ 2021-09-23 12:11 UTC (permalink / raw)
  To: qemu-devel
  Cc: Fam Zheng, Alberto Garcia, Eduardo Habkost, Michael S . Tsirkin,
	Daniel P. Berrange, Markus Armbruster, Paolo Bonzini, John Snow

The function ide_bus_new() does an in-place initialization.  Rename
it to ide_bus_init() to follow our _init vs _new convention.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 include/hw/ide/internal.h | 4 ++--
 hw/ide/ahci.c             | 2 +-
 hw/ide/cmd646.c           | 2 +-
 hw/ide/isa.c              | 2 +-
 hw/ide/macio.c            | 2 +-
 hw/ide/microdrive.c       | 2 +-
 hw/ide/mmio.c             | 2 +-
 hw/ide/piix.c             | 2 +-
 hw/ide/qdev.c             | 2 +-
 hw/ide/sii3112.c          | 2 +-
 hw/ide/via.c              | 2 +-
 11 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/include/hw/ide/internal.h b/include/hw/ide/internal.h
index 79172217ccb..97e7e59dc58 100644
--- a/include/hw/ide/internal.h
+++ b/include/hw/ide/internal.h
@@ -648,8 +648,8 @@ void ide_atapi_cmd(IDEState *s);
 void ide_atapi_cmd_reply_end(IDEState *s);
 
 /* hw/ide/qdev.c */
-void ide_bus_new(IDEBus *idebus, size_t idebus_size, DeviceState *dev,
-                 int bus_id, int max_units);
+void ide_bus_init(IDEBus *idebus, size_t idebus_size, DeviceState *dev,
+                  int bus_id, int max_units);
 IDEDevice *ide_create_drive(IDEBus *bus, int unit, DriveInfo *drive);
 
 int ide_handle_rw_error(IDEState *s, int error, int op);
diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
index f2c51574839..a94c6e26fb0 100644
--- a/hw/ide/ahci.c
+++ b/hw/ide/ahci.c
@@ -1548,7 +1548,7 @@ void ahci_realize(AHCIState *s, DeviceState *qdev, AddressSpace *as, int ports)
     for (i = 0; i < s->ports; i++) {
         AHCIDevice *ad = &s->dev[i];
 
-        ide_bus_new(&ad->port, sizeof(ad->port), qdev, i, 1);
+        ide_bus_init(&ad->port, sizeof(ad->port), qdev, i, 1);
         ide_init2(&ad->port, irqs[i]);
 
         ad->hba = s;
diff --git a/hw/ide/cmd646.c b/hw/ide/cmd646.c
index c2546314855..94c576262c1 100644
--- a/hw/ide/cmd646.c
+++ b/hw/ide/cmd646.c
@@ -293,7 +293,7 @@ static void pci_cmd646_ide_realize(PCIDevice *dev, Error **errp)
 
     qdev_init_gpio_in(ds, cmd646_set_irq, 2);
     for (i = 0; i < 2; i++) {
-        ide_bus_new(&d->bus[i], sizeof(d->bus[i]), ds, i, 2);
+        ide_bus_init(&d->bus[i], sizeof(d->bus[i]), ds, i, 2);
         ide_init2(&d->bus[i], qdev_get_gpio_in(ds, i));
 
         bmdma_init(&d->bus[i], &d->bmdma[i], d);
diff --git a/hw/ide/isa.c b/hw/ide/isa.c
index 6bc19de2265..24bbde24c2b 100644
--- a/hw/ide/isa.c
+++ b/hw/ide/isa.c
@@ -73,7 +73,7 @@ static void isa_ide_realizefn(DeviceState *dev, Error **errp)
     ISADevice *isadev = ISA_DEVICE(dev);
     ISAIDEState *s = ISA_IDE(dev);
 
-    ide_bus_new(&s->bus, sizeof(s->bus), dev, 0, 2);
+    ide_bus_init(&s->bus, sizeof(s->bus), dev, 0, 2);
     ide_init_ioport(&s->bus, isadev, s->iobase, s->iobase2);
     isa_init_irq(isadev, &s->irq, s->isairq);
     ide_init2(&s->bus, s->irq);
diff --git a/hw/ide/macio.c b/hw/ide/macio.c
index b270a101632..b03d401ceb5 100644
--- a/hw/ide/macio.c
+++ b/hw/ide/macio.c
@@ -449,7 +449,7 @@ static void macio_ide_initfn(Object *obj)
     SysBusDevice *d = SYS_BUS_DEVICE(obj);
     MACIOIDEState *s = MACIO_IDE(obj);
 
-    ide_bus_new(&s->bus, sizeof(s->bus), DEVICE(obj), 0, 2);
+    ide_bus_init(&s->bus, sizeof(s->bus), DEVICE(obj), 0, 2);
     memory_region_init_io(&s->mem, obj, &pmac_ide_ops, s, "pmac-ide", 0x1000);
     sysbus_init_mmio(d, &s->mem);
     sysbus_init_irq(d, &s->real_ide_irq);
diff --git a/hw/ide/microdrive.c b/hw/ide/microdrive.c
index 58a14fea363..6df9b4cbbe1 100644
--- a/hw/ide/microdrive.c
+++ b/hw/ide/microdrive.c
@@ -605,7 +605,7 @@ static void microdrive_init(Object *obj)
 {
     MicroDriveState *md = MICRODRIVE(obj);
 
-    ide_bus_new(&md->bus, sizeof(md->bus), DEVICE(obj), 0, 1);
+    ide_bus_init(&md->bus, sizeof(md->bus), DEVICE(obj), 0, 1);
 }
 
 static void microdrive_class_init(ObjectClass *oc, void *data)
diff --git a/hw/ide/mmio.c b/hw/ide/mmio.c
index 36e2f4790ab..fb2ebd4847f 100644
--- a/hw/ide/mmio.c
+++ b/hw/ide/mmio.c
@@ -142,7 +142,7 @@ static void mmio_ide_initfn(Object *obj)
     SysBusDevice *d = SYS_BUS_DEVICE(obj);
     MMIOState *s = MMIO_IDE(obj);
 
-    ide_bus_new(&s->bus, sizeof(s->bus), DEVICE(obj), 0, 2);
+    ide_bus_init(&s->bus, sizeof(s->bus), DEVICE(obj), 0, 2);
     sysbus_init_irq(d, &s->irq);
 }
 
diff --git a/hw/ide/piix.c b/hw/ide/piix.c
index d3e738320be..ce89fd0aa36 100644
--- a/hw/ide/piix.c
+++ b/hw/ide/piix.c
@@ -137,7 +137,7 @@ static int pci_piix_init_ports(PCIIDEState *d)
     int i, ret;
 
     for (i = 0; i < 2; i++) {
-        ide_bus_new(&d->bus[i], sizeof(d->bus[i]), DEVICE(d), i, 2);
+        ide_bus_init(&d->bus[i], sizeof(d->bus[i]), DEVICE(d), i, 2);
         ret = ide_init_ioport(&d->bus[i], NULL, port_info[i].iobase,
                               port_info[i].iobase2);
         if (ret) {
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index ca844419106..618045b85ac 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -68,7 +68,7 @@ static const TypeInfo ide_bus_info = {
     .class_init = ide_bus_class_init,
 };
 
-void ide_bus_new(IDEBus *idebus, size_t idebus_size, DeviceState *dev,
+void ide_bus_init(IDEBus *idebus, size_t idebus_size, DeviceState *dev,
                  int bus_id, int max_units)
 {
     qbus_init(idebus, idebus_size, TYPE_IDE_BUS, dev, NULL);
diff --git a/hw/ide/sii3112.c b/hw/ide/sii3112.c
index 34c347b9c20..46204f10d75 100644
--- a/hw/ide/sii3112.c
+++ b/hw/ide/sii3112.c
@@ -283,7 +283,7 @@ static void sii3112_pci_realize(PCIDevice *dev, Error **errp)
 
     qdev_init_gpio_in(ds, sii3112_set_irq, 2);
     for (i = 0; i < 2; i++) {
-        ide_bus_new(&s->bus[i], sizeof(s->bus[i]), ds, i, 1);
+        ide_bus_init(&s->bus[i], sizeof(s->bus[i]), ds, i, 1);
         ide_init2(&s->bus[i], qdev_get_gpio_in(ds, i));
 
         bmdma_init(&s->bus[i], &s->bmdma[i], s);
diff --git a/hw/ide/via.c b/hw/ide/via.c
index be09912b334..94cc2142c70 100644
--- a/hw/ide/via.c
+++ b/hw/ide/via.c
@@ -190,7 +190,7 @@ static void via_ide_realize(PCIDevice *dev, Error **errp)
 
     qdev_init_gpio_in(ds, via_ide_set_irq, 2);
     for (i = 0; i < 2; i++) {
-        ide_bus_new(&d->bus[i], sizeof(d->bus[i]), ds, i, 2);
+        ide_bus_init(&d->bus[i], sizeof(d->bus[i]), ds, i, 2);
         ide_init2(&d->bus[i], qdev_get_gpio_in(ds, i));
 
         bmdma_init(&d->bus[i], &d->bmdma[i], d);
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 0/6] Improve consistency of bus init function names
  2021-09-23 12:11 [PATCH 0/6] Improve consistency of bus init function names Peter Maydell
                   ` (5 preceding siblings ...)
  2021-09-23 12:11 ` [PATCH 6/6] ide: Rename ide_bus_new() to ide_bus_init() Peter Maydell
@ 2021-09-23 13:36 ` Philippe Mathieu-Daudé
  2021-09-23 15:38 ` Michael S. Tsirkin
  2021-09-30  9:39 ` Peter Maydell
  8 siblings, 0 replies; 13+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-23 13:36 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel
  Cc: Fam Zheng, Daniel P. Berrange, Eduardo Habkost,
	Michael S . Tsirkin, Markus Armbruster, Paolo Bonzini,
	Alberto Garcia, John Snow

On 9/23/21 14:11, Peter Maydell wrote:
> Currently we have a bit of a mishmash of different function
> names for bus creation. There are two basic patterns: you
> can have a function that allocates and returns a new bus
> object; or you can have a function that takes a pointer to
> a bus object and initializes it in-place. We have to some
> extent a convention for those: the allocate-and-return
> function is 'foo_new()', and the 'init in-place' function
> is 'foo_init()'. However many of our bus creation functions
> don't follow that; some use 'foo_new' vs 'foo_new_inplace';
> some use 'foo_new' for the in-place init version; and
> the bottom level qbus functions are 'qbus_create' vs
> 'qbus_create_inplace'. This series tries to bring at least
> scsi, ipack, pci, ide, and qbus into line with the
> _new-vs-_init naming convention.
> 
> The other issue with bus creation functions is that some
> of them take a 'name' argument which can be NULL, and some
> do not. Generally "pass in a specific name" should be the
> rare case, but our API design here is easy to misuse, and
> so a lot of callsites (especially for i2c, sd, ssi) pass
> in names when they should not. Untangling that mess is
> going to be tricky (see other thread for more), but as
> a first step, this series proposes a split between
> foo_bus_new() and foo_bus_new_named() where the latter
> takes a name parameter and the former does not. I do
> this only for scsi (and implicitly ide, whose ide_bus_new
> function already doesn't take a name argument) for the
> moment, as the other bus types have more of a mess of
> "pass name when they should not" callsites, so I didn't
> want to put in too much work before finding out if we
> had agreement on this as a naming convention.
> 
> There are definitely more buses that can be cleaned up
> to follow the init vs new convention, but this series is
> already touching 70 files and trying to do every bus in
> one series seems like a recipe for merge conflicts.
> So this seemed like enough to be going on with...
> 
> thanks
> -- PMM
> 
> Peter Maydell (6):
>    scsi: Replace scsi_bus_new() with scsi_bus_init(),
>      scsi_bus_init_named()
>    ipack: Rename ipack_bus_new_inplace() to ipack_bus_init()
>    pci: Rename pci_root_bus_new_inplace() to pci_root_bus_init()
>    qbus: Rename qbus_create_inplace() to qbus_init()
>    qbus: Rename qbus_create() to qbus_new()
>    ide: Rename ide_bus_new() to ide_bus_init()

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 0/6] Improve consistency of bus init function names
  2021-09-23 12:11 [PATCH 0/6] Improve consistency of bus init function names Peter Maydell
                   ` (6 preceding siblings ...)
  2021-09-23 13:36 ` [PATCH 0/6] Improve consistency of bus init function names Philippe Mathieu-Daudé
@ 2021-09-23 15:38 ` Michael S. Tsirkin
  2021-09-30  9:39 ` Peter Maydell
  8 siblings, 0 replies; 13+ messages in thread
From: Michael S. Tsirkin @ 2021-09-23 15:38 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Fam Zheng, Alberto Garcia, Eduardo Habkost, qemu-devel,
	Markus Armbruster, Daniel P. Berrange, Paolo Bonzini, John Snow

On Thu, Sep 23, 2021 at 01:11:47PM +0100, Peter Maydell wrote:
> Currently we have a bit of a mishmash of different function
> names for bus creation. There are two basic patterns: you
> can have a function that allocates and returns a new bus
> object; or you can have a function that takes a pointer to
> a bus object and initializes it in-place. We have to some
> extent a convention for those: the allocate-and-return
> function is 'foo_new()', and the 'init in-place' function
> is 'foo_init()'. However many of our bus creation functions
> don't follow that; some use 'foo_new' vs 'foo_new_inplace';
> some use 'foo_new' for the in-place init version; and
> the bottom level qbus functions are 'qbus_create' vs
> 'qbus_create_inplace'. This series tries to bring at least
> scsi, ipack, pci, ide, and qbus into line with the
> _new-vs-_init naming convention.
> 
> The other issue with bus creation functions is that some
> of them take a 'name' argument which can be NULL, and some
> do not. Generally "pass in a specific name" should be the
> rare case, but our API design here is easy to misuse, and
> so a lot of callsites (especially for i2c, sd, ssi) pass
> in names when they should not. Untangling that mess is
> going to be tricky (see other thread for more), but as
> a first step, this series proposes a split between
> foo_bus_new() and foo_bus_new_named() where the latter
> takes a name parameter and the former does not. I do
> this only for scsi (and implicitly ide, whose ide_bus_new
> function already doesn't take a name argument) for the
> moment, as the other bus types have more of a mess of
> "pass name when they should not" callsites, so I didn't
> want to put in too much work before finding out if we
> had agreement on this as a naming convention.
> 
> There are definitely more buses that can be cleaned up
> to follow the init vs new convention, but this series is
> already touching 70 files and trying to do every bus in
> one series seems like a recipe for merge conflicts.
> So this seemed like enough to be going on with...
> 
> thanks
> -- PMM


pci:

Reviewed-by: Michael S. Tsirkin <mst@redhat.com>

feel free to merge.

> Peter Maydell (6):
>   scsi: Replace scsi_bus_new() with scsi_bus_init(),
>     scsi_bus_init_named()
>   ipack: Rename ipack_bus_new_inplace() to ipack_bus_init()
>   pci: Rename pci_root_bus_new_inplace() to pci_root_bus_init()
>   qbus: Rename qbus_create_inplace() to qbus_init()
>   qbus: Rename qbus_create() to qbus_new()
>   ide: Rename ide_bus_new() to ide_bus_init()
> 
>  include/hw/ide/internal.h     |  4 ++--
>  include/hw/ipack/ipack.h      |  8 ++++----
>  include/hw/pci/pci.h          | 10 +++++-----
>  include/hw/qdev-core.h        |  6 +++---
>  include/hw/scsi/scsi.h        | 30 ++++++++++++++++++++++++++++--
>  hw/audio/intel-hda.c          |  2 +-
>  hw/block/fdc.c                |  2 +-
>  hw/block/swim.c               |  3 +--
>  hw/char/virtio-serial-bus.c   |  4 ++--
>  hw/core/bus.c                 | 13 +++++++------
>  hw/core/sysbus.c              | 10 ++++++----
>  hw/gpio/bcm2835_gpio.c        |  3 +--
>  hw/hyperv/vmbus.c             |  2 +-
>  hw/i2c/core.c                 |  2 +-
>  hw/ide/ahci.c                 |  2 +-
>  hw/ide/cmd646.c               |  2 +-
>  hw/ide/isa.c                  |  2 +-
>  hw/ide/macio.c                |  2 +-
>  hw/ide/microdrive.c           |  2 +-
>  hw/ide/mmio.c                 |  2 +-
>  hw/ide/piix.c                 |  2 +-
>  hw/ide/qdev.c                 |  4 ++--
>  hw/ide/sii3112.c              |  2 +-
>  hw/ide/via.c                  |  2 +-
>  hw/ipack/ipack.c              | 10 +++++-----
>  hw/ipack/tpci200.c            |  4 ++--
>  hw/isa/isa-bus.c              |  2 +-
>  hw/misc/auxbus.c              |  2 +-
>  hw/misc/mac_via.c             |  4 ++--
>  hw/misc/macio/cuda.c          |  4 ++--
>  hw/misc/macio/macio.c         |  4 ++--
>  hw/misc/macio/pmu.c           |  4 ++--
>  hw/nubus/mac-nubus-bridge.c   |  2 +-
>  hw/nvme/ctrl.c                |  4 ++--
>  hw/nvme/subsys.c              |  3 +--
>  hw/pci-host/raven.c           |  4 ++--
>  hw/pci-host/versatile.c       |  6 +++---
>  hw/pci/pci.c                  | 30 +++++++++++++++---------------
>  hw/pci/pci_bridge.c           |  4 ++--
>  hw/ppc/spapr_vio.c            |  2 +-
>  hw/s390x/ap-bridge.c          |  2 +-
>  hw/s390x/css-bridge.c         |  2 +-
>  hw/s390x/event-facility.c     |  4 ++--
>  hw/s390x/s390-pci-bus.c       |  2 +-
>  hw/s390x/virtio-ccw.c         |  3 +--
>  hw/scsi/esp-pci.c             |  2 +-
>  hw/scsi/esp.c                 |  2 +-
>  hw/scsi/lsi53c895a.c          |  2 +-
>  hw/scsi/megasas.c             |  3 +--
>  hw/scsi/mptsas.c              |  2 +-
>  hw/scsi/scsi-bus.c            |  6 +++---
>  hw/scsi/spapr_vscsi.c         |  3 +--
>  hw/scsi/virtio-scsi.c         |  4 ++--
>  hw/scsi/vmw_pvscsi.c          |  3 +--
>  hw/sd/allwinner-sdhost.c      |  4 ++--
>  hw/sd/bcm2835_sdhost.c        |  4 ++--
>  hw/sd/pl181.c                 |  3 +--
>  hw/sd/pxa2xx_mmci.c           |  4 ++--
>  hw/sd/sdhci.c                 |  3 +--
>  hw/sd/ssi-sd.c                |  3 +--
>  hw/ssi/ssi.c                  |  2 +-
>  hw/usb/bus.c                  |  2 +-
>  hw/usb/dev-smartcard-reader.c |  3 +--
>  hw/usb/dev-storage-bot.c      |  3 +--
>  hw/usb/dev-storage-classic.c  |  4 ++--
>  hw/usb/dev-uas.c              |  3 +--
>  hw/virtio/virtio-mmio.c       |  3 +--
>  hw/virtio/virtio-pci.c        |  3 +--
>  hw/xen/xen-bus.c              |  2 +-
>  hw/xen/xen-legacy-backend.c   |  2 +-
>  70 files changed, 156 insertions(+), 142 deletions(-)
> 
> -- 
> 2.20.1



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 5/6] qbus: Rename qbus_create() to qbus_new()
  2021-09-23 12:11 ` [PATCH 5/6] qbus: Rename qbus_create() to qbus_new() Peter Maydell
@ 2021-09-23 16:00   ` Corey Minyard
  0 siblings, 0 replies; 13+ messages in thread
From: Corey Minyard @ 2021-09-23 16:00 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Fam Zheng, Daniel P. Berrange, Eduardo Habkost,
	Michael S . Tsirkin, qemu-devel, Markus Armbruster,
	Paolo Bonzini, Alberto Garcia, John Snow

On Thu, Sep 23, 2021 at 01:11:52PM +0100, Peter Maydell wrote:
> Rename the "allocate and return" qbus creation function to
> qbus_new(), to bring it into line with our _init vs _new convention.

This looks like a good idea to me.

Reviewed-by: Corey Minyard <cminyard@mvista.com>

> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  include/hw/qdev-core.h      | 2 +-
>  hw/core/bus.c               | 2 +-
>  hw/hyperv/vmbus.c           | 2 +-
>  hw/i2c/core.c               | 2 +-
>  hw/isa/isa-bus.c            | 2 +-
>  hw/misc/auxbus.c            | 2 +-
>  hw/nubus/mac-nubus-bridge.c | 2 +-
>  hw/pci/pci.c                | 2 +-
>  hw/ppc/spapr_vio.c          | 2 +-
>  hw/s390x/ap-bridge.c        | 2 +-
>  hw/s390x/css-bridge.c       | 2 +-
>  hw/s390x/s390-pci-bus.c     | 2 +-
>  hw/ssi/ssi.c                | 2 +-
>  hw/xen/xen-bus.c            | 2 +-
>  hw/xen/xen-legacy-backend.c | 2 +-
>  15 files changed, 15 insertions(+), 15 deletions(-)
> 
> diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
> index ebca8cf9fca..4ff19c714bd 100644
> --- a/include/hw/qdev-core.h
> +++ b/include/hw/qdev-core.h
> @@ -680,7 +680,7 @@ typedef int (qdev_walkerfn)(DeviceState *dev, void *opaque);
>  
>  void qbus_init(void *bus, size_t size, const char *typename,
>                 DeviceState *parent, const char *name);
> -BusState *qbus_create(const char *typename, DeviceState *parent, const char *name);
> +BusState *qbus_new(const char *typename, DeviceState *parent, const char *name);
>  bool qbus_realize(BusState *bus, Error **errp);
>  void qbus_unrealize(BusState *bus);
>  
> diff --git a/hw/core/bus.c b/hw/core/bus.c
> index cec49985024..c7831b5293b 100644
> --- a/hw/core/bus.c
> +++ b/hw/core/bus.c
> @@ -159,7 +159,7 @@ void qbus_init(void *bus, size_t size, const char *typename,
>      qbus_init_internal(bus, parent, name);
>  }
>  
> -BusState *qbus_create(const char *typename, DeviceState *parent, const char *name)
> +BusState *qbus_new(const char *typename, DeviceState *parent, const char *name)
>  {
>      BusState *bus;
>  
> diff --git a/hw/hyperv/vmbus.c b/hw/hyperv/vmbus.c
> index c9887d5a7bc..dbce3b35fba 100644
> --- a/hw/hyperv/vmbus.c
> +++ b/hw/hyperv/vmbus.c
> @@ -2729,7 +2729,7 @@ static void vmbus_bridge_realize(DeviceState *dev, Error **errp)
>          return;
>      }
>  
> -    bridge->bus = VMBUS(qbus_create(TYPE_VMBUS, dev, "vmbus"));
> +    bridge->bus = VMBUS(qbus_new(TYPE_VMBUS, dev, "vmbus"));
>  }
>  
>  static char *vmbus_bridge_ofw_unit_address(const SysBusDevice *dev)
> diff --git a/hw/i2c/core.c b/hw/i2c/core.c
> index 416372ad00c..0e7d2763b9e 100644
> --- a/hw/i2c/core.c
> +++ b/hw/i2c/core.c
> @@ -60,7 +60,7 @@ I2CBus *i2c_init_bus(DeviceState *parent, const char *name)
>  {
>      I2CBus *bus;
>  
> -    bus = I2C_BUS(qbus_create(TYPE_I2C_BUS, parent, name));
> +    bus = I2C_BUS(qbus_new(TYPE_I2C_BUS, parent, name));
>      QLIST_INIT(&bus->current_devs);
>      vmstate_register(NULL, VMSTATE_INSTANCE_ID_ANY, &vmstate_i2c_bus, bus);
>      return bus;
> diff --git a/hw/isa/isa-bus.c b/hw/isa/isa-bus.c
> index cffaa35e9cf..6c31398dda6 100644
> --- a/hw/isa/isa-bus.c
> +++ b/hw/isa/isa-bus.c
> @@ -64,7 +64,7 @@ ISABus *isa_bus_new(DeviceState *dev, MemoryRegion* address_space,
>          sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
>      }
>  
> -    isabus = ISA_BUS(qbus_create(TYPE_ISA_BUS, dev, NULL));
> +    isabus = ISA_BUS(qbus_new(TYPE_ISA_BUS, dev, NULL));
>      isabus->address_space = address_space;
>      isabus->address_space_io = address_space_io;
>      return isabus;
> diff --git a/hw/misc/auxbus.c b/hw/misc/auxbus.c
> index 434ff8d910d..8a8012f5f08 100644
> --- a/hw/misc/auxbus.c
> +++ b/hw/misc/auxbus.c
> @@ -65,7 +65,7 @@ AUXBus *aux_bus_init(DeviceState *parent, const char *name)
>      AUXBus *bus;
>      Object *auxtoi2c;
>  
> -    bus = AUX_BUS(qbus_create(TYPE_AUX_BUS, parent, name));
> +    bus = AUX_BUS(qbus_new(TYPE_AUX_BUS, parent, name));
>      auxtoi2c = object_new_with_props(TYPE_AUXTOI2C, OBJECT(bus), "i2c",
>                                       &error_abort, NULL);
>  
> diff --git a/hw/nubus/mac-nubus-bridge.c b/hw/nubus/mac-nubus-bridge.c
> index 7c329300b82..148979dab13 100644
> --- a/hw/nubus/mac-nubus-bridge.c
> +++ b/hw/nubus/mac-nubus-bridge.c
> @@ -16,7 +16,7 @@ static void mac_nubus_bridge_init(Object *obj)
>      MacNubusState *s = MAC_NUBUS_BRIDGE(obj);
>      SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
>  
> -    s->bus = NUBUS_BUS(qbus_create(TYPE_NUBUS_BUS, DEVICE(s), NULL));
> +    s->bus = NUBUS_BUS(qbus_new(TYPE_NUBUS_BUS, DEVICE(s), NULL));
>  
>      sysbus_init_mmio(sbd, &s->bus->super_slot_io);
>      sysbus_init_mmio(sbd, &s->bus->slot_io);
> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> index 14cb15a0aa1..186758ee11f 100644
> --- a/hw/pci/pci.c
> +++ b/hw/pci/pci.c
> @@ -478,7 +478,7 @@ PCIBus *pci_root_bus_new(DeviceState *parent, const char *name,
>  {
>      PCIBus *bus;
>  
> -    bus = PCI_BUS(qbus_create(typename, parent, name));
> +    bus = PCI_BUS(qbus_new(typename, parent, name));
>      pci_root_bus_internal_init(bus, parent, address_space_mem,
>                                 address_space_io, devfn_min);
>      return bus;
> diff --git a/hw/ppc/spapr_vio.c b/hw/ppc/spapr_vio.c
> index b59452bcd62..b975ed29cad 100644
> --- a/hw/ppc/spapr_vio.c
> +++ b/hw/ppc/spapr_vio.c
> @@ -577,7 +577,7 @@ SpaprVioBus *spapr_vio_bus_init(void)
>      sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
>  
>      /* Create bus on bridge device */
> -    qbus = qbus_create(TYPE_SPAPR_VIO_BUS, dev, "spapr-vio");
> +    qbus = qbus_new(TYPE_SPAPR_VIO_BUS, dev, "spapr-vio");
>      bus = SPAPR_VIO_BUS(qbus);
>      bus->next_reg = SPAPR_VIO_REG_BASE;
>  
> diff --git a/hw/s390x/ap-bridge.c b/hw/s390x/ap-bridge.c
> index 8bcf8ece9dd..ef8fa2b15be 100644
> --- a/hw/s390x/ap-bridge.c
> +++ b/hw/s390x/ap-bridge.c
> @@ -55,7 +55,7 @@ void s390_init_ap(void)
>      sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
>  
>      /* Create bus on bridge device */
> -    bus = qbus_create(TYPE_AP_BUS, dev, TYPE_AP_BUS);
> +    bus = qbus_new(TYPE_AP_BUS, dev, TYPE_AP_BUS);
>  
>      /* Enable hotplugging */
>      qbus_set_hotplug_handler(bus, OBJECT(dev));
> diff --git a/hw/s390x/css-bridge.c b/hw/s390x/css-bridge.c
> index 191b29f0771..4017081d49c 100644
> --- a/hw/s390x/css-bridge.c
> +++ b/hw/s390x/css-bridge.c
> @@ -106,7 +106,7 @@ VirtualCssBus *virtual_css_bus_init(void)
>      sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
>  
>      /* Create bus on bridge device */
> -    bus = qbus_create(TYPE_VIRTUAL_CSS_BUS, dev, "virtual-css");
> +    bus = qbus_new(TYPE_VIRTUAL_CSS_BUS, dev, "virtual-css");
>      cbus = VIRTUAL_CSS_BUS(bus);
>  
>      /* Enable hotplugging */
> diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
> index 6c0225c3a01..6fafffb029a 100644
> --- a/hw/s390x/s390-pci-bus.c
> +++ b/hw/s390x/s390-pci-bus.c
> @@ -813,7 +813,7 @@ static void s390_pcihost_realize(DeviceState *dev, Error **errp)
>      qbus_set_hotplug_handler(bus, OBJECT(dev));
>      phb->bus = b;
>  
> -    s->bus = S390_PCI_BUS(qbus_create(TYPE_S390_PCI_BUS, dev, NULL));
> +    s->bus = S390_PCI_BUS(qbus_new(TYPE_S390_PCI_BUS, dev, NULL));
>      qbus_set_hotplug_handler(BUS(s->bus), OBJECT(dev));
>  
>      s->iommu_table = g_hash_table_new_full(g_int64_hash, g_int64_equal,
> diff --git a/hw/ssi/ssi.c b/hw/ssi/ssi.c
> index e5d7ce95237..003931fb509 100644
> --- a/hw/ssi/ssi.c
> +++ b/hw/ssi/ssi.c
> @@ -107,7 +107,7 @@ DeviceState *ssi_create_peripheral(SSIBus *bus, const char *name)
>  SSIBus *ssi_create_bus(DeviceState *parent, const char *name)
>  {
>      BusState *bus;
> -    bus = qbus_create(TYPE_SSI_BUS, parent, name);
> +    bus = qbus_new(TYPE_SSI_BUS, parent, name);
>      return SSI_BUS(bus);
>  }
>  
> diff --git a/hw/xen/xen-bus.c b/hw/xen/xen-bus.c
> index 8c588920d9f..416583f130b 100644
> --- a/hw/xen/xen-bus.c
> +++ b/hw/xen/xen-bus.c
> @@ -1398,7 +1398,7 @@ type_init(xen_register_types)
>  void xen_bus_init(void)
>  {
>      DeviceState *dev = qdev_new(TYPE_XEN_BRIDGE);
> -    BusState *bus = qbus_create(TYPE_XEN_BUS, dev, NULL);
> +    BusState *bus = qbus_new(TYPE_XEN_BUS, dev, NULL);
>  
>      sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
>      qbus_set_bus_hotplug_handler(bus);
> diff --git a/hw/xen/xen-legacy-backend.c b/hw/xen/xen-legacy-backend.c
> index dd8ae1452d1..be3cf4a195e 100644
> --- a/hw/xen/xen-legacy-backend.c
> +++ b/hw/xen/xen-legacy-backend.c
> @@ -702,7 +702,7 @@ int xen_be_init(void)
>  
>      xen_sysdev = qdev_new(TYPE_XENSYSDEV);
>      sysbus_realize_and_unref(SYS_BUS_DEVICE(xen_sysdev), &error_fatal);
> -    xen_sysbus = qbus_create(TYPE_XENSYSBUS, xen_sysdev, "xen-sysbus");
> +    xen_sysbus = qbus_new(TYPE_XENSYSBUS, xen_sysdev, "xen-sysbus");
>      qbus_set_bus_hotplug_handler(xen_sysbus);
>  
>      return 0;
> -- 
> 2.20.1
> 
> 


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 6/6] ide: Rename ide_bus_new() to ide_bus_init()
  2021-09-23 12:11 ` [PATCH 6/6] ide: Rename ide_bus_new() to ide_bus_init() Peter Maydell
@ 2021-09-23 18:26   ` John Snow
  0 siblings, 0 replies; 13+ messages in thread
From: John Snow @ 2021-09-23 18:26 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Fam Zheng, Alberto Garcia, Eduardo Habkost, Michael S . Tsirkin,
	qemu-devel, Markus Armbruster, Daniel P. Berrange, Paolo Bonzini

[-- Attachment #1: Type: text/plain, Size: 6817 bytes --]

On Thu, Sep 23, 2021 at 8:12 AM Peter Maydell <peter.maydell@linaro.org>
wrote:

> The function ide_bus_new() does an in-place initialization.  Rename
> it to ide_bus_init() to follow our _init vs _new convention.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  include/hw/ide/internal.h | 4 ++--
>  hw/ide/ahci.c             | 2 +-
>  hw/ide/cmd646.c           | 2 +-
>  hw/ide/isa.c              | 2 +-
>  hw/ide/macio.c            | 2 +-
>  hw/ide/microdrive.c       | 2 +-
>  hw/ide/mmio.c             | 2 +-
>  hw/ide/piix.c             | 2 +-
>  hw/ide/qdev.c             | 2 +-
>  hw/ide/sii3112.c          | 2 +-
>  hw/ide/via.c              | 2 +-
>  11 files changed, 12 insertions(+), 12 deletions(-)
>
> diff --git a/include/hw/ide/internal.h b/include/hw/ide/internal.h
> index 79172217ccb..97e7e59dc58 100644
> --- a/include/hw/ide/internal.h
> +++ b/include/hw/ide/internal.h
> @@ -648,8 +648,8 @@ void ide_atapi_cmd(IDEState *s);
>  void ide_atapi_cmd_reply_end(IDEState *s);
>
>  /* hw/ide/qdev.c */
> -void ide_bus_new(IDEBus *idebus, size_t idebus_size, DeviceState *dev,
> -                 int bus_id, int max_units);
> +void ide_bus_init(IDEBus *idebus, size_t idebus_size, DeviceState *dev,
> +                  int bus_id, int max_units);
>  IDEDevice *ide_create_drive(IDEBus *bus, int unit, DriveInfo *drive);
>
>  int ide_handle_rw_error(IDEState *s, int error, int op);
> diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
> index f2c51574839..a94c6e26fb0 100644
> --- a/hw/ide/ahci.c
> +++ b/hw/ide/ahci.c
> @@ -1548,7 +1548,7 @@ void ahci_realize(AHCIState *s, DeviceState *qdev,
> AddressSpace *as, int ports)
>      for (i = 0; i < s->ports; i++) {
>          AHCIDevice *ad = &s->dev[i];
>
> -        ide_bus_new(&ad->port, sizeof(ad->port), qdev, i, 1);
> +        ide_bus_init(&ad->port, sizeof(ad->port), qdev, i, 1);
>          ide_init2(&ad->port, irqs[i]);
>
>          ad->hba = s;
> diff --git a/hw/ide/cmd646.c b/hw/ide/cmd646.c
> index c2546314855..94c576262c1 100644
> --- a/hw/ide/cmd646.c
> +++ b/hw/ide/cmd646.c
> @@ -293,7 +293,7 @@ static void pci_cmd646_ide_realize(PCIDevice *dev,
> Error **errp)
>
>      qdev_init_gpio_in(ds, cmd646_set_irq, 2);
>      for (i = 0; i < 2; i++) {
> -        ide_bus_new(&d->bus[i], sizeof(d->bus[i]), ds, i, 2);
> +        ide_bus_init(&d->bus[i], sizeof(d->bus[i]), ds, i, 2);
>          ide_init2(&d->bus[i], qdev_get_gpio_in(ds, i));
>
>          bmdma_init(&d->bus[i], &d->bmdma[i], d);
> diff --git a/hw/ide/isa.c b/hw/ide/isa.c
> index 6bc19de2265..24bbde24c2b 100644
> --- a/hw/ide/isa.c
> +++ b/hw/ide/isa.c
> @@ -73,7 +73,7 @@ static void isa_ide_realizefn(DeviceState *dev, Error
> **errp)
>      ISADevice *isadev = ISA_DEVICE(dev);
>      ISAIDEState *s = ISA_IDE(dev);
>
> -    ide_bus_new(&s->bus, sizeof(s->bus), dev, 0, 2);
> +    ide_bus_init(&s->bus, sizeof(s->bus), dev, 0, 2);
>      ide_init_ioport(&s->bus, isadev, s->iobase, s->iobase2);
>      isa_init_irq(isadev, &s->irq, s->isairq);
>      ide_init2(&s->bus, s->irq);
> diff --git a/hw/ide/macio.c b/hw/ide/macio.c
> index b270a101632..b03d401ceb5 100644
> --- a/hw/ide/macio.c
> +++ b/hw/ide/macio.c
> @@ -449,7 +449,7 @@ static void macio_ide_initfn(Object *obj)
>      SysBusDevice *d = SYS_BUS_DEVICE(obj);
>      MACIOIDEState *s = MACIO_IDE(obj);
>
> -    ide_bus_new(&s->bus, sizeof(s->bus), DEVICE(obj), 0, 2);
> +    ide_bus_init(&s->bus, sizeof(s->bus), DEVICE(obj), 0, 2);
>      memory_region_init_io(&s->mem, obj, &pmac_ide_ops, s, "pmac-ide",
> 0x1000);
>      sysbus_init_mmio(d, &s->mem);
>      sysbus_init_irq(d, &s->real_ide_irq);
> diff --git a/hw/ide/microdrive.c b/hw/ide/microdrive.c
> index 58a14fea363..6df9b4cbbe1 100644
> --- a/hw/ide/microdrive.c
> +++ b/hw/ide/microdrive.c
> @@ -605,7 +605,7 @@ static void microdrive_init(Object *obj)
>  {
>      MicroDriveState *md = MICRODRIVE(obj);
>
> -    ide_bus_new(&md->bus, sizeof(md->bus), DEVICE(obj), 0, 1);
> +    ide_bus_init(&md->bus, sizeof(md->bus), DEVICE(obj), 0, 1);
>  }
>
>  static void microdrive_class_init(ObjectClass *oc, void *data)
> diff --git a/hw/ide/mmio.c b/hw/ide/mmio.c
> index 36e2f4790ab..fb2ebd4847f 100644
> --- a/hw/ide/mmio.c
> +++ b/hw/ide/mmio.c
> @@ -142,7 +142,7 @@ static void mmio_ide_initfn(Object *obj)
>      SysBusDevice *d = SYS_BUS_DEVICE(obj);
>      MMIOState *s = MMIO_IDE(obj);
>
> -    ide_bus_new(&s->bus, sizeof(s->bus), DEVICE(obj), 0, 2);
> +    ide_bus_init(&s->bus, sizeof(s->bus), DEVICE(obj), 0, 2);
>      sysbus_init_irq(d, &s->irq);
>  }
>
> diff --git a/hw/ide/piix.c b/hw/ide/piix.c
> index d3e738320be..ce89fd0aa36 100644
> --- a/hw/ide/piix.c
> +++ b/hw/ide/piix.c
> @@ -137,7 +137,7 @@ static int pci_piix_init_ports(PCIIDEState *d)
>      int i, ret;
>
>      for (i = 0; i < 2; i++) {
> -        ide_bus_new(&d->bus[i], sizeof(d->bus[i]), DEVICE(d), i, 2);
> +        ide_bus_init(&d->bus[i], sizeof(d->bus[i]), DEVICE(d), i, 2);
>          ret = ide_init_ioport(&d->bus[i], NULL, port_info[i].iobase,
>                                port_info[i].iobase2);
>          if (ret) {
> diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
> index ca844419106..618045b85ac 100644
> --- a/hw/ide/qdev.c
> +++ b/hw/ide/qdev.c
> @@ -68,7 +68,7 @@ static const TypeInfo ide_bus_info = {
>      .class_init = ide_bus_class_init,
>  };
>
> -void ide_bus_new(IDEBus *idebus, size_t idebus_size, DeviceState *dev,
> +void ide_bus_init(IDEBus *idebus, size_t idebus_size, DeviceState *dev,
>                   int bus_id, int max_units)
>  {
>      qbus_init(idebus, idebus_size, TYPE_IDE_BUS, dev, NULL);
> diff --git a/hw/ide/sii3112.c b/hw/ide/sii3112.c
> index 34c347b9c20..46204f10d75 100644
> --- a/hw/ide/sii3112.c
> +++ b/hw/ide/sii3112.c
> @@ -283,7 +283,7 @@ static void sii3112_pci_realize(PCIDevice *dev, Error
> **errp)
>
>      qdev_init_gpio_in(ds, sii3112_set_irq, 2);
>      for (i = 0; i < 2; i++) {
> -        ide_bus_new(&s->bus[i], sizeof(s->bus[i]), ds, i, 1);
> +        ide_bus_init(&s->bus[i], sizeof(s->bus[i]), ds, i, 1);
>          ide_init2(&s->bus[i], qdev_get_gpio_in(ds, i));
>
>          bmdma_init(&s->bus[i], &s->bmdma[i], s);
> diff --git a/hw/ide/via.c b/hw/ide/via.c
> index be09912b334..94cc2142c70 100644
> --- a/hw/ide/via.c
> +++ b/hw/ide/via.c
> @@ -190,7 +190,7 @@ static void via_ide_realize(PCIDevice *dev, Error
> **errp)
>
>      qdev_init_gpio_in(ds, via_ide_set_irq, 2);
>      for (i = 0; i < 2; i++) {
> -        ide_bus_new(&d->bus[i], sizeof(d->bus[i]), ds, i, 2);
> +        ide_bus_init(&d->bus[i], sizeof(d->bus[i]), ds, i, 2);
>          ide_init2(&d->bus[i], qdev_get_gpio_in(ds, i));
>
>          bmdma_init(&d->bus[i], &d->bmdma[i], d);
> --
> 2.20.1
>
>
Reviewed-by: John Snow <jsnow@redhat.com>
Acked-by: John Snow <jsnow@redhat.com> (Feel free to merge.)

--js

[-- Attachment #2: Type: text/html, Size: 8526 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/6] scsi: Replace scsi_bus_new() with scsi_bus_init(), scsi_bus_init_named()
  2021-09-23 12:11 ` [PATCH 1/6] scsi: Replace scsi_bus_new() with scsi_bus_init(), scsi_bus_init_named() Peter Maydell
@ 2021-09-28 15:12   ` Paolo Bonzini
  0 siblings, 0 replies; 13+ messages in thread
From: Paolo Bonzini @ 2021-09-28 15:12 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel
  Cc: Fam Zheng, Daniel P. Berrange, Eduardo Habkost,
	Michael S . Tsirkin, Markus Armbruster, Alberto Garcia,
	John Snow

On 23/09/21 14:11, Peter Maydell wrote:
> The function scsi_bus_new() creates a new SCSI bus; callers can
> either pass in a name argument to specify the name of the new bus, or
> they can pass in NULL to allow the bus to be given an automatically
> generated unique name.  Almost all callers want to use the
> autogenerated name; the only exception is the virtio-scsi device.
> 
> Taking a name argument that should almost always be NULL is an
> easy-to-misuse API design -- it encourages callers to think perhaps
> they should pass in some standard name like "scsi" or "scsi-bus".  We
> don't do this anywhere for SCSI, but we do (incorrectly) do it for
> other bus types such as i2c.
> 
> The function name also implies that it will return a newly allocated
> object, when it in fact does in-place allocation.  We more commonly
> name such functions foo_init(), with foo_new() being the
> allocate-and-return variant.
> 
> Replace all the scsi_bus_new() callsites with either:
>   * scsi_bus_init() for the usual case where the caller wants
>     an autogenerated bus name
>   * scsi_bus_init_named() for the rare case where the caller
>     needs to specify the bus name
> 
> and document that for the _named() version it's then the caller's
> responsibility to think about uniqueness of bus names.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   include/hw/scsi/scsi.h       | 30 ++++++++++++++++++++++++++++--
>   hw/scsi/esp-pci.c            |  2 +-
>   hw/scsi/esp.c                |  2 +-
>   hw/scsi/lsi53c895a.c         |  2 +-
>   hw/scsi/megasas.c            |  3 +--
>   hw/scsi/mptsas.c             |  2 +-
>   hw/scsi/scsi-bus.c           |  4 ++--
>   hw/scsi/spapr_vscsi.c        |  3 +--
>   hw/scsi/virtio-scsi.c        |  4 ++--
>   hw/scsi/vmw_pvscsi.c         |  3 +--
>   hw/usb/dev-storage-bot.c     |  3 +--
>   hw/usb/dev-storage-classic.c |  4 ++--
>   hw/usb/dev-uas.c             |  3 +--
>   13 files changed, 43 insertions(+), 22 deletions(-)
> 
> diff --git a/include/hw/scsi/scsi.h b/include/hw/scsi/scsi.h
> index 0b726bc78c6..a567a5ed86b 100644
> --- a/include/hw/scsi/scsi.h
> +++ b/include/hw/scsi/scsi.h
> @@ -146,8 +146,34 @@ struct SCSIBus {
>       const SCSIBusInfo *info;
>   };
>   
> -void scsi_bus_new(SCSIBus *bus, size_t bus_size, DeviceState *host,
> -                  const SCSIBusInfo *info, const char *bus_name);
> +/**
> + * scsi_bus_init_named: Initialize a SCSI bus with the specified name
> + * @bus: SCSIBus object to initialize
> + * @bus_size: size of @bus object
> + * @host: Device which owns the bus (generally the SCSI controller)
> + * @info: structure defining callbacks etc for the controller
> + * @bus_name: Name to use for this bus
> + *
> + * This in-place initializes @bus as a new SCSI bus with a name
> + * provided by the caller. It is the caller's responsibility to make
> + * sure that name does not clash with the name of any other bus in the
> + * system. Unless you need the new bus to have a specific name, you
> + * should use scsi_bus_new() instead.
> + */
> +void scsi_bus_init_named(SCSIBus *bus, size_t bus_size, DeviceState *host,
> +                         const SCSIBusInfo *info, const char *bus_name);
> +
> +/**
> + * scsi_bus_init: Initialize a SCSI bus
> + *
> + * This in-place-initializes @bus as a new SCSI bus and gives it
> + * an automatically generated unique name.
> + */
> +static inline void scsi_bus_init(SCSIBus *bus, size_t bus_size,
> +                                 DeviceState *host, const SCSIBusInfo *info)
> +{
> +    scsi_bus_init_named(bus, bus_size, host, info, NULL);
> +}
>   
>   static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d)
>   {
> diff --git a/hw/scsi/esp-pci.c b/hw/scsi/esp-pci.c
> index 9db10b1a487..dac054aeed4 100644
> --- a/hw/scsi/esp-pci.c
> +++ b/hw/scsi/esp-pci.c
> @@ -388,7 +388,7 @@ static void esp_pci_scsi_realize(PCIDevice *dev, Error **errp)
>       pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &pci->io);
>       s->irq = pci_allocate_irq(dev);
>   
> -    scsi_bus_new(&s->bus, sizeof(s->bus), d, &esp_pci_scsi_info, NULL);
> +    scsi_bus_init(&s->bus, sizeof(s->bus), d, &esp_pci_scsi_info);
>   }
>   
>   static void esp_pci_scsi_exit(PCIDevice *d)
> diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c
> index 4ac21147888..8454ed17735 100644
> --- a/hw/scsi/esp.c
> +++ b/hw/scsi/esp.c
> @@ -1348,7 +1348,7 @@ static void sysbus_esp_realize(DeviceState *dev, Error **errp)
>   
>       qdev_init_gpio_in(dev, sysbus_esp_gpio_demux, 2);
>   
> -    scsi_bus_new(&s->bus, sizeof(s->bus), dev, &esp_scsi_info, NULL);
> +    scsi_bus_init(&s->bus, sizeof(s->bus), dev, &esp_scsi_info);
>   }
>   
>   static void sysbus_esp_hard_reset(DeviceState *dev)
> diff --git a/hw/scsi/lsi53c895a.c b/hw/scsi/lsi53c895a.c
> index e2c19180a0d..85e907a7854 100644
> --- a/hw/scsi/lsi53c895a.c
> +++ b/hw/scsi/lsi53c895a.c
> @@ -2309,7 +2309,7 @@ static void lsi_scsi_realize(PCIDevice *dev, Error **errp)
>       pci_register_bar(dev, 2, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->ram_io);
>       QTAILQ_INIT(&s->queue);
>   
> -    scsi_bus_new(&s->bus, sizeof(s->bus), d, &lsi_scsi_info, NULL);
> +    scsi_bus_init(&s->bus, sizeof(s->bus), d, &lsi_scsi_info);
>   }
>   
>   static void lsi_scsi_exit(PCIDevice *dev)
> diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c
> index 8f2389d2c6a..4ff51221d4c 100644
> --- a/hw/scsi/megasas.c
> +++ b/hw/scsi/megasas.c
> @@ -2416,8 +2416,7 @@ static void megasas_scsi_realize(PCIDevice *dev, Error **errp)
>           s->frames[i].state = s;
>       }
>   
> -    scsi_bus_new(&s->bus, sizeof(s->bus), DEVICE(dev),
> -                 &megasas_scsi_info, NULL);
> +    scsi_bus_init(&s->bus, sizeof(s->bus), DEVICE(dev), &megasas_scsi_info);
>   }
>   
>   static Property megasas_properties_gen1[] = {
> diff --git a/hw/scsi/mptsas.c b/hw/scsi/mptsas.c
> index db3219e7d20..f6c77655443 100644
> --- a/hw/scsi/mptsas.c
> +++ b/hw/scsi/mptsas.c
> @@ -1315,7 +1315,7 @@ static void mptsas_scsi_realize(PCIDevice *dev, Error **errp)
>   
>       s->request_bh = qemu_bh_new(mptsas_fetch_requests, s);
>   
> -    scsi_bus_new(&s->bus, sizeof(s->bus), &dev->qdev, &mptsas_scsi_info, NULL);
> +    scsi_bus_init(&s->bus, sizeof(s->bus), &dev->qdev, &mptsas_scsi_info);
>   }
>   
>   static void mptsas_scsi_uninit(PCIDevice *dev)
> diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c
> index 2a0a98cac91..e28a6ea053a 100644
> --- a/hw/scsi/scsi-bus.c
> +++ b/hw/scsi/scsi-bus.c
> @@ -134,8 +134,8 @@ void scsi_device_unit_attention_reported(SCSIDevice *s)
>   }
>   
>   /* Create a scsi bus, and attach devices to it.  */
> -void scsi_bus_new(SCSIBus *bus, size_t bus_size, DeviceState *host,
> -                  const SCSIBusInfo *info, const char *bus_name)
> +void scsi_bus_init_named(SCSIBus *bus, size_t bus_size, DeviceState *host,
> +                         const SCSIBusInfo *info, const char *bus_name)
>   {
>       qbus_create_inplace(bus, bus_size, TYPE_SCSI_BUS, host, bus_name);
>       bus->busnr = next_scsi_bus++;
> diff --git a/hw/scsi/spapr_vscsi.c b/hw/scsi/spapr_vscsi.c
> index c210262484a..a07a8e1523f 100644
> --- a/hw/scsi/spapr_vscsi.c
> +++ b/hw/scsi/spapr_vscsi.c
> @@ -1216,8 +1216,7 @@ static void spapr_vscsi_realize(SpaprVioDevice *dev, Error **errp)
>   
>       dev->crq.SendFunc = vscsi_do_crq;
>   
> -    scsi_bus_new(&s->bus, sizeof(s->bus), DEVICE(dev),
> -                 &vscsi_scsi_info, NULL);
> +    scsi_bus_init(&s->bus, sizeof(s->bus), DEVICE(dev), &vscsi_scsi_info);
>   
>       /* ibmvscsi SCSI bus does not allow hotplug. */
>       qbus_set_hotplug_handler(BUS(&s->bus), NULL);
> diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
> index 6d807302870..51fd09522ac 100644
> --- a/hw/scsi/virtio-scsi.c
> +++ b/hw/scsi/virtio-scsi.c
> @@ -1019,8 +1019,8 @@ static void virtio_scsi_device_realize(DeviceState *dev, Error **errp)
>           return;
>       }
>   
> -    scsi_bus_new(&s->bus, sizeof(s->bus), dev,
> -                 &virtio_scsi_scsi_info, vdev->bus_name);
> +    scsi_bus_init_named(&s->bus, sizeof(s->bus), dev,
> +                       &virtio_scsi_scsi_info, vdev->bus_name);
>       /* override default SCSI bus hotplug-handler, with virtio-scsi's one */
>       qbus_set_hotplug_handler(BUS(&s->bus), OBJECT(dev));
>   
> diff --git a/hw/scsi/vmw_pvscsi.c b/hw/scsi/vmw_pvscsi.c
> index 1f30cb020a1..cd76bd67ab7 100644
> --- a/hw/scsi/vmw_pvscsi.c
> +++ b/hw/scsi/vmw_pvscsi.c
> @@ -1180,8 +1180,7 @@ pvscsi_realizefn(PCIDevice *pci_dev, Error **errp)
>   
>       s->completion_worker = qemu_bh_new(pvscsi_process_completion_queue, s);
>   
> -    scsi_bus_new(&s->bus, sizeof(s->bus), DEVICE(pci_dev),
> -                 &pvscsi_scsi_info, NULL);
> +    scsi_bus_init(&s->bus, sizeof(s->bus), DEVICE(pci_dev), &pvscsi_scsi_info);
>       /* override default SCSI bus hotplug-handler, with pvscsi's one */
>       qbus_set_hotplug_handler(BUS(&s->bus), OBJECT(s));
>       pvscsi_reset_state(s);
> diff --git a/hw/usb/dev-storage-bot.c b/hw/usb/dev-storage-bot.c
> index 68ebaca10c6..b24b3148c28 100644
> --- a/hw/usb/dev-storage-bot.c
> +++ b/hw/usb/dev-storage-bot.c
> @@ -37,8 +37,7 @@ static void usb_msd_bot_realize(USBDevice *dev, Error **errp)
>           s->dev.auto_attach = 0;
>       }
>   
> -    scsi_bus_new(&s->bus, sizeof(s->bus), DEVICE(dev),
> -                 &usb_msd_scsi_info_bot, NULL);
> +    scsi_bus_init(&s->bus, sizeof(s->bus), DEVICE(dev), &usb_msd_scsi_info_bot);
>       usb_msd_handle_reset(dev);
>   }
>   
> diff --git a/hw/usb/dev-storage-classic.c b/hw/usb/dev-storage-classic.c
> index 3d017a4e679..00f25bade28 100644
> --- a/hw/usb/dev-storage-classic.c
> +++ b/hw/usb/dev-storage-classic.c
> @@ -65,8 +65,8 @@ static void usb_msd_storage_realize(USBDevice *dev, Error **errp)
>       usb_desc_create_serial(dev);
>       usb_desc_init(dev);
>       dev->flags |= (1 << USB_DEV_FLAG_IS_SCSI_STORAGE);
> -    scsi_bus_new(&s->bus, sizeof(s->bus), DEVICE(dev),
> -                 &usb_msd_scsi_info_storage, NULL);
> +    scsi_bus_init(&s->bus, sizeof(s->bus), DEVICE(dev),
> +                 &usb_msd_scsi_info_storage);
>       scsi_dev = scsi_bus_legacy_add_drive(&s->bus, blk, 0, !!s->removable,
>                                            s->conf.bootindex, s->conf.share_rw,
>                                            s->conf.rerror, s->conf.werror,
> diff --git a/hw/usb/dev-uas.c b/hw/usb/dev-uas.c
> index f6309a5ebfd..599d6b52a01 100644
> --- a/hw/usb/dev-uas.c
> +++ b/hw/usb/dev-uas.c
> @@ -938,8 +938,7 @@ static void usb_uas_realize(USBDevice *dev, Error **errp)
>       uas->status_bh = qemu_bh_new(usb_uas_send_status_bh, uas);
>   
>       dev->flags |= (1 << USB_DEV_FLAG_IS_SCSI_STORAGE);
> -    scsi_bus_new(&uas->bus, sizeof(uas->bus), DEVICE(dev),
> -                 &usb_uas_scsi_info, NULL);
> +    scsi_bus_init(&uas->bus, sizeof(uas->bus), DEVICE(dev), &usb_uas_scsi_info);
>   }
>   
>   static const VMStateDescription vmstate_usb_uas = {
> 

Acked-by: Paolo Bonzini <pbonzini@redhat.com>

Thanks,

Paolo



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 0/6] Improve consistency of bus init function names
  2021-09-23 12:11 [PATCH 0/6] Improve consistency of bus init function names Peter Maydell
                   ` (7 preceding siblings ...)
  2021-09-23 15:38 ` Michael S. Tsirkin
@ 2021-09-30  9:39 ` Peter Maydell
  8 siblings, 0 replies; 13+ messages in thread
From: Peter Maydell @ 2021-09-30  9:39 UTC (permalink / raw)
  To: QEMU Developers
  Cc: Fam Zheng, Alberto Garcia, Eduardo Habkost, Michael S . Tsirkin,
	Daniel P. Berrange, Markus Armbruster, Paolo Bonzini, John Snow

On Thu, 23 Sept 2021 at 13:11, Peter Maydell <peter.maydell@linaro.org> wrote:
>
> Currently we have a bit of a mishmash of different function
> names for bus creation. There are two basic patterns: you
> can have a function that allocates and returns a new bus
> object; or you can have a function that takes a pointer to
> a bus object and initializes it in-place. We have to some
> extent a convention for those: the allocate-and-return
> function is 'foo_new()', and the 'init in-place' function
> is 'foo_init()'. However many of our bus creation functions
> don't follow that; some use 'foo_new' vs 'foo_new_inplace';
> some use 'foo_new' for the in-place init version; and
> the bottom level qbus functions are 'qbus_create' vs
> 'qbus_create_inplace'. This series tries to bring at least
> scsi, ipack, pci, ide, and qbus into line with the
> _new-vs-_init naming convention.

Thanks all for the reviews/acks. I'm going to take this via
target-arm.next.

-- PMM


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2021-09-30  9:44 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-23 12:11 [PATCH 0/6] Improve consistency of bus init function names Peter Maydell
2021-09-23 12:11 ` [PATCH 1/6] scsi: Replace scsi_bus_new() with scsi_bus_init(), scsi_bus_init_named() Peter Maydell
2021-09-28 15:12   ` Paolo Bonzini
2021-09-23 12:11 ` [PATCH 2/6] ipack: Rename ipack_bus_new_inplace() to ipack_bus_init() Peter Maydell
2021-09-23 12:11 ` [PATCH 3/6] pci: Rename pci_root_bus_new_inplace() to pci_root_bus_init() Peter Maydell
2021-09-23 12:11 ` [PATCH 4/6] qbus: Rename qbus_create_inplace() to qbus_init() Peter Maydell
2021-09-23 12:11 ` [PATCH 5/6] qbus: Rename qbus_create() to qbus_new() Peter Maydell
2021-09-23 16:00   ` Corey Minyard
2021-09-23 12:11 ` [PATCH 6/6] ide: Rename ide_bus_new() to ide_bus_init() Peter Maydell
2021-09-23 18:26   ` John Snow
2021-09-23 13:36 ` [PATCH 0/6] Improve consistency of bus init function names Philippe Mathieu-Daudé
2021-09-23 15:38 ` Michael S. Tsirkin
2021-09-30  9:39 ` Peter Maydell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).