@samitouri / QOSamiQemu / commits / b3b845f762

qdev-monitor: make print_dev() callback take MonitorHMP

The callback is specific to HMP context, avoid unsafe MONITOR_HMP() cast. Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-ID: <20260828-qemu-no-hmp-v5-39-9227de146347@redhat.com>

Marc-André Lureau committed Aug 28, 2026 at 16:04 UTC b3b845f762d75b03dfbdb99def99ddd152aa4c9e
9 files changed +18 -23
hw/char/virtio-serial-bus.c
+3 -3
@@ -814,7 +814,7 @@ static int virtio_serial_load_device(VirtIODevice *vdev, QEMUFile *f,
814 return 0;
815 }
816
817 -static void virtser_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent);
817 +static void virtser_bus_dev_print(MonitorHMP *hmp, DeviceState *qdev, int indent);
818
819 static const Property virtser_props[] = {
820 DEFINE_PROP_UINT32("nr", VirtIOSerialPort, id, VIRTIO_CONSOLE_BAD_ID),
@@ -834,11 +834,11 @@ static const TypeInfo virtser_bus_info = {
834 .class_init = virtser_bus_class_init,
835 };
836
837 -static void virtser_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent)
837 +static void virtser_bus_dev_print(MonitorHMP *hmp, DeviceState *qdev, int indent)
838 {
839 VirtIOSerialPort *port = VIRTIO_SERIAL_PORT(qdev);
840
841 - monitor_hmp_printf(MONITOR_HMP(mon), "%*sport %d, guest %s, host %s, throttle %s\n",
841 + monitor_hmp_printf(hmp, "%*sport %d, guest %s, host %s, throttle %s\n",
842 indent, "", port->id,
843 port->guest_connected ? "on" : "off",
844 port->host_connected ? "on" : "off",
hw/core/sysbus.c
+2 -3
@@ -24,7 +24,7 @@
24 #include "monitor/hmp.h"
25 #include "system/address-spaces.h"
26
27 -static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent);
27 +static void sysbus_dev_print(MonitorHMP *hmp, DeviceState *dev, int indent);
28 static char *sysbus_get_fw_dev_path(DeviceState *dev);
29
30 typedef struct SysBusFind {
@@ -249,10 +249,9 @@ bool sysbus_realize_and_unref(SysBusDevice *dev, Error **errp)
249 return qdev_realize_and_unref(DEVICE(dev), sysbus_get_default(), errp);
250 }
251
252 -static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent)
252 +static void sysbus_dev_print(MonitorHMP *hmp, DeviceState *dev, int indent)
253 {
254 SysBusDevice *s = SYS_BUS_DEVICE(dev);
255 - MonitorHMP *hmp = MONITOR_HMP(mon);
255 hwaddr size;
256 int i;
257
hw/misc/auxbus.c
+3 -4
@@ -47,7 +47,7 @@
47 } while (0)
48
49
50 -static void aux_slave_dev_print(Monitor *mon, DeviceState *dev, int indent);
50 +static void aux_slave_dev_print(MonitorHMP *hmp, DeviceState *dev, int indent);
51 static inline I2CBus *aux_bridge_get_i2c_bus(AUXTOI2CState *bridge);
52
53 /* aux-bus implementation (internal not public) */
@@ -288,7 +288,7 @@ static const TypeInfo aux_to_i2c_type_info = {
288 };
289
290 /* aux-slave implementation */
291 -static void aux_slave_dev_print(Monitor *mon, DeviceState *dev, int indent)
291 +static void aux_slave_dev_print(MonitorHMP *hmp, DeviceState *dev, int indent)
292 {
293 AUXBus *bus = AUX_BUS(qdev_get_parent_bus(dev));
294 AUXSlave *s;
@@ -300,8 +300,7 @@ static void aux_slave_dev_print(Monitor *mon, DeviceState *dev, int indent)
300
301 s = AUX_SLAVE(dev);
302
303 - monitor_hmp_printf(MONITOR_HMP(mon),
304 - "%*smemory " HWADDR_FMT_plx "/" HWADDR_FMT_plx "\n",
303 + monitor_hmp_printf(hmp, "%*smemory " HWADDR_FMT_plx "/" HWADDR_FMT_plx "\n",
304 indent, "",
305 object_property_get_uint(OBJECT(s->mmio), "addr", NULL),
306 memory_region_size(s->mmio));
hw/pci/pci-hmp-cmds.c
+1 -2
@@ -135,9 +135,8 @@ void hmp_info_pci(MonitorHMP *hmp, const QDict *qdict)
135 qapi_free_PciInfoList(info_list);
136 }
137
138 -void pcibus_dev_print(Monitor *mon, DeviceState *dev, int indent)
138 +void pcibus_dev_print(MonitorHMP *hmp, DeviceState *dev, int indent)
139 {
140 - MonitorHMP *hmp = MONITOR_HMP(mon);
140 PCIDevice *d = (PCIDevice *)dev;
141 int class = pci_get_word(d->config + PCI_CLASS_DEVICE);
142 const pci_class_desc *desc = get_class_desc(class);
hw/pci/pci-internal.h
+1 -1
@@ -16,7 +16,7 @@ extern PCIHostStateList pci_host_bridges;
16
17 const pci_class_desc *get_class_desc(int class);
18 PCIBus *pci_find_bus_nr(PCIBus *bus, int bus_num);
19 -void pcibus_dev_print(Monitor *mon, DeviceState *dev, int indent);
19 +void pcibus_dev_print(MonitorHMP *mon, DeviceState *dev, int indent);
20
21 int pcie_aer_parse_error_string(const char *error_name,
22 uint32_t *status, bool *correctable);
hw/usb/bus.c
+2 -3
@@ -13,7 +13,7 @@
13 #include "trace.h"
14 #include "qemu/cutils.h"
15
16 -static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent);
16 +static void usb_bus_dev_print(MonitorHMP *hmp, DeviceState *qdev, int indent);
17
18 static char *usb_get_dev_path(DeviceState *dev);
19 static char *usb_get_fw_dev_path(DeviceState *qdev);
@@ -544,9 +544,8 @@ static const char *usb_speed(unsigned int speed)
544 return txt[speed];
545 }
546
547 -static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent)
547 +static void usb_bus_dev_print(MonitorHMP *hmp, DeviceState *qdev, int indent)
548 {
549 - MonitorHMP *hmp = MONITOR_HMP(mon);
549 USBDevice *dev = USB_DEVICE(qdev);
550 USBBus *bus = usb_bus_from_device(dev);
551
hw/xen/xen-bus.c
+1 -2
@@ -101,9 +101,8 @@ abort:
101 qemu_xen_xs_transaction_end(xenbus->xsh, tid, true);
102 }
103
104 -static void xen_bus_print_dev(Monitor *mon, DeviceState *dev, int indent)
104 +static void xen_bus_print_dev(MonitorHMP *hmp, DeviceState *dev, int indent)
105 {
106 - MonitorHMP *hmp = MONITOR_HMP(mon);
106 XenDevice *xendev = XEN_DEVICE(dev);
107
108 monitor_hmp_printf(hmp, "%*sname = '%s' frontend_id = %u\n",
include/hw/core/qdev.h
+2 -1
@@ -10,6 +10,7 @@
10 #include "qom/object.h"
11 #include "hw/core/hotplug.h"
12 #include "hw/core/resettable.h"
13 +#include "monitor/hmp.h"
14
15 /**
16 * DOC: The QEMU Device API
@@ -323,7 +324,7 @@ struct BusClass {
324 ObjectClass parent_class;
325
326 /* FIXME first arg should be BusState */
326 - void (*print_dev)(Monitor *mon, DeviceState *dev, int indent);
327 + void (*print_dev)(MonitorHMP *mon, DeviceState *dev, int indent);
328 /*
329 * Return a newly allocated string containing the path of the
330 * device on this bus.
system/qdev-monitor.c
+3 -4
@@ -790,18 +790,17 @@ static void qdev_print_props(MonitorHMP *hmp, DeviceState *dev, DeviceClass *dc,
790 }
791 }
792
793 -static void bus_print_dev(BusState *bus, Monitor *mon, DeviceState *dev, int indent)
793 +static void bus_print_dev(BusState *bus, MonitorHMP *hmp, DeviceState *dev, int indent)
794 {
795 BusClass *bc = BUS_GET_CLASS(bus);
796
797 if (bc->print_dev) {
798 - bc->print_dev(mon, dev, indent);
798 + bc->print_dev(hmp, dev, indent);
799 }
800 }
801
802 static void qdev_print(MonitorHMP *hmp, DeviceState *dev, int indent)
803 {
804 - Monitor *mon = MONITOR(hmp);
804 ObjectClass *class;
805 NamedGPIOList *ngl;
806 NamedClockList *ncl;
@@ -828,7 +827,7 @@ static void qdev_print(MonitorHMP *hmp, DeviceState *dev, int indent)
827 qdev_print_props(hmp, dev, DEVICE_CLASS(class), indent);
828 class = object_class_get_parent(class);
829 } while (class != object_class_by_name(TYPE_DEVICE));
831 - bus_print_dev(dev->parent_bus, mon, dev, indent);
830 + bus_print_dev(dev->parent_bus, hmp, dev, indent);
831 }
832
833 static void qbus_print(MonitorHMP *hmp, BusState *bus, int indent, bool details)