diff mbox series

[v5,3/6] hw/qdev: Introduce qdev_hotplug_unplug_allowed_common()

Message ID 20250110091908.64454-4-philmd@linaro.org (mailing list archive)
State New
Headers show
Series hw/core: Unify hotplug decision logic | expand

Commit Message

Philippe Mathieu-Daudé Jan. 10, 2025, 9:19 a.m. UTC
From: Akihiko Odaki <akihiko.odaki@daynix.com>

Introduce qdev_hotplug_unplug_allowed_common() to hold
common code between checking hot-plug/unplug is allowed.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/core/qdev-hotplug.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/hw/core/qdev-hotplug.c b/hw/core/qdev-hotplug.c
index dc35110e735..168d7964740 100644
--- a/hw/core/qdev-hotplug.c
+++ b/hw/core/qdev-hotplug.c
@@ -30,12 +30,22 @@  HotplugHandler *qdev_get_machine_hotplug_handler(DeviceState *dev)
     return NULL;
 }
 
+static bool qdev_hotplug_unplug_allowed_common(DeviceState *dev, BusState *bus,
+                                               Error **errp)
+{
+    return true;
+}
+
 bool qdev_hotplug_allowed(DeviceState *dev, BusState *bus, Error **errp)
 {
     MachineState *machine;
     MachineClass *mc;
     Object *m_obj = qdev_get_machine();
 
+    if (!qdev_hotplug_unplug_allowed_common(dev, bus, errp)) {
+        return false;
+    }
+
     if (object_dynamic_cast(m_obj, TYPE_MACHINE)) {
         machine = MACHINE(m_obj);
         mc = MACHINE_GET_CLASS(machine);
@@ -49,7 +59,8 @@  bool qdev_hotplug_allowed(DeviceState *dev, BusState *bus, Error **errp)
 
 bool qdev_hotunplug_allowed(DeviceState *dev, Error **errp)
 {
-    return !qdev_unplug_blocked(dev, errp);
+    return !qdev_unplug_blocked(dev, errp) &&
+           qdev_hotplug_unplug_allowed_common(dev, dev->parent_bus, errp);
 }
 
 HotplugHandler *qdev_get_bus_hotplug_handler(DeviceState *dev)