From: Stefan Weil <sw@weilnetz.de>
To: qemu-devel@nongnu.org
Cc: Stefan Weil <sw@weilnetz.de>
Subject: [Qemu-devel] [PATCH 1/3] irq: Add new function qemu_init_irqs
Date: Mon, 24 Sep 2012 21:08:48 +0200 [thread overview]
Message-ID: <1348513730-7485-2-git-send-email-sw@weilnetz.de> (raw)
In-Reply-To: <1348513730-7485-1-git-send-email-sw@weilnetz.de>
It is used to avoid dynamic memory allocation for qemu_irq arrays
with known size or single qemu_irq variables.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
---
hw/irq.c | 15 +++++++++------
hw/irq.h | 4 ++++
2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/hw/irq.c b/hw/irq.c
index d413a0b..fd284b0 100644
--- a/hw/irq.c
+++ b/hw/irq.c
@@ -38,14 +38,11 @@ void qemu_set_irq(qemu_irq irq, int level)
irq->handler(irq->opaque, irq->n, level);
}
-qemu_irq *qemu_allocate_irqs(qemu_irq_handler handler, void *opaque, int n)
+void qemu_init_irqs(qemu_irq_handler handler, void *opaque,
+ qemu_irq *s, int n)
{
- qemu_irq *s;
- struct IRQState *p;
int i;
-
- s = (qemu_irq *)g_malloc0(sizeof(qemu_irq) * n);
- p = (struct IRQState *)g_malloc0(sizeof(struct IRQState) * n);
+ struct IRQState *p = g_new0(struct IRQState, n);
for (i = 0; i < n; i++) {
p->handler = handler;
p->opaque = opaque;
@@ -53,6 +50,12 @@ qemu_irq *qemu_allocate_irqs(qemu_irq_handler handler, void *opaque, int n)
s[i] = p;
p++;
}
+}
+
+qemu_irq *qemu_allocate_irqs(qemu_irq_handler handler, void *opaque, int n)
+{
+ qemu_irq *s = g_new(qemu_irq, n);
+ qemu_init_irqs(handler, opaque, s, n);
return s;
}
diff --git a/hw/irq.h b/hw/irq.h
index 56c55f0..368b88f 100644
--- a/hw/irq.h
+++ b/hw/irq.h
@@ -23,6 +23,10 @@ static inline void qemu_irq_pulse(qemu_irq irq)
qemu_set_irq(irq, 0);
}
+/* Initialize an array of N IRQs. */
+void qemu_init_irqs(qemu_irq_handler handler, void *opaque,
+ qemu_irq *irqs, int n);
+
/* Returns an array of N IRQs. */
qemu_irq *qemu_allocate_irqs(qemu_irq_handler handler, void *opaque, int n);
void qemu_free_irqs(qemu_irq *s);
--
1.7.10
next prev parent reply other threads:[~2012-09-24 19:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-24 19:08 [Qemu-devel] [PATCH 0/3] Fix some memory leaks caused by qemu_allocate_irqs Stefan Weil
2012-09-24 19:08 ` Stefan Weil [this message]
2012-09-24 19:26 ` [Qemu-devel] [PATCH 1/3] irq: Add new function qemu_init_irqs Peter Maydell
2012-09-24 19:08 ` [Qemu-devel] [PATCH 2/3] hw/arm_timer: Fix memory leak (detected by Valgrind) Stefan Weil
2012-09-24 19:08 ` [Qemu-devel] [PATCH 3/3] hw/spitz: Fix memory leaks " Stefan Weil
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=1348513730-7485-2-git-send-email-sw@weilnetz.de \
--to=sw@weilnetz.de \
--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).