Skip to contentSkip to conversation

ALSA: Fix synchronize_irq() bugs, redundancies

PATCH In review Jeff Garzik 3 participants 4 messages Apr 21, 2008 – Apr 22, 2008

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 ALSA: Fix synchronize_irq() bugs, redundancies

free_irq() calls synchronize_irq() for you, so there is no need for drivers to manually do the same thing (again). Thus, calls where sync-irq immediately precedes free-irq can be simplified.

However, during this audit several bugs were noticed, where free-irq is preceded by a "irq >= 0" check... but the sync-irq call is not covered by the same check.

So, where sync-irq could not be eliminated completely, the missing check was added.

---
 drivers/media/video/cx88/cx88-alsa.c       |    4 +---
 drivers/media/video/saa7134/saa7134-alsa.c |    4 +---
 sound/pci/ad1889.c                         |    2 --
 sound/pci/ali5451/ali5451.c                |    4 +---
 sound/pci/atiixp.c                         |    2 +-
 sound/pci/atiixp_modem.c                   |    2 +-
 sound/pci/au88x0/au88x0.c                  |    2 --
 sound/pci/azt3328.c                        |    3 ++-
 sound/pci/cmipci.c                         |    2 --
 sound/pci/ens1370.c                        |    3 ++-
 sound/pci/es1938.c                         |    5 +----
 sound/pci/es1968.c                         |    3 ++-
 sound/pci/hda/hda_intel.c                  |    5 +----
 sound/pci/ice1712/ice1712.c                |    5 ++---
 sound/pci/ice1712/ice1724.c                |    4 +---
 sound/pci/intel8x0.c                       |    3 +--
 sound/pci/intel8x0m.c                      |    3 ++-
 sound/pci/maestro3.c                       |    4 +---
 sound/pci/oxygen/oxygen_lib.c              |    4 +---
 sound/pci/sis7019.c                        |    1 -
 sound/pci/via82xx.c                        |    2 +-
 sound/pci/via82xx_modem.c                  |    2 +-
 22 files changed, 23 insertions(+), 46 deletions(-)
