diff mbox

[07/11] qdev: add reference for the bus while it is referred to by the DeviceState

Message ID 1354740282-20679-8-git-send-email-pbonzini@redhat.com
State New
Headers show

Commit Message

Paolo Bonzini Dec. 5, 2012, 8:44 p.m. UTC
Now that the unparent callbacks are complete, we can correctly account
more missing references.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/qdev.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Anthony Liguori Jan. 7, 2013, 8:29 p.m. UTC | #1
Paolo Bonzini <pbonzini@redhat.com> writes:

> Now that the unparent callbacks are complete, we can correctly account
> more missing references.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  hw/qdev.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/hw/qdev.c b/hw/qdev.c
> index d7f1545..62b6c14 100644
> --- a/hw/qdev.c
> +++ b/hw/qdev.c
> @@ -101,6 +101,7 @@ static void bus_add_child(BusState *bus, DeviceState *child)
>  void qdev_set_parent_bus(DeviceState *dev, BusState *bus)
>  {
>      dev->parent_bus = bus;
> +    object_ref(OBJECT(bus));
>      bus_add_child(bus, dev);

If we make parent_bus a link property, we'll get the reference counting
for free.

Regards,

Anthony Liguori

>  }
>  
> @@ -734,6 +735,8 @@ static void qdev_remove_from_bus(Object *obj)
>      }
>      if (dev->parent_bus) {
>          bus_remove_child(dev->parent_bus, dev);
> +        object_unref(OBJECT(dev->parent_bus));
> +        dev->parent_bus = NULL;
>      }
>  }
>  
> -- 
> 1.8.0.1
Paolo Bonzini Jan. 9, 2013, 1:25 p.m. UTC | #2
Il 07/01/2013 21:29, Anthony Liguori ha scritto:
> Paolo Bonzini <pbonzini@redhat.com> writes:
> 
>> Now that the unparent callbacks are complete, we can correctly account
>> more missing references.
>>
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> ---
>>  hw/qdev.c | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/hw/qdev.c b/hw/qdev.c
>> index d7f1545..62b6c14 100644
>> --- a/hw/qdev.c
>> +++ b/hw/qdev.c
>> @@ -101,6 +101,7 @@ static void bus_add_child(BusState *bus, DeviceState *child)
>>  void qdev_set_parent_bus(DeviceState *dev, BusState *bus)
>>  {
>>      dev->parent_bus = bus;
>> +    object_ref(OBJECT(bus));
>>      bus_add_child(bus, dev);
> 
> If we make parent_bus a link property, we'll get the reference counting
> for free.

True, but I think this should be a separate series.

Paolo

> Regards,
> 
> Anthony Liguori
> 
>>  }
>>  
>> @@ -734,6 +735,8 @@ static void qdev_remove_from_bus(Object *obj)
>>      }
>>      if (dev->parent_bus) {
>>          bus_remove_child(dev->parent_bus, dev);
>> +        object_unref(OBJECT(dev->parent_bus));
>> +        dev->parent_bus = NULL;
>>      }
>>  }
>>  
>> -- 
>> 1.8.0.1
>
diff mbox

Patch

diff --git a/hw/qdev.c b/hw/qdev.c
index d7f1545..62b6c14 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -101,6 +101,7 @@  static void bus_add_child(BusState *bus, DeviceState *child)
 void qdev_set_parent_bus(DeviceState *dev, BusState *bus)
 {
     dev->parent_bus = bus;
+    object_ref(OBJECT(bus));
     bus_add_child(bus, dev);
 }
 
@@ -734,6 +735,8 @@  static void qdev_remove_from_bus(Object *obj)
     }
     if (dev->parent_bus) {
         bus_remove_child(dev->parent_bus, dev);
+        object_unref(OBJECT(dev->parent_bus));
+        dev->parent_bus = NULL;
     }
 }