Patchwork [02/10] qdev: export qdev_reset() for later use.

login
register
mail settings
Submitter Isaku Yamahata
Date June 17, 2010, 6:15 a.m.
Message ID <f0eb537874405963c93fb022e4a2b7e9b94ee9e8.1276755023.git.yamahata@valinux.co.jp>
Download mbox | patch
Permalink /patch/55971/
State New
Headers show

Comments

Isaku Yamahata - June 17, 2010, 6:15 a.m.
export qdev_reset() for later use.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
 hw/qdev.c |   13 +++++++++----
 hw/qdev.h |    1 +
 2 files changed, 10 insertions(+), 4 deletions(-)
Markus Armbruster - June 17, 2010, 7:01 a.m.
Isaku Yamahata <yamahata@valinux.co.jp> writes:

> export qdev_reset() for later use.
>
> Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
> ---
>  hw/qdev.c |   13 +++++++++----
>  hw/qdev.h |    1 +
>  2 files changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/hw/qdev.c b/hw/qdev.c
> index 61f999c..378f842 100644
> --- a/hw/qdev.c
> +++ b/hw/qdev.c
> @@ -256,13 +256,18 @@ DeviceState *qdev_device_add(QemuOpts *opts)
>      return qdev;
>  }
>  
> -static void qdev_reset(void *opaque)
> +void qdev_reset(DeviceState *dev)
>  {
> -    DeviceState *dev = opaque;
>      if (dev->info->reset)
>          dev->info->reset(dev);
>  }
>  
> +static void qdev_reset_fn(void *opaque)
> +{
> +    DeviceState *dev = opaque;
> +    qdev_reset(dev);
> +}
> +

Nitpick: why the local variable?

[...]
Michael S. Tsirkin - June 17, 2010, 10:05 a.m.
On Thu, Jun 17, 2010 at 03:15:44PM +0900, Isaku Yamahata wrote:
> export qdev_reset() for later use.
> 
> Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
> ---
>  hw/qdev.c |   13 +++++++++----
>  hw/qdev.h |    1 +
>  2 files changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/qdev.c b/hw/qdev.c
> index 61f999c..378f842 100644
> --- a/hw/qdev.c
> +++ b/hw/qdev.c
> @@ -256,13 +256,18 @@ DeviceState *qdev_device_add(QemuOpts *opts)
>      return qdev;
>  }
>  
> -static void qdev_reset(void *opaque)
> +void qdev_reset(DeviceState *dev)

What does this API do? Yes, I see that it invokes
the reset callback internally. But what does it do
that the caller wants? After all, the callback
gets invoked on reset directly.


>  {
> -    DeviceState *dev = opaque;
>      if (dev->info->reset)
>          dev->info->reset(dev);
>  }
>  
> +static void qdev_reset_fn(void *opaque)
> +{
> +    DeviceState *dev = opaque;
> +    qdev_reset(dev);
> +}
> +
>  /* Initialize a device.  Device properties should be set before calling
>     this function.  IRQs and MMIO regions should be connected/mapped after
>     calling this function.
> @@ -278,7 +283,7 @@ int qdev_init(DeviceState *dev)
>          qdev_free(dev);
>          return rc;
>      }
> -    qemu_register_reset(qdev_reset, dev);
> +    qemu_register_reset(qdev_reset_fn, dev);
>      if (dev->info->vmsd) {
>          vmstate_register_with_alias_id(-1, dev->info->vmsd, dev,
>                                         dev->instance_id_alias,
> @@ -348,7 +353,7 @@ void qdev_free(DeviceState *dev)
>          if (dev->opts)
>              qemu_opts_del(dev->opts);
>      }
> -    qemu_unregister_reset(qdev_reset, dev);
> +    qemu_unregister_reset(qdev_reset_fn, dev);
>      QLIST_REMOVE(dev, sibling);
>      for (prop = dev->info->props; prop && prop->name; prop++) {
>          if (prop->info->free) {
> diff --git a/hw/qdev.h b/hw/qdev.h
> index be5ad67..5fbdebf 100644
> --- a/hw/qdev.h
> +++ b/hw/qdev.h
> @@ -113,6 +113,7 @@ typedef struct GlobalProperty {
>  DeviceState *qdev_create(BusState *bus, const char *name);
>  int qdev_device_help(QemuOpts *opts);
>  DeviceState *qdev_device_add(QemuOpts *opts);
> +void qdev_reset(DeviceState *dev);
>  int qdev_init(DeviceState *dev) QEMU_WARN_UNUSED_RESULT;
>  void qdev_init_nofail(DeviceState *dev);
>  void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
> -- 
> 1.6.6.1

Patch

diff --git a/hw/qdev.c b/hw/qdev.c
index 61f999c..378f842 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -256,13 +256,18 @@  DeviceState *qdev_device_add(QemuOpts *opts)
     return qdev;
 }
 
-static void qdev_reset(void *opaque)
+void qdev_reset(DeviceState *dev)
 {
-    DeviceState *dev = opaque;
     if (dev->info->reset)
         dev->info->reset(dev);
 }
 
+static void qdev_reset_fn(void *opaque)
+{
+    DeviceState *dev = opaque;
+    qdev_reset(dev);
+}
+
 /* Initialize a device.  Device properties should be set before calling
    this function.  IRQs and MMIO regions should be connected/mapped after
    calling this function.
@@ -278,7 +283,7 @@  int qdev_init(DeviceState *dev)
         qdev_free(dev);
         return rc;
     }
-    qemu_register_reset(qdev_reset, dev);
+    qemu_register_reset(qdev_reset_fn, dev);
     if (dev->info->vmsd) {
         vmstate_register_with_alias_id(-1, dev->info->vmsd, dev,
                                        dev->instance_id_alias,
@@ -348,7 +353,7 @@  void qdev_free(DeviceState *dev)
         if (dev->opts)
             qemu_opts_del(dev->opts);
     }
-    qemu_unregister_reset(qdev_reset, dev);
+    qemu_unregister_reset(qdev_reset_fn, dev);
     QLIST_REMOVE(dev, sibling);
     for (prop = dev->info->props; prop && prop->name; prop++) {
         if (prop->info->free) {
diff --git a/hw/qdev.h b/hw/qdev.h
index be5ad67..5fbdebf 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -113,6 +113,7 @@  typedef struct GlobalProperty {
 DeviceState *qdev_create(BusState *bus, const char *name);
 int qdev_device_help(QemuOpts *opts);
 DeviceState *qdev_device_add(QemuOpts *opts);
+void qdev_reset(DeviceState *dev);
 int qdev_init(DeviceState *dev) QEMU_WARN_UNUSED_RESULT;
 void qdev_init_nofail(DeviceState *dev);
 void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,