All of lore.kernel.org
 help / color / mirror / Atom feed
From: marcandre.lureau@redhat.com
To: qemu-devel@nongnu.org
Cc: eblake@redhat.com, "Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [Qemu-devel] [PATCH v2 13/37] portio: keep references on portio
Date: Thu, 28 Jul 2016 18:37:44 +0400	[thread overview]
Message-ID: <20160728143808.13707-14-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <20160728143808.13707-1-marcandre.lureau@redhat.com>

From: Marc-André Lureau <marcandre.lureau@redhat.com>

The isa_register_portio_list() function allocates ioports
data/state. Let's keep the reference to this data on some owner.  This
isn't enough to fix leaks, but at least, ASAN stops complaining of
direct leaks. Further cleanup would require calling
portio_list_del/destroy().

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 hw/audio/gus.c            |  9 ++++++---
 hw/audio/sb16.c           |  4 +++-
 hw/block/fdc.c            |  4 +++-
 hw/char/parallel.c        |  3 ++-
 hw/display/vga-isa.c      |  8 ++++++--
 hw/dma/i8257.c            |  6 ++++--
 hw/ide/core.c             |  6 ++++--
 hw/isa/isa-bus.c          | 14 +++++---------
 include/hw/ide/internal.h |  2 ++
 include/hw/isa/i8257.h    |  2 ++
 include/hw/isa/isa.h      |  5 ++++-
 11 files changed, 41 insertions(+), 22 deletions(-)

diff --git a/hw/audio/gus.c b/hw/audio/gus.c
index 6c02646..3d08a65 100644
--- a/hw/audio/gus.c
+++ b/hw/audio/gus.c
@@ -60,6 +60,8 @@ typedef struct GUSState {
     int64_t last_ticks;
     qemu_irq pic;
     IsaDma *isa_dma;
+    PortioList portio_list1;
+    PortioList portio_list2;
 } GUSState;
 
 static uint32_t gus_readb(void *opaque, uint32_t nport)
@@ -265,9 +267,10 @@ static void gus_realizefn (DeviceState *dev, Error **errp)
     s->samples = AUD_get_buffer_size_out (s->voice) >> s->shift;
     s->mixbuf = g_malloc0 (s->samples << s->shift);
 
-    isa_register_portio_list (d, s->port, gus_portio_list1, s, "gus");
-    isa_register_portio_list (d, (s->port + 0x100) & 0xf00,
-                              gus_portio_list2, s, "gus");
+    isa_register_portio_list(d, &s->portio_list1, s->port,
+                             gus_portio_list1, s, "gus");
+    isa_register_portio_list(d, &s->portio_list2, (s->port + 0x100) & 0xf00,
+                             gus_portio_list2, s, "gus");
 
     s->isa_dma = isa_get_dma(isa_bus_from_device(d), s->emu.gusdma);
     k = ISADMA_GET_CLASS(s->isa_dma);
diff --git a/hw/audio/sb16.c b/hw/audio/sb16.c
index 3a4a57a..6b4427f 100644
--- a/hw/audio/sb16.c
+++ b/hw/audio/sb16.c
@@ -106,6 +106,7 @@ typedef struct SB16State {
     /* mixer state */
     int mixer_nreg;
     uint8_t mixer_regs[256];
+    PortioList portio_list;
 } SB16State;
 
 static void SB_audio_callback (void *opaque, int free);
@@ -1378,7 +1379,8 @@ static void sb16_realizefn (DeviceState *dev, Error **errp)
         dolog ("warning: Could not create auxiliary timer\n");
     }
 
-    isa_register_portio_list (isadev, s->port, sb16_ioport_list, s, "sb16");
+    isa_register_portio_list(isadev, &s->portio_list, s->port,
+                             sb16_ioport_list, s, "sb16");
 
     s->isa_hdma = isa_get_dma(isa_bus_from_device(isadev), s->hdma);
     k = ISADMA_GET_CLASS(s->isa_hdma);
diff --git a/hw/block/fdc.c b/hw/block/fdc.c
index f73af7d..b79873a 100644
--- a/hw/block/fdc.c
+++ b/hw/block/fdc.c
@@ -692,6 +692,7 @@ struct FDCtrl {
     /* Timers state */
     uint8_t timer0;
     uint8_t timer1;
+    PortioList portio_list;
 };
 
 static FloppyDriveType get_fallback_drive_type(FDrive *drv)
@@ -2495,7 +2496,8 @@ static void isabus_fdc_realize(DeviceState *dev, Error **errp)
     FDCtrl *fdctrl = &isa->state;
     Error *err = NULL;
 