drivers/media/video/cx88/cx88-alsa.c +1 -3
index 316b106..03feb5b 100644
@@ -690,10 +690,8 @@ MODULE_DEVICE_TABLE(pci, cx88_audio_pci_tbl);
 static int snd_cx88_free(snd_cx88_card_t *chip)
 {
 
-	if (chip->irq >= 0){
-		synchronize_irq(chip->irq);
+	if (chip->irq >= 0)
 		free_irq(chip->irq, chip);
-	}
 
 	cx88_core_put(chip->core,chip->pci);
 
drivers/media/video/saa7134/saa7134-alsa.c +1 -3
index 047add8..ec6bdb9 100644
@@ -954,10 +954,8 @@ static void snd_saa7134_free(struct snd_card * card)
 	if (chip->dev->dmasound.priv_data == NULL)
 		return;
 
-	if (chip->irq >= 0) {
-		synchronize_irq(chip->irq);
+	if (chip->irq >= 0)
 		free_irq(chip->irq, &chip->dev->dmasound);
-	}
 
 	chip->dev->dmasound.priv_data = NULL;
 
sound/pci/ad1889.c +0 -2
index a66d515..8d65ef6 100644
@@ -854,8 +854,6 @@ snd_ad1889_free(struct snd_ad1889 *chip)
 
 	spin_unlock_irq(&chip->lock);
 
-	synchronize_irq(chip->irq);
-	
 	if (chip->irq >= 0)
 		free_irq(chip->irq, chip);
 
sound/pci/ali5451/ali5451.c +1 -3
index 6a905ed..01d133c 100644
@@ -2047,10 +2047,8 @@ static int snd_ali_free(struct snd_ali * codec)
 {
 	if (codec->hw_initialized)
 		snd_ali_disable_address_interrupt(codec);
-	if (codec->irq >= 0) {
-		synchronize_irq(codec->irq);
+	if (codec->irq >= 0)
 		free_irq(codec->irq, codec);
-	}
 	if (codec->port)
 		pci_release_regions(codec->pci);
 	pci_disable_device(codec->pci);
sound/pci/atiixp.c +1 -1
index 4594186..457228f 100644
@@ -1553,7 +1553,7 @@ static int snd_atiixp_free(struct atiixp *chip)
 	if (chip->irq < 0)
 		goto __hw_end;
 	snd_atiixp_chip_stop(chip);
-	synchronize_irq(chip->irq);
+
       __hw_end:
 	if (chip->irq >= 0)
 		free_irq(chip->irq, chip);
sound/pci/atiixp_modem.c +1 -1
index a67a869..d457a32 100644
@@ -1197,7 +1197,7 @@ static int snd_atiixp_free(struct atiixp_modem *chip)
 	if (chip->irq < 0)
 		goto __hw_end;
 	snd_atiixp_chip_stop(chip);
-	synchronize_irq(chip->irq);
+
       __hw_end:
 	if (chip->irq >= 0)
 		free_irq(chip->irq, chip);
sound/pci/au88x0/au88x0.c +0 -2
index 26819e2..68368e4 100644
@@ -126,7 +126,6 @@ static int snd_vortex_dev_free(struct snd_device *device)
 	vortex_gameport_unregister(vortex);
 	vortex_core_shutdown(vortex);
 	// Take down PCI interface.
-	synchronize_irq(vortex->irq);
 	free_irq(vortex->irq, vortex);
 	iounmap(vortex->mmio);
 	pci_release_regions(vortex->pci_dev);
@@ -220,7 +219,6 @@ snd_vortex_create(struct snd_card *card, struct pci_dev *pci, vortex_t ** rchip)
 	return 0;
 
       alloc_out:
-	synchronize_irq(chip->irq);
 	free_irq(chip->irq, chip);
       irq_out:
 	vortex_core_shutdown(chip);
sound/pci/azt3328.c +2 -1
index 4e71a55..c28fbaa 100644
@@ -1514,7 +1514,8 @@ snd_azf3328_free(struct snd_azf3328 *chip)
 	/* well, at least we know how to disable the timer IRQ */
 	snd_azf3328_codec_outb(chip, IDX_IO_TIMER_VALUE + 3, 0x00);
 
-        synchronize_irq(chip->irq);
+	if (chip->irq >= 0)
+        	synchronize_irq(chip->irq);
 __end_hw:
 	snd_azf3328_free_joystick(chip);
         if (chip->irq >= 0)
sound/pci/cmipci.c +0 -2
index 135f308..342dab3 100644
@@ -2932,8 +2932,6 @@ static int snd_cmipci_free(struct cmipci *cm)
 		/* reset mixer */
 		snd_cmipci_mixer_write(cm, 0, 0);
 
-		synchronize_irq(cm->irq);
-
 		free_irq(cm->irq, cm);
 	}
 
sound/pci/ens1370.c +2 -1
index 72d85a5..09652f3 100644
@@ -1910,7 +1910,8 @@ static int snd_ensoniq_free(struct ensoniq *ensoniq)
 	outl(0, ES_REG(ensoniq, CONTROL));	/* switch everything off */
 	outl(0, ES_REG(ensoniq, SERIAL));	/* clear serial interface */
 #endif
-	synchronize_irq(ensoniq->irq);
+	if (ensoniq->irq >= 0)
+		synchronize_irq(ensoniq->irq);
 	pci_set_power_state(ensoniq->pci, 3);
       __hw_end:
 #ifdef CHIP1370
sound/pci/es1938.c +1 -4
index 1a314fa..84fac1f 100644
@@ -1488,7 +1488,6 @@ static int es1938_suspend(struct pci_dev *pci, pm_message_t state)
 
 	outb(0x00, SLIO_REG(chip, IRQCONTROL)); /* disable irqs */
 	if (chip->irq >= 0) {
-		synchronize_irq(chip->irq);
 		free_irq(chip->irq, chip);
 		chip->irq = -1;
 	}
@@ -1578,10 +1577,8 @@ static int snd_es1938_free(struct es1938 *chip)
 
 	snd_es1938_free_gameport(chip);
 
-	if (chip->irq >= 0) {
-		synchronize_irq(chip->irq);
+	if (chip->irq >= 0)
 		free_irq(chip->irq, chip);
-	}
 	pci_release_regions(chip->pci);
 	pci_disable_device(chip->pci);
 	kfree(chip);
sound/pci/es1968.c +2 -1
index 7d911a1..3e294b6 100644
@@ -2456,7 +2456,8 @@ static inline void snd_es1968_free_gameport(struct es1968 *chip) { }
 static int snd_es1968_free(struct es1968 *chip)
 {
 	if (chip->io_port) {
-		synchronize_irq(chip->irq);
+		if (chip->irq >= 0)
+			synchronize_irq(chip->irq);
 		outw(1, chip->io_port + 0x04); /* clear WP interrupts */
 		outw(0, chip->io_port + ESM_PORT_HOST_IRQ); /* disable IRQ */
 	}
sound/pci/hda/hda_intel.c +1 -4
index 4be36c8..ddf6e9c 100644
@@ -1593,7 +1593,6 @@ static int azx_suspend(struct pci_dev *pci, pm_message_t state)
 		snd_hda_suspend(chip->bus, state);
 	azx_stop_chip(chip);
 	if (chip->irq >= 0) {
-		synchronize_irq(chip->irq);
 		free_irq(chip->irq, chip);
 		chip->irq = -1;
 	}
@@ -1648,10 +1647,8 @@ static int azx_free(struct azx *chip)
 		azx_stop_chip(chip);
 	}
 
-	if (chip->irq >= 0) {
-		synchronize_irq(chip->irq);
+	if (chip->irq >= 0)
 		free_irq(chip->irq, (void*)chip);
-	}
 	if (chip->msi)
 		pci_disable_msi(chip->pci);
 	if (chip->remap_addr)
sound/pci/ice1712/ice1712.c +2 -3
index df292af..fb13248 100644
@@ -2482,10 +2482,9 @@ static int snd_ice1712_free(struct snd_ice1712 *ice)
 	outb(0xff, ICEREG(ice, IRQMASK));
 	/* --- */
       __hw_end:
-	if (ice->irq >= 0) {
-		synchronize_irq(ice->irq);
+	if (ice->irq >= 0)
 		free_irq(ice->irq, ice);
-	}
+
 	if (ice->port)
 		pci_release_regions(ice->pci);
 	snd_ice1712_akm4xxx_free(ice);
sound/pci/ice1712/ice1724.c +1 -3
index f533850..50bb140 100644
@@ -2169,10 +2169,8 @@ static int snd_vt1724_free(struct snd_ice1712 *ice)
 	outb(0xff, ICEREG1724(ice, IRQMASK));
 	/* --- */
       __hw_end:
-	if (ice->irq >= 0) {
-		synchronize_irq(ice->irq);
+	if (ice->irq >= 0)
 		free_irq(ice->irq, ice);
-	}
 	pci_release_regions(ice->pci);
 	snd_ice1712_akm4xxx_free(ice);
 	pci_disable_device(ice->pci);
sound/pci/intel8x0.c +1 -2
index c52abd0..3e19504 100644
@@ -2446,7 +2446,7 @@ static int snd_intel8x0_free(struct intel8x0 *chip)
 		pci_write_config_dword(chip->pci, 0x4c, val);
 	}
 	/* --- */
