@samitouri / QOSamiQemu / commits / 75724a58ba

hw: guard BusClass::print_dev with CONFIG_HMP

The print_dev callback is only used by HMP 'info qtree'. Guard the field in BusClass, all implementations, and the caller with CONFIG_HMP. Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-ID: <20260828-qemu-no-hmp-v5-43-9227de146347@redhat.com>

Marc-André Lureau committed Aug 28, 2026 at 16:04 UTC 75724a58ba3a39cf1bb5c1c660ae4a4ede0e96bc
8 files changed +39 -5
hw/char/virtio-serial-bus.c
+6
@@ -814,7 +814,9 @@ static int virtio_serial_load_device(VirtIODevice *vdev, QEMUFile *f,
814 return 0;
815 }
816
817 +#ifdef CONFIG_HMP
818 static void virtser_bus_dev_print(MonitorHMP *hmp, DeviceState *qdev, int indent);
819 +#endif
820
821 static const Property virtser_props[] = {
822 DEFINE_PROP_UINT32("nr", VirtIOSerialPort, id, VIRTIO_CONSOLE_BAD_ID),
@@ -823,8 +825,10 @@ static const Property virtser_props[] = {
825
826 static void virtser_bus_class_init(ObjectClass *klass, const void *data)
827 {
828 +#ifdef CONFIG_HMP
829 BusClass *k = BUS_CLASS(klass);
830 k->print_dev = virtser_bus_dev_print;
831 +#endif
832 }
833
834 static const TypeInfo virtser_bus_info = {
@@ -834,6 +838,7 @@ static const TypeInfo virtser_bus_info = {
838 .class_init = virtser_bus_class_init,
839 };
840
841 +#ifdef CONFIG_HMP
842 static void virtser_bus_dev_print(MonitorHMP *hmp, DeviceState *qdev, int indent)
843 {
844 VirtIOSerialPort *port = VIRTIO_SERIAL_PORT(qdev);
@@ -844,6 +849,7 @@ static void virtser_bus_dev_print(MonitorHMP *hmp, DeviceState *qdev, int indent
849 port->host_connected ? "on" : "off",
850 port->throttled ? "on" : "off");
851 }
852 +#endif
853
854 /* This function is only used if a port id is not provided by the user */
855 static uint32_t find_free_port_id(VirtIOSerial *vser)
hw/core/sysbus.c
+6
@@ -24,7 +24,9 @@
24 #include "monitor/hmp.h"
25 #include "system/address-spaces.h"
26
27 +#ifdef CONFIG_HMP
28 static void sysbus_dev_print(MonitorHMP *hmp, DeviceState *dev, int indent);
29 +#endif
30 static char *sysbus_get_fw_dev_path(DeviceState *dev);
31
32 typedef struct SysBusFind {
@@ -76,7 +78,9 @@ static void system_bus_class_init(ObjectClass *klass, const void *data)
78 {
79 BusClass *k = BUS_CLASS(klass);
80
81 +#ifdef CONFIG_HMP
82 k->print_dev = sysbus_dev_print;
83 +#endif
84 k->get_fw_dev_path = sysbus_get_fw_dev_path;
85 }
86
@@ -249,6 +253,7 @@ bool sysbus_realize_and_unref(SysBusDevice *dev, Error **errp)
253 return qdev_realize_and_unref(DEVICE(dev), sysbus_get_default(), errp);
254 }
255
256 +#ifdef CONFIG_HMP
257 static void sysbus_dev_print(MonitorHMP *hmp, DeviceState *dev, int indent)
258 {
259 SysBusDevice *s = SYS_BUS_DEVICE(dev);
@@ -261,6 +266,7 @@ static void sysbus_dev_print(MonitorHMP *hmp, DeviceState *dev, int indent)
266 indent, "", s->mmio[i].addr, size);
267 }
268 }
269 +#endif
270
271 static char *sysbus_get_fw_dev_path(DeviceState *dev)
272 {
hw/misc/auxbus.c
+11 -5
@@ -47,18 +47,22 @@
47 } while (0)
48
49
50 +#ifdef CONFIG_HMP
51 static void aux_slave_dev_print(MonitorHMP *hmp, DeviceState *dev, int indent);
52 +#endif
53 static inline I2CBus *aux_bridge_get_i2c_bus(AUXTOI2CState *bridge);
54
55 /* aux-bus implementation (internal not public) */
56 static void aux_bus_class_init(ObjectClass *klass, const void *data)
57 {
58 +#ifdef CONFIG_HMP
59 BusClass *k = BUS_CLASS(klass);
60
61 /* AUXSlave has an MMIO so we need to change the way we print information
62 * in monitor.
63 */
64 k->print_dev = aux_slave_dev_print;
65 +#endif
66 }
67
68 AUXBus *aux_bus_init(DeviceState *parent, const char *name)
@@ -91,11 +95,6 @@ void aux_map_slave(AUXSlave *aux_dev, hwaddr addr)
95 memory_region_add_subregion(bus->aux_io, addr, aux_dev->mmio);
96 }
97
94 -static bool aux_bus_is_bridge(AUXBus *bus, DeviceState *dev)
95 -{
96 - return (dev == DEVICE(bus->bridge));
97 -}
98 -
98 I2CBus *aux_get_i2c_bus(AUXBus *bus)
99 {
100 return aux_bridge_get_i2c_bus(bus->bridge);
@@ -288,6 +287,12 @@ static const TypeInfo aux_to_i2c_type_info = {
287 };
288
289 /* aux-slave implementation */
290 +#ifdef CONFIG_HMP
291 +static bool aux_bus_is_bridge(AUXBus *bus, DeviceState *dev)
292 +{
293 + return (dev == DEVICE(bus->bridge));
294 +}
295 +
296 static void aux_slave_dev_print(MonitorHMP *hmp, DeviceState *dev, int indent)
297 {
298 AUXBus *bus = AUX_BUS(qdev_get_parent_bus(dev));
@@ -305,6 +310,7 @@ static void aux_slave_dev_print(MonitorHMP *hmp, DeviceState *dev, int indent)
310 object_property_get_uint(OBJECT(s->mmio), "addr", NULL),
311 memory_region_size(s->mmio));
312 }
313 +#endif
314
315 void aux_init_mmio(AUXSlave *aux_slave, MemoryRegion *mmio)
316 {
hw/pci/pci-hmp-cmds.c
+2
@@ -135,6 +135,7 @@ void hmp_info_pci(MonitorHMP *hmp, const QDict *qdict)
135 qapi_free_PciInfoList(info_list);
136 }
137
138 +#ifdef CONFIG_HMP
139 void pcibus_dev_print(MonitorHMP *hmp, DeviceState *dev, int indent)
140 {
141 PCIDevice *d = (PCIDevice *)dev;
@@ -170,6 +171,7 @@ void pcibus_dev_print(MonitorHMP *hmp, DeviceState *dev, int indent)
171 r->addr, r->addr + r->size - 1);
172 }
173 }
174 +#endif
175
176 void hmp_pcie_aer_inject_error(MonitorHMP *hmp, const QDict *qdict)
177 {
hw/pci/pci.c
+2
@@ -293,7 +293,9 @@ static void pci_bus_class_init(ObjectClass *klass, const void *data)
293 ResettableClass *rc = RESETTABLE_CLASS(klass);
294 FWCfgDataGeneratorClass *fwgc = FW_CFG_DATA_GENERATOR_CLASS(klass);
295
296 +#ifdef CONFIG_HMP
297 k->print_dev = pcibus_dev_print;
298 +#endif
299 k->get_dev_path = pcibus_get_dev_path;
300 k->get_fw_dev_path = pcibus_get_fw_dev_path;
301 k->realize = pci_bus_realize;
hw/usb/bus.c
+6
@@ -13,7 +13,9 @@
13 #include "trace.h"
14 #include "qemu/cutils.h"
15
16 +#ifdef CONFIG_HMP
17 static void usb_bus_dev_print(MonitorHMP *hmp, DeviceState *qdev, int indent);
18 +#endif
19
20 static char *usb_get_dev_path(DeviceState *dev);
21 static char *usb_get_fw_dev_path(DeviceState *qdev);
@@ -32,7 +34,9 @@ static void usb_bus_class_init(ObjectClass *klass, const void *data)
34 BusClass *k = BUS_CLASS(klass);
35 HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass);
36
37 +#ifdef CONFIG_HMP
38 k->print_dev = usb_bus_dev_print;
39 +#endif
40 k->get_dev_path = usb_get_dev_path;
41 k->get_fw_dev_path = usb_get_fw_dev_path;
42 hc->unplug = qdev_simple_device_unplug_cb;
@@ -544,6 +548,7 @@ static const char *usb_speed(unsigned int speed)
548 return txt[speed];
549 }
550
551 +#ifdef CONFIG_HMP
552 static void usb_bus_dev_print(MonitorHMP *hmp, DeviceState *qdev, int indent)
553 {
554 USBDevice *dev = USB_DEVICE(qdev);
@@ -555,6 +560,7 @@ static void usb_bus_dev_print(MonitorHMP *hmp, DeviceState *qdev, int indent)
560 usb_speed(dev->speed), dev->product_desc,
561 dev->attached ? ", attached" : "");
562 }
563 +#endif
564
565 static char *usb_get_dev_path(DeviceState *qdev)
566 {
hw/xen/xen-bus.c
+4
@@ -101,6 +101,7 @@ abort:
101 qemu_xen_xs_transaction_end(xenbus->xsh, tid, true);
102 }
103
104 +#ifdef CONFIG_HMP
105 static void xen_bus_print_dev(MonitorHMP *hmp, DeviceState *dev, int indent)
106 {
107 XenDevice *xendev = XEN_DEVICE(dev);
@@ -108,6 +109,7 @@ static void xen_bus_print_dev(MonitorHMP *hmp, DeviceState *dev, int indent)
109 monitor_hmp_printf(hmp, "%*sname = '%s' frontend_id = %u\n",
110 indent, "", xendev->name, xendev->frontend_id);
111 }
112 +#endif
113
114 static char *xen_bus_get_dev_path(DeviceState *dev)
115 {
@@ -386,7 +388,9 @@ static void xen_bus_class_init(ObjectClass *class, const void *data)
388 BusClass *bus_class = BUS_CLASS(class);
389 HotplugHandlerClass *hotplug_class = HOTPLUG_HANDLER_CLASS(class);
390
391 +#ifdef CONFIG_HMP
392 bus_class->print_dev = xen_bus_print_dev;
393 +#endif
394 bus_class->get_dev_path = xen_bus_get_dev_path;
395 bus_class->realize = xen_bus_realize;
396 bus_class->unrealize = xen_bus_unrealize;
include/hw/core/qdev.h
+2
@@ -323,8 +323,10 @@ DECLARE_OBJ_CHECKERS(BusState, BusClass,
323 struct BusClass {
324 ObjectClass parent_class;
325
326 +#ifdef CONFIG_HMP
327 /* FIXME first arg should be BusState */
328 void (*print_dev)(MonitorHMP *mon, DeviceState *dev, int indent);
329 +#endif
330 /*
331 * Return a newly allocated string containing the path of the
332 * device on this bus.