qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v4 11/12] pc: Support firmware configuration wit


From: Markus Armbruster
Subject: Re: [Qemu-devel] [PATCH v4 11/12] pc: Support firmware configuration with -blockdev
Date: Mon, 11 Mar 2019 18:42:51 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)

Incremental diff since v3:

diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c
index ccf2221acb..c628540774 100644
--- a/hw/i386/pc_sysfw.c
+++ b/hw/i386/pc_sysfw.c
@@ -82,13 +82,19 @@ static void pc_isa_bios_init(MemoryRegion *rom_memory,
     memory_region_set_readonly(isa_bios, true);
 }
 
-static PFlashCFI01 *pc_pflash_create(const char *name)
+static PFlashCFI01 *pc_pflash_create(PCMachineState *pcms,
+                                     const char *name,
+                                     const char *alias_prop_name)
 {
     DeviceState *dev = qdev_create(NULL, TYPE_PFLASH_CFI01);
 
     qdev_prop_set_uint64(dev, "sector-length", FLASH_SECTOR_SIZE);
     qdev_prop_set_uint8(dev, "width", 1);
     qdev_prop_set_string(dev, "name", name);
+    object_property_add_child(OBJECT(pcms), name, OBJECT(dev),
+                              &error_abort);
+    object_property_add_alias(OBJECT(pcms), alias_prop_name,
+                              OBJECT(dev), "drive", &error_abort);
     return PFLASH_CFI01(dev);
 }
 
@@ -97,14 +103,10 @@ void pc_system_flash_create(PCMachineState *pcms)
     PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
 
     if (pcmc->pci_enabled) {
-        pcms->flash[0] = pc_pflash_create("system.flash0");
-        pcms->flash[1] = pc_pflash_create("system.flash1");
-        object_property_add_alias(OBJECT(pcms), "pflash0",
-                                  OBJECT(pcms->flash[0]), "drive",
-                                  &error_abort);
-        object_property_add_alias(OBJECT(pcms), "pflash1",
-                                  OBJECT(pcms->flash[1]), "drive",
-                                  &error_abort);
+        pcms->flash[0] = pc_pflash_create(pcms, "system.flash0",
+                                          "pflash0");
+        pcms->flash[1] = pc_pflash_create(pcms, "system.flash1",
+                                          "pflash1");
     }
 }
 
@@ -122,19 +124,7 @@ static void pc_system_flash_cleanup_unused(PCMachineState 
*pcms)
             prop_name = g_strdup_printf("pflash%d", i);
             object_property_del(OBJECT(pcms), prop_name, &error_abort);
             g_free(prop_name);
-            /*
-             * Delete @dev_obj.  Straight object_unref() is wrong,
-             * since it leaves dangling references in the parent bus
-             * behind.  object_unparent() doesn't work, either: since
-             * @dev_obj hasn't been realized, dev_obj->parent is null,
-             * and object_unparent() does nothing.  DeviceClass method
-             * device_unparent() works, but we have to take a
-             * temporary reference, or else device_unparent() commits
-             * a use-after-free error.
-             */
-            object_ref(dev_obj);
-            object_get_class(dev_obj)->unparent(dev_obj);
-            object_unref(dev_obj);
+            object_unparent(dev_obj);
             pcms->flash[i] = NULL;
         }
     }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]