-    isa_register_portio_list(isadev, isa->iobase, fdc_portio_list, fdctrl,
+    isa_register_portio_list(isadev, &fdctrl->portio_list,
+                             isa->iobase, fdc_portio_list, fdctrl,
                              "fdc");
 
     isa_init_irq(isadev, &fdctrl->irq, isa->irq);
diff --git a/hw/char/parallel.c b/hw/char/parallel.c
index 11c78fe..fa08566 100644
--- a/hw/char/parallel.c
+++ b/hw/char/parallel.c
@@ -80,6 +80,7 @@ typedef struct ParallelState {
     uint32_t last_read_offset; /* For debugging */
     /* Memory-mapped interface */
     int it_shift;
+    PortioList portio_list;
 } ParallelState;
 
 #define TYPE_ISA_PARALLEL "isa-parallel"
@@ -532,7 +533,7 @@ static void parallel_isa_realizefn(DeviceState *dev, Error **errp)
         s->status = dummy;
     }
 
-    isa_register_portio_list(isadev, base,
+    isa_register_portio_list(isadev, &s->portio_list, base,
                              (s->hw_driver
                               ? &isa_parallel_portio_hw_list[0]
                               : &isa_parallel_portio_sw_list[0]),
diff --git a/hw/display/vga-isa.c b/hw/display/vga-isa.c
index f5aff1c..1af9556 100644
--- a/hw/display/vga-isa.c
+++ b/hw/display/vga-isa.c
@@ -39,6 +39,8 @@ typedef struct ISAVGAState {
     ISADevice parent_obj;
 
     struct VGACommonState state;
+    PortioList portio_vga;
+    PortioList portio_vbe;
 } ISAVGAState;
 
 static void vga_isa_reset(DeviceState *dev)
@@ -60,9 +62,11 @@ static void vga_isa_realizefn(DeviceState *dev, Error **errp)
     vga_common_init(s, OBJECT(dev), true);
     s->legacy_address_space = isa_address_space(isadev);
     vga_io_memory = vga_init_io(s, OBJECT(dev), &vga_ports, &vbe_ports);
-    isa_register_portio_list(isadev, 0x3b0, vga_ports, s, "vga");
+    isa_register_portio_list(isadev, &d->portio_vga,
+                             0x3b0, vga_ports, s, "vga");
     if (vbe_ports) {
-        isa_register_portio_list(isadev, 0x1ce, vbe_ports, s, "vbe");
+        isa_register_portio_list(isadev, &d->portio_vbe,
+                                 0x1ce, vbe_ports, s, "vbe");
     }
     memory_region_add_subregion_overlap(isa_address_space(isadev),
                                         0x000a0000,
diff --git a/hw/dma/i8257.c b/hw/dma/i8257.c
index f345c54..bffbdea 100644
--- a/hw/dma/i8257.c
+++ b/hw/dma/i8257.c
@@ -553,10 +553,12 @@ static void i8257_realize(DeviceState *dev, Error **errp)
     memory_region_add_subregion(isa_address_space_io(isa),
                                 d->base, &d->channel_io);
 
-    isa_register_portio_list(isa, d->page_base, page_portio_list, d,
+    isa_register_portio_list(isa, &d->portio_page,
+                             d->page_base, page_portio_list, d,
                              "dma-page");
     if (d->pageh_base >= 0) {
-        isa_register_portio_list(isa, d->pageh_base, pageh_portio_list, d,
+        isa_register_portio_list(isa, &d->portio_pageh,
+                                 d->pageh_base, pageh_portio_list, d,
                                  "dma-pageh");
     }
 
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 081c9eb..95790cc 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -2617,10 +2617,12 @@ void ide_init_ioport(IDEBus *bus, ISADevice *dev, int iobase, int iobase2)
 {
     /* ??? Assume only ISA and PCI configurations, and that the PCI-ISA
        bridge has been setup properly to always register with ISA.  */
-    isa_register_portio_list(dev, iobase, ide_portio_list, bus, "ide");
+    isa_register_portio_list(dev, &bus->portio_list,
+                             iobase, ide_portio_list, bus, "ide");
 
     if (iobase2) {
-        isa_register_portio_list(dev, iobase2, ide_portio2_list, bus, "ide");
+        isa_register_portio_list(dev, &bus->portio2_list,
+                                 iobase2, ide_portio2_list, bus, "ide");
     }
 }
 
diff --git a/hw/isa/isa-bus.c b/hw/isa/isa-bus.c
index ce74db2..9d07b11 100644
--- a/hw/isa/isa-bus.c
+++ b/hw/isa/isa-bus.c
@@ -131,24 +131,20 @@ void isa_register_ioport(ISADevice *dev, MemoryRegion *io, uint16_t start)
     isa_init_ioport(dev, start);
 }
 
-void isa_register_portio_list(ISADevice *dev, uint16_t start,
+void isa_register_portio_list(ISADevice *dev,
+                              PortioList *piolist, uint16_t start,
                               const MemoryRegionPortio *pio_start,
                               void *opaque, const char *name)
 {
-    PortioList piolist;
+    assert(piolist && !piolist->owner);
 
     /* START is how we should treat DEV, regardless of the actual
        contents of the portio array.  This is how the old code
        actually handled e.g. the FDC device.  */
     isa_init_ioport(dev, start);
 
-    /* FIXME: the device should store created PortioList in its state.  Note
-       that DEV can be NULL here and that single device can register several
-       portio lists.  Current implementation is leaking memory allocated
-       in portio_list_init.  The leak is not critical because it happens only
-       at initialization time.  */
-    portio_list_init(&piolist, OBJECT(dev), pio_start, opaque, name);
-    portio_list_add(&piolist, isabus->address_space_io, start);
+    portio_list_init(piolist, OBJECT(dev), pio_start, opaque, name);
+    portio_list_add(piolist, isabus->address_space_io, start);
 }
 
 static void isa_device_init(Object *obj)
diff --git a/include/hw/ide/internal.h b/include/hw/ide/internal.h
index 7824bc3..a6dd2c3 100644
--- a/include/hw/ide/internal.h
+++ b/include/hw/ide/internal.h
@@ -480,6 +480,8 @@ struct IDEBus {
     uint8_t retry_unit;
     int64_t retry_sector_num;
     uint32_t retry_nsector;
+    PortioList portio_list;
+    PortioList portio2_list;
 };
 
 #define TYPE_IDE_DEVICE "ide-device"
diff --git a/include/hw/isa/i8257.h b/include/hw/isa/i8257.h
index aa211c0..88a2766 100644
--- a/include/hw/isa/i8257.h
+++ b/include/hw/isa/i8257.h
@@ -36,6 +36,8 @@ typedef struct I8257State {
     QEMUBH *dma_bh;
     bool dma_bh_scheduled;
     int running;
+    PortioList portio_page;
+    PortioList portio_pageh;
 } I8257State;
 
 #endif
diff --git a/include/hw/isa/isa.h b/include/hw/isa/isa.h
index 7693ac5..c2fdd70 100644
--- a/include/hw/isa/isa.h
+++ b/include/hw/isa/isa.h
@@ -134,12 +134,15 @@ void isa_register_ioport(ISADevice *dev, MemoryRegion *io, uint16_t start);
  * device and use the legacy portio routines.
  *
  * @dev: the ISADevice against which these are registered; may be NULL.
+ * @piolist: the PortioList associated with the io ports
  * @start: the base I/O port against which the portio->offset is applied.
  * @portio: the ports, sorted by offset.
  * @opaque: passed into the portio callbacks.
  * @name: passed into memory_region_init_io.
  */
-void isa_register_portio_list(ISADevice *dev, uint16_t start,
+void isa_register_portio_list(ISADevice *dev,
+                              PortioList *piolist,
+                              uint16_t start,
                               const MemoryRegionPortio *portio,
                               void *opaque, const char *name);
 
-- 
2.9.0

  parent reply	other threads:[~2016-07-28 14:39 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-28 14:37 [Qemu-devel] [PATCH v2 00/37] Various memory leak fixes marcandre.lureau
2016-07-28 14:37 ` [Qemu-devel] [PATCH v2 01/37] build-sys: use an override for CFLAGS filter marcandre.lureau
2016-07-28 14:37 ` [Qemu-devel] [PATCH v2 02/37] tests: fix test-qga leaks marcandre.lureau
2016-07-28 14:37 ` [Qemu-devel] [PATCH v2 03/37] qga: free the whole blacklist marcandre.lureau
2016-07-28 21:18   ` Eric Blake
2016-07-28 21:36     ` Marc-André Lureau
2016-07-28 21:39       ` Eric Blake
2016-07-28 14:37 ` [Qemu-devel] [PATCH v2 04/37] qga: free remaining leaking state marcandre.lureau
2016-07-28 21:22   ` Eric Blake
2016-07-28 14:37 ` [Qemu-devel] [PATCH v2 05/37] tests: fix test-cutils leaks marcandre.lureau
2016-07-28 14:37 ` [Qemu-devel] [PATCH v2 06/37] tests: fix test-vmstate leaks marcandre.lureau
2016-07-28 14:37 ` [Qemu-devel] [PATCH v2 07/37] tests: fix test-iov leaks marcandre.lureau
2016-07-28 14:37 ` [Qemu-devel] [PATCH v2 08/37] qdist: fix entries memory leak marcandre.lureau
2016-07-28 14:37 ` [Qemu-devel] [PATCH v2 09/37] tests: fix check-qom-interface leaks marcandre.lureau
2016-07-28 14:37 ` [Qemu-devel] [PATCH v2 10/37] tests: fix check-qom-proplist leaks marcandre.lureau
2016-07-28 14:37 ` [Qemu-devel] [PATCH v2 11/37] tests: fix small leak in test-io-channel-command marcandre.lureau
2016-07-28 21:44   ` Eric Blake
2016-07-28 14:37 ` [Qemu-devel] [PATCH v2 12/37] tests: fix leak in test-string-input-visitor marcandre.lureau
2016-07-28 14:37 ` marcandre.lureau [this message]
2016-08-01 12:42   ` [Qemu-devel] [PATCH v2 13/37] portio: keep references on portio Paolo Bonzini
2016-07-28 14:37 ` [Qemu-devel] [PATCH v2 14/37] numa: do not leak NumaOptions marcandre.lureau
2016-07-28 14:37 ` [Qemu-devel] [PATCH v2 15/37] pc: simplify passing qemu_irq marcandre.lureau
2016-07-28 14:37 ` [Qemu-devel] [PATCH v2 16/37] pc: don't leak a20_line marcandre.lureau
2016-07-28 14:37 ` [Qemu-devel] [PATCH v2 17/37] machine: use class base init generated name marcandre.lureau
2016-07-28 14:37 ` [Qemu-devel] [PATCH v2 18/37] acpi-build: fix array leak marcandre.lureau
2016-07-28 14:37 ` [Qemu-devel] [PATCH v2 19/37] char: disconnect peer when qemu_chr_free() marcandre.lureau
2016-07-28 21:49   ` Eric Blake
2016-08-01 12:48   ` Paolo Bonzini
2016-07-28 14:37 ` [Qemu-devel] [PATCH v2 20/37] char: free MuxDriver when closing marcandre.lureau
2016-07-28 22:02   ` Eric Blake
2016-08-01 12:50   ` Paolo Bonzini
2016-08-01 12:52     ` Paolo Bonzini
2016-07-28 14:37 ` [Qemu-devel] [PATCH v2 21/37] tests: fix qom-test leaks marcandre.lureau
2016-07-28 14:37 ` [Qemu-devel] [PATCH v2 22/37] pc: free i8259 marcandre.lureau
2016-07-28 14:37 ` [Qemu-devel] [PATCH v2 23/37] pc: keep gsi reference marcandre.lureau
2016-07-28 14:37 ` [Qemu-devel] [PATCH v2 24/37] ahci: free irqs array marcandre.lureau
2016-07-28 14:37 ` [Qemu-devel] [PATCH v2 25/37] sd: free timer marcandre.lureau
2016-07-28 14:37 ` [Qemu-devel] [PATCH v2 26/37] qjson: free str marcandre.lureau
2016-07-28 14:37 ` [Qemu-devel] [PATCH v2 27/37] virtio-input: free config list marcandre.lureau
2016-07-28 14:37 ` [Qemu-devel] [PATCH v2 28/37] ipmi: free extern timer marcandre.lureau
2016-07-28 14:38 ` [Qemu-devel] [PATCH v2 29/37] usb: free USBDevice.strings marcandre.lureau
2016-07-28 14:38 ` [Qemu-devel] [PATCH v2 30/37] tests: free a bunch of qmp responses marcandre.lureau
2016-07-28 14:38 ` [Qemu-devel] [PATCH v2 31/37] usb: free leaking path marcandre.lureau
2016-07-28 14:38 ` [Qemu-devel] [PATCH v2 32/37] bus: simplify name handling marcandre.lureau
2016-07-28 22:05   ` Eric Blake
2016-07-28 14:38 ` [Qemu-devel] [PATCH v2 33/37] tests: add qtest_add_data_func_full marcandre.lureau
2016-07-28 22:16   ` Eric Blake
2016-07-29  8:48     ` Marc-André Lureau
2016-08-01 12:53       ` Eric Blake
2016-07-28 14:38 ` [Qemu-devel] [PATCH v2 34/37] tests: pc-cpu-test leaks fixes marcandre.lureau
2016-07-28 22:17   ` Eric Blake
2016-07-28 14:38 ` [Qemu-devel] [PATCH v2 35/37] tests: fix rsp leak in postcopy-test marcandre.lureau
2016-07-28 14:38 ` [Qemu-devel] [PATCH v2 36/37] ahci: fix sglist leak on retry marcandre.lureau
2016-07-28 14:38 ` [Qemu-devel] [PATCH v2 37/37] tests: fix postcopy-test leaks marcandre.lureau
2016-07-28 22:18   ` Eric Blake
2016-07-28 21:49 ` [Qemu-devel] [PATCH v2 00/37] Various memory leak fixes Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160728143808.13707-14-marcandre.lureau@redhat.com \
    --to=marcandre.lureau@redhat.com \
    --cc=eblake@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.