irq: Allocate IRQs individually
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>
This commit is contained in:
parent
f3c7d0389f
commit
f173d57a4c
@ -152,7 +152,7 @@ static void multi_serial_pci_exit(PCIDevice *dev)
|
|||||||
g_free(pci->name[i]);
|
g_free(pci->name[i]);
|
||||||
}
|
}
|
||||||
memory_region_destroy(&pci->iobar);
|
memory_region_destroy(&pci->iobar);
|
||||||
qemu_free_irqs(pci->irqs);
|
qemu_free_irqs(pci->irqs, pci->ports);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const VMStateDescription vmstate_pci_serial = {
|
static const VMStateDescription vmstate_pci_serial = {
|
||||||
|
@ -42,23 +42,14 @@ qemu_irq *qemu_extend_irqs(qemu_irq *old, int n_old, qemu_irq_handler handler,
|
|||||||
void *opaque, int n)
|
void *opaque, int n)
|
||||||
{
|
{
|
||||||
qemu_irq *s;
|
qemu_irq *s;
|
||||||
struct IRQState *p;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!old) {
|
if (!old) {
|
||||||
n_old = 0;
|
n_old = 0;
|
||||||
}
|
}
|
||||||
s = old ? g_renew(qemu_irq, old, n + n_old) : g_new(qemu_irq, n);
|
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) :
|
for (i = n_old; i < n + n_old; i++) {
|
||||||
g_new(struct IRQState, n);
|
s[i] = qemu_allocate_irq(handler, opaque, i);
|
||||||
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++;
|
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
@ -80,9 +71,12 @@ qemu_irq qemu_allocate_irq(qemu_irq_handler handler, void *opaque, int n)
|
|||||||
return irq;
|
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);
|
g_free(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -949,7 +949,7 @@ static void device_finalize(Object *obj)
|
|||||||
|
|
||||||
QLIST_FOREACH_SAFE(ngl, &dev->gpios, node, next) {
|
QLIST_FOREACH_SAFE(ngl, &dev->gpios, node, next) {
|
||||||
QLIST_REMOVE(ngl, node);
|
QLIST_REMOVE(ngl, node);
|
||||||
qemu_free_irqs(ngl->in);
|
qemu_free_irqs(ngl->in, ngl->num_in);
|
||||||
g_free(ngl->name);
|
g_free(ngl->name);
|
||||||
g_free(ngl);
|
g_free(ngl);
|
||||||
/* ngl->out irqs are owned by the other end and should not be freed
|
/* ngl->out irqs are owned by the other end and should not be freed
|
||||||
|
@ -66,7 +66,7 @@ static void ipack_device_unrealize(DeviceState *dev, Error **errp)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
qemu_free_irqs(idev->irq);
|
qemu_free_irqs(idev->irq, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Property ipack_device_props[] = {
|
static Property ipack_device_props[] = {
|
||||||
|
@ -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,
|
qemu_irq *qemu_extend_irqs(qemu_irq *old, int n_old, qemu_irq_handler handler,
|
||||||
void *opaque, int n);
|
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);
|
void qemu_free_irq(qemu_irq irq);
|
||||||
|
|
||||||
/* Returns a new IRQ with opposite polarity. */
|
/* Returns a new IRQ with opposite polarity. */
|
||||||
|
Loading…
Reference in New Issue
Block a user