-	synchronize_irq(chip->irq);
+
       __hw_end:
 	if (chip->irq >= 0)
 		free_irq(chip->irq, chip);
@@ -2495,7 +2495,6 @@ static int intel8x0_suspend(struct pci_dev *pci, pm_message_t state)
 		chip->sdm_saved = igetbyte(chip, ICHREG(SDM));
 
 	if (chip->irq >= 0) {
-		synchronize_irq(chip->irq);
 		free_irq(chip->irq, chip);
 		chip->irq = -1;
 	}
sound/pci/intel8x0m.c +2 -1
index cadda8d..15db810 100644
@@ -986,7 +986,8 @@ static int snd_intel8x0_free(struct intel8x0m *chip)
 	for (i = 0; i < chip->bdbars_count; i++)
 		iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, ICH_RESETREGS);
 	/* --- */
-	synchronize_irq(chip->irq);
+	if (chip->irq >= 0)
+		synchronize_irq(chip->irq);
       __hw_end:
 	if (chip->bdbars.area)
 		snd_dma_free_pages(&chip->bdbars);
sound/pci/maestro3.c +1 -3
index 04fa0a6..9aa8f05 100644
@@ -2542,10 +2542,8 @@ static int snd_m3_free(struct snd_m3 *chip)
 	vfree(chip->suspend_mem);
 #endif
 
