Skip to contentSkip to conversation

Let's kill BUG*()

PATCH New Takashi Iwai 1 participant 6 messages Nov 5, 2013

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

cover Let's kill BUG*()

Hi,

this is a series of trivial patches to kill BUG() and BUG_ON() in sound/* (except for ASoC codes, which will follow later).

Basically BUG() and BUG_ON() are usless for drivers like sound drivers, because they stop the whole operation intentionally by calling panic(). In this patch series, they are replaced with WARN_ON(), snd_BUG() or something else more soft ones.

[PATCH 1/5] ALSA: ctxfi: Use WARN_ON() instead of BUG_ON() [PATCH 2/5] ALSA: ps3: Use WARN_ON() instead of BUG_ON() [PATCH 3/5] ALSA: sparc/cs4231: Use WARN_ON() instead of BUG_ON() [PATCH 4/5] ALSA: mips/ad1843: Use WARN_ON() instead of BUG_ON() [PATCH 5/5] ALSA: pxa2xx: Replace BUG() with snd_BUG()

Takashi

#1 lore raw

PATCH 1/5 ALSA: ctxfi: Use WARN_ON() instead of BUG_ON()

BUG_ON() is rather useless for debugging as it leads to panic(). Use WARN_ON() and handle the error cases accordingly.

---
 sound/pci/ctxfi/cthardware.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
sound/pci/ctxfi/cthardware.c +4 -2
index 110b8ace6d8a..a689f2552706 100644
@@ -69,7 +69,8 @@ unsigned int get_field(unsigned int data, unsigned int field)
 {
 	int i;
 
-	BUG_ON(!field);
+	if (WARN_ON(!field))
+		return 0;
 	/* @field should always be greater than 0 */
 	for (i = 0; !(field & (1 << i)); )
 		i++;
@@ -81,7 +82,8 @@ void set_field(unsigned int *data, unsigned int field, unsigned int value)
 {
 	int i;
 
-	BUG_ON(!field);
+	if (WARN_ON(!field))
+		return;
 	/* @field should always be greater than 0 */
 	for (i = 0; !(field & (1 << i)); )
 		i++;
Signature · 1 line
1.8.4.2
#2 lore raw

PATCH 2/5 ALSA: ps3: Use WARN_ON() instead of BUG_ON()

In reply to Takashi Iwai

BUG_ON() is rather useless for debugging as it leads to panic(). Use WARN_ON() and handle the error cases accordingly.

---
 sound/ppc/snd_ps3.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
sound/ppc/snd_ps3.c +4 -2
index 8c7dcbe0118d..ebb76f2d90d7 100644
@@ -933,8 +933,10 @@ static int snd_ps3_driver_probe(struct ps3_system_bus_device *dev)
 	int i, ret;
 	u64 lpar_addr, lpar_size;
 
-	BUG_ON(!firmware_has_feature(FW_FEATURE_PS3_LV1));
-	BUG_ON(dev->match_id != PS3_MATCH_ID_SOUND);
+	if (WARN_ON(!firmware_has_feature(FW_FEATURE_PS3_LV1)))
+		return -ENODEV;
+	if (WARN_ON(dev->match_id != PS3_MATCH_ID_SOUND))
+		return -ENODEV;
 
 	the_card.ps3_dev = dev;
 
Signature · 1 line
1.8.4.2
#3 lore raw

PATCH 3/5 ALSA: sparc/cs4231: Use WARN_ON() instead of BUG_ON()

In reply to Takashi Iwai

BUG_ON() is rather useless for debugging as it leads to panic(). Use WARN_ON() and handle the error cases accordingly.

---
 sound/sparc/cs4231.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
sound/sparc/cs4231.c +4 -2
index 54aaad2a10f5..b47f6fe6277f 100644
@@ -429,7 +429,8 @@ static void snd_cs4231_advance_dma(struct cs4231_dma_control *dma_cont,
 		unsigned int period_size = snd_pcm_lib_period_bytes(substream);
 		unsigned int offset = period_size * (*periods_sent);
 
-		BUG_ON(period_size >= (1 << 24));
+		if (WARN_ON(period_size >= (1 << 24)))
+			return;
 
 		if (dma_cont->request(dma_cont,
 				      runtime->dma_addr + offset, period_size))
@@ -912,7 +913,8 @@ static int snd_cs4231_playback_prepare(struct snd_pcm_substream *substream)
 	chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_PLAYBACK_ENABLE |
 					    CS4231_PLAYBACK_PIO);
 
-	BUG_ON(runtime->period_size > 0xffff + 1);
+	if (WARN_ON(runtime->period_size > 0xffff + 1))
+		return -EINVAL;
 
 	chip->p_periods_sent = 0;
 	spin_unlock_irqrestore(&chip->lock, flags);
Signature · 1 line
1.8.4.2
#4 lore raw

PATCH 4/5 ALSA: mips/ad1843: Use WARN_ON() instead of BUG_ON()

In reply to Takashi Iwai

BUG_ON() is rather useless for debugging as it leads to panic(). Use WARN_ON() and handle the error cases accordingly.

---
 sound/mips/ad1843.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/mips/ad1843.c +1 -1
index c624510ec374..586907500ca5 100644
@@ -276,7 +276,7 @@ static void ad1843_write_multi(struct snd_ad1843 *ad1843, int argcount, ...)
 		if (reg == -1)
 			reg = fp->reg;
 		else
-			BUG_ON(reg != fp->reg);
+			WARN_ON(reg != fp->reg);
 		m = ((1 << fp->nbits) - 1) << fp->lo_bit;
 		mask |= m;
 		bits |= (value << fp->lo_bit) & m;
Signature · 1 line
1.8.4.2
#5 lore raw

PATCH 5/5 ALSA: pxa2xx: Replace BUG() with snd_BUG()

In reply to Takashi Iwai

BUG() used in the driver is just to spit the stack trace on buggy points, not really needed to stop the whole operation. For that purpose, it'd be more convenient to use snd_BUG() instead.

---
 sound/arm/pxa2xx-ac97-lib.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
sound/arm/pxa2xx-ac97-lib.c +2 -2
index 99a466822a7d..66de90ed30ca 100644
@@ -208,7 +208,7 @@ bool pxa2xx_ac97_try_warm_reset(struct snd_ac97 *ac97)
 		pxa_ac97_warm_pxa3xx();
 	else
 #endif
-		BUG();
+		snd_BUG();
 
 	while (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)) && timeout--)
 		mdelay(1);
@@ -245,7 +245,7 @@ bool pxa2xx_ac97_try_cold_reset(struct snd_ac97 *ac97)
 		pxa_ac97_cold_pxa3xx();
 	else
 #endif
-		BUG();
+		snd_BUG();
 
 	while (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)) && timeout--)
 		mdelay(1);
Signature · 1 line
1.8.4.2