Patchwork [22/26] kvmclock: QOM'ify some more

login
register
mail settings
Submitter Hu Tao
Date June 22, 2013, 8:50 a.m.
Message ID <86ee840ebf8ad7980e10a2dced91022f207d490c.1371804804.git.hutao@cn.fujitsu.com>
Download mbox | patch
Permalink /patch/253386/
State New
Headers show

Comments

Hu Tao - June 22, 2013, 8:50 a.m.
Introduce type constant and avoid DO_UPCAST().

Cc: qemu-devel@nongnu.org
Cc: "Andreas Färber" <afaerber@suse.de>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Cc: Igor Mammedov <imammedo@redhat.com>
Cc: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
---
 hw/i386/kvm/clock.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
Eduardo Habkost - June 24, 2013, 1:33 p.m.
On Sat, Jun 22, 2013 at 04:50:34PM +0800, Hu Tao wrote:
> Introduce type constant and avoid DO_UPCAST().
> 
> Cc: qemu-devel@nongnu.org
> Cc: "Andreas Färber" <afaerber@suse.de>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Eduardo Habkost <ehabkost@redhat.com>
> Cc: Igor Mammedov <imammedo@redhat.com>
> Cc: Anthony Liguori <aliguori@us.ibm.com>
> Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>

Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>

But I agree with Igor that the order of 21/26 and 22/26 could be
changed, so kvmclock_realize() could use KVM_CLOCK() since the
beginning.


> ---
>  hw/i386/kvm/clock.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/i386/kvm/clock.c b/hw/i386/kvm/clock.c
> index 74aa240..eaad880 100644
> --- a/hw/i386/kvm/clock.c
> +++ b/hw/i386/kvm/clock.c
> @@ -22,6 +22,9 @@
>  #include <linux/kvm.h>
>  #include <linux/kvm_para.h>
>  
> +#define TYPE_KVM_CLOCK "kvmclock"
> +#define KVM_CLOCK(obj) OBJECT_CHECK(KVMClockState, (obj), TYPE_KVM_CLOCK)
> +
>  typedef struct KVMClockState {
>      SysBusDevice busdev;
>      uint64_t clock;
> @@ -89,13 +92,13 @@ static void kvmclock_vm_state_change(void *opaque, int running,
>  
>  static void kvmclock_realize(DeviceState *dev, Error **errp)
>  {
> -    KVMClockState *s = DO_UPCAST(KVMClockState, busdev.qdev, dev);
> +    KVMClockState *s = KVM_CLOCK(dev);
>  
>      qemu_add_vm_change_state_handler(kvmclock_vm_state_change, s);
>  }
>  
>  static const VMStateDescription kvmclock_vmsd = {
> -    .name = "kvmclock",
> +    .name = TYPE_KVM_CLOCK,
>      .version_id = 1,
>      .minimum_version_id = 1,
>      .minimum_version_id_old = 1,
> @@ -117,7 +120,7 @@ static void kvmclock_class_init(ObjectClass *klass, void *data)
>  }
>  
>  static const TypeInfo kvmclock_info = {
> -    .name          = "kvmclock",
> +    .name          = TYPE_KVM_CLOCK,
>      .parent        = TYPE_SYS_BUS_DEVICE,
>      .instance_size = sizeof(KVMClockState),
>      .class_init    = kvmclock_class_init,
> @@ -129,7 +132,7 @@ void kvmclock_create(void)
>      if (kvm_enabled() &&
>          first_cpu->features[FEAT_KVM] & ((1ULL << KVM_FEATURE_CLOCKSOURCE) |
>                                           (1ULL << KVM_FEATURE_CLOCKSOURCE2))) {
> -        sysbus_create_simple("kvmclock", -1, NULL);
> +        sysbus_create_simple(TYPE_KVM_CLOCK, -1, NULL);
>      }
>  }
>  
> -- 
> 1.8.3.1
> 
>

Patch

diff --git a/hw/i386/kvm/clock.c b/hw/i386/kvm/clock.c
index 74aa240..eaad880 100644
--- a/hw/i386/kvm/clock.c
+++ b/hw/i386/kvm/clock.c
@@ -22,6 +22,9 @@ 
 #include <linux/kvm.h>
 #include <linux/kvm_para.h>
 
+#define TYPE_KVM_CLOCK "kvmclock"
+#define KVM_CLOCK(obj) OBJECT_CHECK(KVMClockState, (obj), TYPE_KVM_CLOCK)
+
 typedef struct KVMClockState {
     SysBusDevice busdev;
     uint64_t clock;
@@ -89,13 +92,13 @@  static void kvmclock_vm_state_change(void *opaque, int running,
 
 static void kvmclock_realize(DeviceState *dev, Error **errp)
 {
-    KVMClockState *s = DO_UPCAST(KVMClockState, busdev.qdev, dev);
+    KVMClockState *s = KVM_CLOCK(dev);
 
     qemu_add_vm_change_state_handler(kvmclock_vm_state_change, s);
 }
 
 static const VMStateDescription kvmclock_vmsd = {
-    .name = "kvmclock",
+    .name = TYPE_KVM_CLOCK,
     .version_id = 1,
     .minimum_version_id = 1,
     .minimum_version_id_old = 1,
@@ -117,7 +120,7 @@  static void kvmclock_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo kvmclock_info = {
-    .name          = "kvmclock",
+    .name          = TYPE_KVM_CLOCK,
     .parent        = TYPE_SYS_BUS_DEVICE,
     .instance_size = sizeof(KVMClockState),
     .class_init    = kvmclock_class_init,
@@ -129,7 +132,7 @@  void kvmclock_create(void)
     if (kvm_enabled() &&
         first_cpu->features[FEAT_KVM] & ((1ULL << KVM_FEATURE_CLOCKSOURCE) |
                                          (1ULL << KVM_FEATURE_CLOCKSOURCE2))) {
-        sysbus_create_simple("kvmclock", -1, NULL);
+        sysbus_create_simple(TYPE_KVM_CLOCK, -1, NULL);
     }
 }