-	if (chip->irq >= 0) {
-		synchronize_irq(chip->irq);
+	if (chip->irq >= 0)
 		free_irq(chip->irq, chip);
-	}
 
 	if (chip->iobase)
 		pci_release_regions(chip->pci);
sound/pci/oxygen/oxygen_lib.c +1 -3
index 78c2115..15b517e 100644
@@ -388,10 +388,8 @@ static void oxygen_card_free(struct snd_card *card)
 	oxygen_write16(chip, OXYGEN_DMA_STATUS, 0);
 	oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, 0);
 	spin_unlock_irq(&chip->reg_lock);
-	if (chip->irq >= 0) {
+	if (chip->irq >= 0)
 		free_irq(chip->irq, chip);
-		synchronize_irq(chip->irq);
-	}
 	flush_scheduled_work();
 	chip->model->cleanup(chip);
 	mutex_destroy(&chip->mutex);
sound/pci/sis7019.c +0 -1
index dcd7cd0..d888293 100644
@@ -1194,7 +1194,6 @@ static int sis_suspend(struct pci_dev *pci, pm_message_t state)
 	/* snd_pcm_suspend_all() stopped all channels, so we're quiescent.
 	 */
 	if (sis->irq >= 0) {
-		synchronize_irq(sis->irq);
 		free_irq(sis->irq, sis);
 		sis->irq = -1;
 	}
sound/pci/via82xx.c +1 -1
index a756be6..b585cc3 100644
@@ -2236,7 +2236,7 @@ static int snd_via82xx_free(struct via82xx *chip)
 	/* disable interrupts */
 	for (i = 0; i < chip->num_devs; i++)
 		snd_via82xx_channel_reset(chip, &chip->devs[i]);
-	synchronize_irq(chip->irq);
+
 	if (chip->irq >= 0)
 		free_irq(chip->irq, chip);
  __end_hw:
sound/pci/via82xx_modem.c +1 -1
index f5df1c7..31f64ee 100644
@@ -1075,7 +1075,7 @@ static int snd_via82xx_free(struct via82xx_modem *chip)
 	/* disable interrupts */
 	for (i = 0; i < chip->num_devs; i++)
 		snd_via82xx_channel_reset(chip, &chip->devs[i]);
-	synchronize_irq(chip->irq);
+
       __end_hw:
 	if (chip->irq >= 0)
 		free_irq(chip->irq, chip);
#1 lore raw

PATCH 2/2 drivers/net: Fix synchronize_irq() bugs, redundancies

free_irq() calls synchronize_irq() for you, so there is no need for drivers to manually do the same thing (again). Thus, calls where sync-irq immediately precedes free-irq can be simplified.

---
 drivers/net/8139cp.c       |    1 -
 drivers/net/8139too.c      |    1 -
 drivers/net/dl2k.c         |    2 +-
 drivers/net/pci-skeleton.c |    1 -
 drivers/net/tsi108_eth.c   |    1 -
 drivers/net/typhoon.c      |    3 ---
 6 files changed, 1 insertion(+), 8 deletions(-)
drivers/net/8139cp.c +0 -1
index a453eda..b92cc15 100644
@@ -1214,7 +1214,6 @@ static int cp_close (struct net_device *dev)
 
 	spin_unlock_irqrestore(&cp->lock, flags);
 
-	synchronize_irq(dev->irq);
 	free_irq(dev->irq, dev);
 
 	cp_free_rings(cp);
