[Lguest] [PATCH] lguest: Make sure the interrupt is allocated correctly by lguest_setup_irq (ie check the return value of irq_alloc_desc_at for -ENOMEM)

Stratos Psomadakis psomas at cslab.ece.ntua.gr
Thu May 19 21:33:02 EST 2011


I saw the FIXME while reading the lguest documentation, and ... I tried to fix
it. :)

I think we only have to check for -ENOMEM, since all the other return values
are harmless (ie -EEXIST) and -EINVAL cannot be returned (normally).

Signed-off-by: Stratos Psomadakis <psomas at cslab.ece.ntua.gr>
---
 arch/x86/lguest/boot.c         |   15 ++++++++++-----
 drivers/lguest/lguest_device.c |    6 ++++--
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
index 1cd6089..fd392e7 100644
--- a/arch/x86/lguest/boot.c
+++ b/arch/x86/lguest/boot.c
@@ -840,15 +840,20 @@ static void __init lguest_init_IRQ(void)
  * With CONFIG_SPARSE_IRQ, interrupt descriptors are allocated as-needed, so
  * rather than set them in lguest_init_IRQ we are called here every time an
  * lguest device needs an interrupt.
- *
- * FIXME: irq_alloc_desc_at() can fail due to lack of memory, we should
- * pass that up!
  */
-void lguest_setup_irq(unsigned int irq)
+int lguest_setup_irq(unsigned int irq)
 {
-	irq_alloc_desc_at(irq, 0);
+	int err = 0;
+
+	err = irq_alloc_desc_at(irq, 0);
+	if (err  == -ENOMEM)
+		goto out;
+	
 	irq_set_chip_and_handler_name(irq, &lguest_irq_controller,
 				      handle_level_irq, "level");
+
+out:
+	return err;
 }
 
 /*
diff --git a/drivers/lguest/lguest_device.c b/drivers/lguest/lguest_device.c
index 69c84a1..3fadfe5 100644
--- a/drivers/lguest/lguest_device.c
+++ b/drivers/lguest/lguest_device.c
@@ -233,7 +233,7 @@ static void lg_notify(struct virtqueue *vq)
 }
 
 /* An extern declaration inside a C file is bad form.  Don't do it. */
-extern void lguest_setup_irq(unsigned int irq);
+extern int lguest_setup_irq(unsigned int irq);
 
 /*
  * This routine finds the Nth virtqueue described in the configuration of
@@ -294,7 +294,9 @@ static struct virtqueue *lg_find_vq(struct virtio_device *vdev,
 	}
 
 	/* Make sure the interrupt is allocated. */
-	lguest_setup_irq(lvq->config.irq);
+	err = lguest_setup_irq(lvq->config.irq);
+	if (err == -ENOMEM)
+		goto unmap;
 
 	/*
 	 * Tell the interrupt for this virtqueue to go to the virtio_ring
-- 
1.7.5.rc3



More information about the Lguest mailing list