[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)

Rusty Russell rusty at rustcorp.com.au
Sat May 21 14:33:34 EST 2011


On Thu, 19 May 2011 14:33:02 +0300, Stratos Psomadakis <psomas at cslab.ece.ntua.gr> wrote:
> I saw the FIXME while reading the lguest documentation, and ... I tried to fix
> it. :)
> 

Hi Stratos,


   Thanks for your patch.  Comments below:

> 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).

We should probably pass back any error we receive, however, for
simplicity, futureproofing and clarity.

> -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;
>  }

No need to initialize err in the declaration.

>  
>  	/* Make sure the interrupt is allocated. */
> -	lguest_setup_irq(lvq->config.irq);
> +	err = lguest_setup_irq(lvq->config.irq);
> +	if (err == -ENOMEM)
> +		goto unmap;

This should be goto destroy_vring.

Cheers,
Rusty.


More information about the Lguest mailing list