All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] usb: ehci: fix memory leak in ehci
@ 2017-02-08  2:42 Li Qiang
  2017-02-15  6:25 ` Li Qiang
  0 siblings, 1 reply; 2+ messages in thread
From: Li Qiang @ 2017-02-08  2:42 UTC (permalink / raw)
  To: kraxel, qemu-devel; +Cc: Li Qiang

From: Li Qiang <liqiang6-s@360.cn>

In usb_ehci_init function, it initializes 's->ipacket', but there
is no corresponding function to free this. As the ehci can be hotplug
and unplug, this will leak host memory leak. In order to make the
hierarchy clean, we should add a ehci pci finalize function, then call
the clean function in ehci device.

Signed-off-by: Li Qiang <liqiang6-s@360.cn>
---
 hw/usb/hcd-ehci-pci.c | 9 +++++++++
 hw/usb/hcd-ehci.c     | 5 +++++
 hw/usb/hcd-ehci.h     | 1 +
 3 files changed, 15 insertions(+)

diff --git a/hw/usb/hcd-ehci-pci.c b/hw/usb/hcd-ehci-pci.c
index 5657705..6dedcb8 100644
--- a/hw/usb/hcd-ehci-pci.c
+++ b/hw/usb/hcd-ehci-pci.c
@@ -89,6 +89,14 @@ static void usb_ehci_pci_init(Object *obj)
     usb_ehci_init(s, DEVICE(obj));
 }
 
+static void usb_ehci_pci_finalize(Object *obj)
+{
+    EHCIPCIState *i = PCI_EHCI(obj);
+    EHCIState *s = &i->ehci;
+
+    usb_ehci_finalize(s);
+}
+
 static void usb_ehci_pci_exit(PCIDevice *dev)
 {
     EHCIPCIState *i = PCI_EHCI(dev);
@@ -159,6 +167,7 @@ static const TypeInfo ehci_pci_type_info = {
     .parent = TYPE_PCI_DEVICE,
     .instance_size = sizeof(EHCIPCIState),
     .instance_init = usb_ehci_pci_init,
+    .instance_finalize = usb_ehci_pci_finalize,
     .abstract = true,
     .class_init = ehci_class_init,
 };
diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index 7622a3a..50ef817 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -2545,6 +2545,11 @@ void usb_ehci_init(EHCIState *s, DeviceState *dev)
                                 &s->mem_ports);
 }
 
+void usb_ehci_finalize(EHCIState *s)
+{
+    usb_packet_cleanup(&s->ipacket);
+}
+
 /*
  * vim: expandtab ts=4
  */
diff --git a/hw/usb/hcd-ehci.h b/hw/usb/hcd-ehci.h
index 3fd7038..938d8aa 100644
--- a/hw/usb/hcd-ehci.h
+++ b/hw/usb/hcd-ehci.h
@@ -323,6 +323,7 @@ struct EHCIState {
 extern const VMStateDescription vmstate_ehci;
 
 void usb_ehci_init(EHCIState *s, DeviceState *dev);
+void usb_ehci_finalize(EHCIState *s);
 void usb_ehci_realize(EHCIState *s, DeviceState *dev, Error **errp);
 void usb_ehci_unrealize(EHCIState *s, DeviceState *dev, Error **errp);
 void ehci_reset(void *opaque);
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [PATCH] usb: ehci: fix memory leak in ehci
  2017-02-08  2:42 [Qemu-devel] [PATCH] usb: ehci: fix memory leak in ehci Li Qiang
@ 2017-02-15  6:25 ` Li Qiang
  0 siblings, 0 replies; 2+ messages in thread
From: Li Qiang @ 2017-02-15  6:25 UTC (permalink / raw)
  To: Gerd Hoffmann, Qemu Developers; +Cc: Li Qiang

Ping...

2017-02-08 10:42 GMT+08:00 Li Qiang <liq3ea@gmail.com>:

> From: Li Qiang <liqiang6-s@360.cn>
>
> In usb_ehci_init function, it initializes 's->ipacket', but there
> is no corresponding function to free this. As the ehci can be hotplug
> and unplug, this will leak host memory leak. In order to make the
> hierarchy clean, we should add a ehci pci finalize function, then call
> the clean function in ehci device.
>
> Signed-off-by: Li Qiang <liqiang6-s@360.cn>
> ---
>  hw/usb/hcd-ehci-pci.c | 9 +++++++++
>  hw/usb/hcd-ehci.c     | 5 +++++
>  hw/usb/hcd-ehci.h     | 1 +
>  3 files changed, 15 insertions(+)
>
> diff --git a/hw/usb/hcd-ehci-pci.c b/hw/usb/hcd-ehci-pci.c
> index 5657705..6dedcb8 100644
> --- a/hw/usb/hcd-ehci-pci.c
> +++ b/hw/usb/hcd-ehci-pci.c
> @@ -89,6 +89,14 @@ static void usb_ehci_pci_init(Object *obj)
>      usb_ehci_init(s, DEVICE(obj));
>  }
>
> +static void usb_ehci_pci_finalize(Object *obj)
> +{
> +    EHCIPCIState *i = PCI_EHCI(obj);
> +    EHCIState *s = &i->ehci;
> +
> +    usb_ehci_finalize(s);
> +}
> +
>  static void usb_ehci_pci_exit(PCIDevice *dev)
>  {
>      EHCIPCIState *i = PCI_EHCI(dev);
> @@ -159,6 +167,7 @@ static const TypeInfo ehci_pci_type_info = {
>      .parent = TYPE_PCI_DEVICE,
>      .instance_size = sizeof(EHCIPCIState),
>      .instance_init = usb_ehci_pci_init,
> +    .instance_finalize = usb_ehci_pci_finalize,
>      .abstract = true,
>      .class_init = ehci_class_init,
>  };
> diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
> index 7622a3a..50ef817 100644
> --- a/hw/usb/hcd-ehci.c
> +++ b/hw/usb/hcd-ehci.c
> @@ -2545,6 +2545,11 @@ void usb_ehci_init(EHCIState *s, DeviceState *dev)
>                                  &s->mem_ports);
>  }
>
> +void usb_ehci_finalize(EHCIState *s)
> +{
> +    usb_packet_cleanup(&s->ipacket);
> +}
> +
>  /*
>   * vim: expandtab ts=4
>   */
> diff --git a/hw/usb/hcd-ehci.h b/hw/usb/hcd-ehci.h
> index 3fd7038..938d8aa 100644
> --- a/hw/usb/hcd-ehci.h
> +++ b/hw/usb/hcd-ehci.h
> @@ -323,6 +323,7 @@ struct EHCIState {
>  extern const VMStateDescription vmstate_ehci;
>
>  void usb_ehci_init(EHCIState *s, DeviceState *dev);
> +void usb_ehci_finalize(EHCIState *s);
>  void usb_ehci_realize(EHCIState *s, DeviceState *dev, Error **errp);
>  void usb_ehci_unrealize(EHCIState *s, DeviceState *dev, Error **errp);
>  void ehci_reset(void *opaque);
> --
> 1.8.3.1
>
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-02-15  6:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-08  2:42 [Qemu-devel] [PATCH] usb: ehci: fix memory leak in ehci Li Qiang
2017-02-15  6:25 ` Li Qiang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.