ALSA: AACI: fix multiple IRQ claiming

Claiming the IRQ each time a playback or capture interface is opened
is wasteful; the second copy of the registered handler is identical to
the first and just wastes resources.  Track the number of opens and
only register the handler when necessary.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
diff --git a/sound/arm/aaci.c b/sound/arm/aaci.c
index 24d3013..65685af 100644
--- a/sound/arm/aaci.c
+++ b/sound/arm/aaci.c
@@ -370,7 +370,7 @@
 			   struct aaci_runtime *aacirun)
 {
 	struct snd_pcm_runtime *runtime = substream->runtime;
-	int ret;
+	int ret = 0;
 
 	aacirun->substream = substream;
 	runtime->private_data = aacirun;
@@ -391,14 +391,15 @@
 	 */
 	runtime->hw.fifo_size = aaci->fifosize * 2;
 
-	ret = request_irq(aaci->dev->irq[0], aaci_irq, IRQF_SHARED|IRQF_DISABLED,
-			  DRIVER_NAME, aaci);
-	if (ret)
-		goto out;
+	mutex_lock(&aaci->irq_lock);
+	if (!aaci->users++) {
+		ret = request_irq(aaci->dev->irq[0], aaci_irq,
+			   IRQF_SHARED | IRQF_DISABLED, DRIVER_NAME, aaci);
+		if (ret != 0)
+			aaci->users--;
+	}
+	mutex_unlock(&aaci->irq_lock);
 
-	return 0;
-
- out:
 	return ret;
 }
 
@@ -414,7 +415,11 @@
 	WARN_ON(aacirun->cr & CR_EN);
 
 	aacirun->substream = NULL;
-	free_irq(aaci->dev->irq[0], aaci);
+
+	mutex_lock(&aaci->irq_lock);
+	if (!--aaci->users)
+		free_irq(aaci->dev->irq[0], aaci);
+	mutex_unlock(&aaci->irq_lock);
 
 	return 0;
 }
@@ -943,6 +948,7 @@
 
 	aaci = card->private_data;
 	mutex_init(&aaci->ac97_sem);
+	mutex_init(&aaci->irq_lock);
 	aaci->card = card;
 	aaci->dev = dev;