From eaddcab0baade23a3d0aac248236055ab9ac8263 Mon Sep 17 00:00:00 2001 From: Maxim Poliakovski Date: Fri, 29 Mar 2024 03:51:27 +0100 Subject: [PATCH] atahd: don't register device for empty images. Workaround for the case when no hard disk image was specified. The device instance is still there but it won't be visible by the guest OS. --- devices/common/ata/atahd.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/devices/common/ata/atahd.cpp b/devices/common/ata/atahd.cpp index 4ac25b5..73cf02f 100644 --- a/devices/common/ata/atahd.cpp +++ b/devices/common/ata/atahd.cpp @@ -44,6 +44,10 @@ int AtaHardDisk::device_postinit() { return -1; } + std::string hdd_image_path = GET_STR_PROP("hdd_img"); + if (hdd_image_path.empty()) + return 0; + std::string bus_id; uint32_t dev_num; @@ -52,10 +56,7 @@ int AtaHardDisk::device_postinit() { auto bus_obj = dynamic_cast(gMachineObj->get_comp_by_name(bus_id)); bus_obj->register_device(dev_num, this); - std::string hdd_image_path = GET_STR_PROP("hdd_img"); - if (!hdd_image_path.empty()) { - this->insert_image(hdd_image_path); - } + this->insert_image(hdd_image_path); return 0; }