qdev: Add a 'free' method to disassociate chardev from qdev device
authorAmit Shah <amit.shah@redhat.com>
Fri, 13 Jan 2012 09:59:47 +0000 (15:29 +0530)
committerAnthony Liguori <aliguori@us.ibm.com>
Fri, 13 Jan 2012 16:21:03 +0000 (10:21 -0600)
When a device is removed, remove the association with a chardev, if any,
so that the chardev can be re-used later for other devices.

Reported-by: Qunfang Zhang <qzhang@redhat.com>
Fix-suggested-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
hw/qdev-properties.c

index 663c2a0a1973ab510284612d9c21d2e4515b625c..02f0dae0bccaf351aa59366a096c3590059c900e 100644 (file)
@@ -680,6 +680,16 @@ static int parse_chr(DeviceState *dev, Property *prop, const char *str)
     return 0;
 }
 
+static void free_chr(DeviceState *dev, Property *prop)
+{
+    CharDriverState **ptr = qdev_get_prop_ptr(dev, prop);
+
+    if (*ptr) {
+        qemu_chr_add_handlers(*ptr, NULL, NULL, NULL, NULL);
+    }
+}
+
+
 static int print_chr(DeviceState *dev, Property *prop, char *dest, size_t len)
 {
     CharDriverState **ptr = qdev_get_prop_ptr(dev, prop);
@@ -699,6 +709,7 @@ PropertyInfo qdev_prop_chr = {
     .print = print_chr,
     .get   = get_generic,
     .set   = set_generic,
+    .free  = free_chr,
 };
 
 /* --- netdev device --- */