drivers/net/8139too.c +0 -1
index 53bd903..fbdf831 100644
@@ -2232,7 +2232,6 @@ static int rtl8139_close (struct net_device *dev)
 
 	spin_unlock_irqrestore (&tp->lock, flags);
 
-	synchronize_irq (dev->irq);	/* racy, but that's ok here */
 	free_irq (dev->irq, dev);
 
 	rtl8139_tx_clear (tp);
drivers/net/dl2k.c +1 -1
index e233d04..05f606d 100644
@@ -1753,7 +1753,7 @@ rio_close (struct net_device *dev)
 
 	/* Stop Tx and Rx logics */
 	writel (TxDisable | RxDisable | StatsDisable, ioaddr + MACCtrl);
-	synchronize_irq (dev->irq);
+
 	free_irq (dev->irq, dev);
 	del_timer_sync (&np->timer);
 
drivers/net/pci-skeleton.c +0 -1
index fffc49b..53451c3 100644
@@ -1739,7 +1739,6 @@ static int netdrv_close (struct net_device *dev)
 
 	spin_unlock_irqrestore (&tp->lock, flags);
 
-	synchronize_irq (dev->irq);
 	free_irq (dev->irq, dev);
 
 	netdrv_tx_clear (dev);
drivers/net/tsi108_eth.c +0 -1
index 6f33f84..e75dd88 100644
@@ -1434,7 +1434,6 @@ static int tsi108_close(struct net_device *dev)
 		dev_kfree_skb(skb);
 	}
 
-	synchronize_irq(data->irq_num);
 	free_irq(data->irq_num, dev);
 
 	/* Discard the RX ring. */
drivers/net/typhoon.c +0 -3
index 333961b..7d2a4c6 100644
@@ -334,8 +334,6 @@ enum state_values {
 #define TYPHOON_RESET_TIMEOUT_NOSLEEP	((6 * 1000000) / TYPHOON_UDELAY)
 #define TYPHOON_WAIT_TIMEOUT		((1000000 / 2) / TYPHOON_UDELAY)
 
-#define typhoon_synchronize_irq(x) synchronize_irq(x)
-
 #if defined(NETIF_F_TSO)
 #define skb_tso_size(x)		(skb_shinfo(x)->gso_size)
 #define TSO_NUM_DESCRIPTORS	2
@@ -2143,7 +2141,6 @@ typhoon_close(struct net_device *dev)
 		printk(KERN_ERR "%s: unable to stop runtime\n", dev->name);
 
 	/* Make sure there is no irq handler running on a different CPU. */
-	typhoon_synchronize_irq(dev->irq);
 	free_irq(dev->irq, dev);
 
 	typhoon_free_rx_rings(tp);
Acked-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] drivers/net: Fix synchronize_irq() bugs, redundancies

Quoted 8 lines · Jeff Garzik

free_irq() calls synchronize_irq() for you, so there is no need for drivers to manually do the same thing (again). Thus, calls where sync-irq immediately precedes free-irq can be simplified.

drivers/net/typhoon.c +0 -0
index 333961b..7d2a4c6 100644

[...]

drivers/net/typhoon.c typhoon_close(struct net_device *dev) · line 2144

Quoted 3 lines
drivers/net/typhoon.c +0 -1
 	/* Make sure there is no irq handler running on a different CPU. */
-	typhoon_synchronize_irq(dev->irq);
 	free_irq(dev->irq, dev);

Should probably kill the comment as well, since it was referring to the synchronize_irq() call.

#3 lore raw
In reply to Jeff Garzik

At Mon, 21 Apr 2008 19:34:19 -0400,

Quoted 5 lines · Jeff Garzik

free_irq() calls synchronize_irq() for you, so there is no need for drivers to manually do the same thing (again). Thus, calls where sync-irq immediately precedes free-irq can be simplified.

Quoted 8 lines

However, during this audit several bugs were noticed, where free-irq is preceded by a "irq >= 0" check... but the sync-irq call is not covered by the same check.

So, where sync-irq could not be eliminated completely, the missing check was added.

Thanks, I applied to ALSA tree now.

Takashi