mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 16:23:55 -06:00
hw/qdev: Check machine_hotplug_handler in hotplug_unplug_allowed_common
Commit03fcbd9dc5
("qdev: Check for the availability of a hotplug controller before adding a device") says: > The qdev_unplug() function contains a g_assert(hotplug_ctrl) > statement, so QEMU crashes when the user tries to device_add + > device_del a device that does not have a corresponding hotplug > controller. > The code in qdev_device_add() already checks whether the bus has a > proper hotplug controller, but for devices that do not have a > corresponding bus, here is no appropriate check available yet. In that > case we should check whether the machine itself provides a suitable > hotplug controller and refuse to plug the device if none is available. However, it forgot to add the corresponding check to qdev_unplug(). Check the machine hotplug handler once in the common qdev_hotplug_unplug_allowed_common() helper so both hotplug and hot-unplug path are covered. Fixes:7716b8ca74
("qdev: HotplugHandler: Add support for unplugging BUS-less devices") Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com> [PMD: Split from bigger patch, part 6/6] Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Igor Mammedov <imammedo@redhat.com> Message-Id: <20250110091908.64454-7-philmd@linaro.org>
This commit is contained in:
parent
ccaca8929d
commit
937874a83d
2 changed files with 13 additions and 11 deletions
|
@ -684,17 +684,9 @@ DeviceState *qdev_device_add_from_qdict(const QDict *opts,
|
|||
dev = qdev_new(driver);
|
||||
|
||||
/* Check whether the hotplug is allowed by the machine */
|
||||
if (phase_check(PHASE_MACHINE_READY)) {
|
||||
if (!qdev_hotplug_allowed(dev, bus, errp)) {
|
||||
goto err_del_dev;
|
||||
}
|
||||
|
||||
if (!bus && !qdev_get_machine_hotplug_handler(dev)) {
|
||||
/* No bus, no machine hotplug handler --> device is not hotpluggable */
|
||||
error_setg(errp, "Device '%s' can not be hotplugged on this machine",
|
||||
driver);
|
||||
goto err_del_dev;
|
||||
}
|
||||
if (phase_check(PHASE_MACHINE_READY) &&
|
||||
!qdev_hotplug_allowed(dev, bus, errp)) {
|
||||
goto err_del_dev;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue