[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 09/10] qdev-monitor: Check sysbus device type before creating it
From: |
Philippe Mathieu-Daudé |
Subject: |
[PULL 09/10] qdev-monitor: Check sysbus device type before creating it |
Date: |
Mon, 1 Nov 2021 19:42:58 +0100 |
From: Damien Hedde <damien.hedde@greensocs.com>
Add an early check to test if the requested sysbus device type
is allowed by the current machine before creating the device. This
impacts both -device cli option and device_add qmp command.
Before this patch, the check was done well after the device has
been created (in a machine init done notifier). We can now report
the error right away.
Signed-off-by: Damien Hedde <damien.hedde@greensocs.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Acked-by: Eduardo Habkost <ehabkost@redhat.com>
Message-Id: <20211029142258.484907-3-damien.hedde@greensocs.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
softmmu/qdev-monitor.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c
index 4851de51a5c..e49d9773d2d 100644
--- a/softmmu/qdev-monitor.c
+++ b/softmmu/qdev-monitor.c
@@ -42,6 +42,7 @@
#include "qemu/cutils.h"
#include "hw/qdev-properties.h"
#include "hw/clock.h"
+#include "hw/boards.h"
/*
* Aliases were a bad idea from the start. Let's keep them
@@ -254,6 +255,16 @@ static DeviceClass *qdev_get_device_class(const char
**driver, Error **errp)
return NULL;
}
+ if (object_class_dynamic_cast(oc, TYPE_SYS_BUS_DEVICE)) {
+ /* sysbus devices need to be allowed by the machine */
+ MachineClass *mc = MACHINE_CLASS(object_get_class(qdev_get_machine()));
+ if (!device_type_is_dynamic_sysbus(mc, *driver)) {
+ error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "driver",
+ "a dynamic sysbus device type for the machine");
+ return NULL;
+ }
+ }
+
return dc;
}
--
2.31.1
- [PULL 00/10] Machine-next patches for 2021-11-01, Philippe Mathieu-Daudé, 2021/11/01
- [PULL 01/10] machine: Move gpio code to hw/core/gpio.c, Philippe Mathieu-Daudé, 2021/11/01
- [PULL 02/10] hw/core: Restrict sysemu specific files, Philippe Mathieu-Daudé, 2021/11/01
- [PULL 03/10] hw/core: Declare meson source set, Philippe Mathieu-Daudé, 2021/11/01
- [PULL 04/10] hw/core: Extract hotplug-related functions to qdev-hotplug.c, Philippe Mathieu-Daudé, 2021/11/01
- [PULL 05/10] hw/core: Restrict hotplug to system emulation, Philippe Mathieu-Daudé, 2021/11/01
- [PULL 06/10] hw/core/machine: Split out the smp parsing code, Philippe Mathieu-Daudé, 2021/11/01
- [PULL 07/10] tests/unit: Add an unit test for smp parsing, Philippe Mathieu-Daudé, 2021/11/01
- [PULL 08/10] machine: add device_type_is_dynamic_sysbus function, Philippe Mathieu-Daudé, 2021/11/01
- [PULL 09/10] qdev-monitor: Check sysbus device type before creating it,
Philippe Mathieu-Daudé <=
- [PULL 10/10] machine: remove the done notifier for dynamic sysbus device type check, Philippe Mathieu-Daudé, 2021/11/01
- Re: [PULL 00/10] Machine-next patches for 2021-11-01, Richard Henderson, 2021/11/02