Il 29/08/2014 22:31, Eduardo Habkost ha scritto:
> Now that we create an accel object before calling machine_init, we can
> simply use the accel object to save all KVMState data, instead of
> allocationg KVMState manually.
> 
> Signed-off-by: Eduardo Habkost <[email protected]>
> ---
>  kvm-all.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/kvm-all.c b/kvm-all.c
> index 9815eaf..8a25f79 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -75,8 +75,10 @@ typedef struct KVMSlot
>  
>  typedef struct kvm_dirty_log KVMDirtyLog;
>  
> -struct KVMState
> +typedef struct KVMState
>  {
> +    AccelState parent_obj;
> +
>      KVMSlot *slots;
>      int nr_slots;
>      int fd;
> @@ -109,10 +111,13 @@ struct KVMState
>      QTAILQ_HEAD(msi_hashtab, KVMMSIRoute) msi_hashtab[KVM_MSI_HASHTAB_SIZE];
>      bool direct_msi;
>  #endif
> -};
> +} KVMState;
>  
>  #define TYPE_KVM_ACCEL ACCEL_CLASS_NAME("kvm")
>  
> +#define KVM_STATE(obj) \
> +    OBJECT_CHECK(KVMState, (obj), TYPE_KVM_ACCEL)
> +
>  KVMState *kvm_state;
>  bool kvm_kernel_irqchip;
>  bool kvm_async_interrupts_allowed;
> @@ -1392,7 +1397,7 @@ static int kvm_init(MachineState *ms)
>      int i, type = 0;
>      const char *kvm_type;
>  
> -    s = g_malloc0(sizeof(KVMState));
> +    s = KVM_STATE(ms->accelerator);
>  
>      /*
>       * On systems where the kernel can support different base page
> @@ -1581,7 +1586,6 @@ err:
>          close(s->fd);
>      }
>      g_free(s->slots);
> -    g_free(s);
>  
>      return ret;
>  }
> @@ -2230,6 +2234,7 @@ static const TypeInfo kvm_accel_type = {
>      .name = TYPE_KVM_ACCEL,
>      .parent = TYPE_ACCEL,
>      .class_init = kvm_accel_class_init,
> +    .instance_size = sizeof(KVMState),
>  };
>  
>  static void kvm_type_init(void)
> 

Reviewed-by: Paolo Bonzini <[email protected]>

Reply via email to