Re: [PATCH] Allow passing platform_data to devices attached to AC97 bus

Russell King - ARM Linux
2009-07-21T22:33:53Z

On Wed, Jul 22, 2009 at 12:13:12AM +0200, Marek Vasut wrote:
> + ret = set_irq_type(gpio_to_irq(pdata->charge_gpio),
> + IRQ_TYPE_EDGE_BOTH);
> + if (ret)
> + goto err2;
> + ret = request_irq(gpio_to_irq(pdata->charge_gpio),
> + wm97xx_chrg_irq, IRQF_DISABLED,
> + "AC Detect", 0);

This should be done as one call to request_irq().

Why?

If the IRQ is already in use by something else, calling set_irq_type()
will stamp on that other user, enforcing the change of configuration.
request_irq() will then fail, leaving the IRQ configuration buggered.

Combining the two allows request_irq() to fail if the IRQ line is busy.
If it isn't busy, it will configure the IRQ line prior to enabling the
IRQ. If the IRQ is shared and sharing is permitted, it will fail if
the configuration is not compatible with the existing IRQ configuration.

set_irq_type() should only be used very sparingly and when there's no
other option.