From: "Andreas Färber" <afaerber@suse.de>
To: qemu-devel@nongnu.org
Cc: "Peter Crosthwaite" <peter.crosthwaite@xilinx.com>,
agarcia@igalia.com, "Andreas Färber" <afaerber@suse.de>,
mst@redhat.com
Subject: [Qemu-devel] [PULL 4/5] irq: Allocate IRQs individually
Date: Tue, 1 Jul 2014 05:08:12 +0200 [thread overview]
Message-ID: <1404184093-966-5-git-send-email-afaerber@suse.de> (raw)
In-Reply-To: <1404184093-966-1-git-send-email-afaerber@suse.de>
From: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
Allocate each IRQ individually on array allocations. This prepares for
QOMification of IRQs, where pointers to individual IRQs may be taken
and handed around for usage as QOM Links. The g_renew() scheme used here
is too fragile and would break all existing links should an IRQ list
be extended.
We now have to pass the IRQ count to qemu_free_irqs(). We have so few
call sites however, so this change is reasonably trivial.
Cc: agarcia@igalia.com
Cc: mst@redhat.com
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Acked-by: Alberto Garcia <agarcia@igalia.com>
Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/char/serial-pci.c | 2 +-
hw/core/irq.c | 20 +++++++-------------
hw/core/qdev.c | 2 +-
hw/ipack/ipack.c | 2 +-
include/hw/irq.h | 2 +-
5 files changed, 11 insertions(+), 17 deletions(-)
diff --git a/hw/char/serial-pci.c b/hw/char/serial-pci.c
index 6c25296..f53bb9c 100644
--- a/hw/char/serial-pci.c
+++ b/hw/char/serial-pci.c
@@ -152,7 +152,7 @@ static void multi_serial_pci_exit(PCIDevice *dev)
g_free(pci->name[i]);
}
memory_region_destroy(&pci->iobar);
- qemu_free_irqs(pci->irqs);
+ qemu_free_irqs(pci->irqs, pci->ports);
}
static const VMStateDescription vmstate_pci_serial = {
diff --git a/hw/core/irq.c b/hw/core/irq.c
index 3d284c6..bc982a7 100644
--- a/hw/core/irq.c
+++ b/hw/core/irq.c
@@ -42,23 +42,14 @@ qemu_irq *qemu_extend_irqs(qemu_irq *old, int n_old, qemu_irq_handler handler,
void *opaque, int n)
{
qemu_irq *s;
- struct IRQState *p;
int i;
if (!old) {
n_old = 0;
}
s = old ? g_renew(qemu_irq, old, n + n_old) : g_new(qemu_irq, n);
- p = old ? g_renew(struct IRQState, s[0], n + n_old) :
- g_new(struct IRQState, n);
- for (i = 0; i < n + n_old; i++) {
- if (i >= n_old) {
- p->handler = handler;
- p->opaque = opaque;
- p->n = i;
- }
- s[i] = p;
- p++;
+ for (i = n_old; i < n + n_old; i++) {
+ s[i] = qemu_allocate_irq(handler, opaque, i);
}
return s;
}
@@ -80,9 +71,12 @@ qemu_irq qemu_allocate_irq(qemu_irq_handler handler, void *opaque, int n)
return irq;
}
-void qemu_free_irqs(qemu_irq *s)
+void qemu_free_irqs(qemu_irq *s, int n)
{
- g_free(s[0]);
+ int i;
+ for (i = 0; i < n; i++) {
+ qemu_free_irq(s[i]);
+ }
g_free(s);
}
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index d1eba3c..371b427 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -949,7 +949,7 @@ static void device_finalize(Object *obj)
QLIST_FOREACH_SAFE(ngl, &dev->gpios, node, next) {
QLIST_REMOVE(ngl, node);
- qemu_free_irqs(ngl->in);
+ qemu_free_irqs(ngl->in, ngl->num_in);
g_free(ngl->name);
g_free(ngl);
/* ngl->out irqs are owned by the other end and should not be freed
diff --git a/hw/ipack/ipack.c b/hw/ipack/ipack.c
index ef032e6..59bfe28 100644
--- a/hw/ipack/ipack.c
+++ b/hw/ipack/ipack.c
@@ -66,7 +66,7 @@ static void ipack_device_unrealize(DeviceState *dev, Error **errp)
return;
}
- qemu_free_irqs(idev->irq);
+ qemu_free_irqs(idev->irq, 2);
}
static Property ipack_device_props[] = {
diff --git a/include/hw/irq.h b/include/hw/irq.h
index d08bc02..9f34c96 100644
--- a/include/hw/irq.h
+++ b/include/hw/irq.h
@@ -42,7 +42,7 @@ qemu_irq qemu_allocate_irq(qemu_irq_handler handler, void *opaque, int n);
qemu_irq *qemu_extend_irqs(qemu_irq *old, int n_old, qemu_irq_handler handler,
void *opaque, int n);
-void qemu_free_irqs(qemu_irq *s);
+void qemu_free_irqs(qemu_irq *s, int n);
void qemu_free_irq(qemu_irq irq);
/* Returns a new IRQ with opposite polarity. */
--
1.8.4.5
next prev parent reply other threads:[~2014-07-01 3:08 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-01 3:08 [Qemu-devel] [PULL 0/5] QOM devices patch queue 2014-07-01 Andreas Färber
2014-07-01 3:08 ` [Qemu-devel] [PULL 1/5] qom: Remove parent pointer when unparenting Andreas Färber
2014-07-01 3:08 ` [Qemu-devel] [PULL 2/5] sdhci: Fix misuse of qemu_free_irqs() Andreas Färber
2014-07-01 3:08 ` [Qemu-devel] [PULL 3/5] hw: Fix qemu_allocate_irqs() leaks Andreas Färber
2014-07-01 3:08 ` Andreas Färber [this message]
2014-07-01 3:08 ` [Qemu-devel] [PULL 5/5] irq: Slim conversion of qemu_irq to QOM Andreas Färber
2014-07-01 10:55 ` [Qemu-devel] [PULL 0/5] QOM devices patch queue 2014-07-01 Peter Maydell
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=1404184093-966-5-git-send-email-afaerber@suse.de \
--to=afaerber@suse.de \
--cc=agarcia@igalia.com \
--cc=mst@redhat.com \
--cc=peter.crosthwaite@xilinx.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).