diff mbox

[28/37] virtio-input: free config list

Message ID 20160719085432.4572-29-marcandre.lureau@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Marc-André Lureau July 19, 2016, 8:54 a.m. UTC
From: Marc-André Lureau <marcandre.lureau@redhat.com>

Clear the list when finalizing. The list is created during realize with
virtio_input_idstr_config() and later by further calls to
virtio_input_init_config() and virtio_input_add_config().

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 hw/input/virtio-input-hid.c      |  1 +
 hw/input/virtio-input.c          | 10 ++++++++++
 include/hw/virtio/virtio-input.h |  1 +
 3 files changed, 12 insertions(+)

Comments

Gerd Hoffmann July 22, 2016, 7:58 a.m. UTC | #1
> --- a/hw/input/virtio-input-hid.c
> +++ b/hw/input/virtio-input-hid.c

> +    .instance_finalize = virtio_input_finalize,

> --- a/hw/input/virtio-input.c
> +++ b/hw/input/virtio-input.c

> +void virtio_input_finalize(Object *obj)
> +{
> +    VirtIOInput *vinput = VIRTIO_INPUT(obj);
> +    VirtIOInputConfig *cfg, *next;
> +
> +    QTAILQ_FOREACH_SAFE(cfg, &vinput->cfg_list, node, next) {
> +        QTAILQ_REMOVE(&vinput->cfg_list, cfg, node);
> +        g_free(cfg);
> +    }
> +}

I think you can keep this local to virtio-input.c and simply hook it
into the abstract base class (TYPE_VIRTIO_INPUT).

Other than that it looks fine to me.

cheers,
  Gerd
Marc-André Lureau July 22, 2016, 8:20 a.m. UTC | #2
Hi

----- Original Message -----
> > --- a/hw/input/virtio-input-hid.c
> > +++ b/hw/input/virtio-input-hid.c
> 
> > +    .instance_finalize = virtio_input_finalize,
> 
> > --- a/hw/input/virtio-input.c
> > +++ b/hw/input/virtio-input.c
> 
> > +void virtio_input_finalize(Object *obj)
> > +{
> > +    VirtIOInput *vinput = VIRTIO_INPUT(obj);
> > +    VirtIOInputConfig *cfg, *next;
> > +
> > +    QTAILQ_FOREACH_SAFE(cfg, &vinput->cfg_list, node, next) {
> > +        QTAILQ_REMOVE(&vinput->cfg_list, cfg, node);
> > +        g_free(cfg);
> > +    }
> > +}
> 
> I think you can keep this local to virtio-input.c and simply hook it
> into the abstract base class (TYPE_VIRTIO_INPUT).
> 

Yes, not sure why I didn't do that in the first, place. fixed.
diff mbox

Patch

diff --git a/hw/input/virtio-input-hid.c b/hw/input/virtio-input-hid.c
index 3ee0c18..0e5596e 100644
--- a/hw/input/virtio-input-hid.c
+++ b/hw/input/virtio-input-hid.c
@@ -340,6 +340,7 @@  static const TypeInfo virtio_input_hid_info = {
     .instance_size = sizeof(VirtIOInputHID),
     .class_init    = virtio_input_hid_class_init,
     .abstract      = true,
+    .instance_finalize = virtio_input_finalize,
 };
 
 /* ----------------------------------------------------------------- */
diff --git a/hw/input/virtio-input.c b/hw/input/virtio-input.c
index edf6990..36a7d5e 100644
--- a/hw/input/virtio-input.c
+++ b/hw/input/virtio-input.c
@@ -285,6 +285,16 @@  static void virtio_input_device_realize(DeviceState *dev, Error **errp)
                     virtio_input_save, virtio_input_load, vinput);
 }
 
+void virtio_input_finalize(Object *obj)
+{
+    VirtIOInput *vinput = VIRTIO_INPUT(obj);
+    VirtIOInputConfig *cfg, *next;
+
+    QTAILQ_FOREACH_SAFE(cfg, &vinput->cfg_list, node, next) {
+        QTAILQ_REMOVE(&vinput->cfg_list, cfg, node);
+        g_free(cfg);
+    }
+}
 static void virtio_input_device_unrealize(DeviceState *dev, Error **errp)
 {
     VirtIOInputClass *vic = VIRTIO_INPUT_GET_CLASS(dev);
diff --git a/include/hw/virtio/virtio-input.h b/include/hw/virtio/virtio-input.h
index 55db310..8fd790f 100644
--- a/include/hw/virtio/virtio-input.h
+++ b/include/hw/virtio/virtio-input.h
@@ -104,5 +104,6 @@  void virtio_input_add_config(VirtIOInput *vinput,
                              virtio_input_config *config);
 void virtio_input_idstr_config(VirtIOInput *vinput,
                                uint8_t select, const char *string);
+void virtio_input_finalize(Object *obj);
 
 #endif /* QEMU_VIRTIO_INPUT_H */