[alsa-devel] [PATCH 0/5] 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

BUG_ON() is rather useless for debugging as it leads to panic(). Use WARN_ON() and handle the error cases accordingly.
Signed-off-by: Takashi Iwai tiwai@suse.de --- sound/pci/ctxfi/cthardware.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/sound/pci/ctxfi/cthardware.c b/sound/pci/ctxfi/cthardware.c index 110b8ace6d8a..a689f2552706 100644 --- a/sound/pci/ctxfi/cthardware.c +++ b/sound/pci/ctxfi/cthardware.c @@ -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++;

BUG_ON() is rather useless for debugging as it leads to panic(). Use WARN_ON() and handle the error cases accordingly.
Signed-off-by: Takashi Iwai tiwai@suse.de --- sound/ppc/snd_ps3.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/sound/ppc/snd_ps3.c b/sound/ppc/snd_ps3.c index 8c7dcbe0118d..ebb76f2d90d7 100644 --- a/sound/ppc/snd_ps3.c +++ b/sound/ppc/snd_ps3.c @@ -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;

BUG_ON() is rather useless for debugging as it leads to panic(). Use WARN_ON() and handle the error cases accordingly.
Signed-off-by: Takashi Iwai tiwai@suse.de --- sound/sparc/cs4231.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/sound/sparc/cs4231.c b/sound/sparc/cs4231.c index 54aaad2a10f5..b47f6fe6277f 100644 --- a/sound/sparc/cs4231.c +++ b/sound/sparc/cs4231.c @@ -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);

BUG_ON() is rather useless for debugging as it leads to panic(). Use WARN_ON() and handle the error cases accordingly.
Signed-off-by: Takashi Iwai tiwai@suse.de --- sound/mips/ad1843.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sound/mips/ad1843.c b/sound/mips/ad1843.c index c624510ec374..586907500ca5 100644 --- a/sound/mips/ad1843.c +++ b/sound/mips/ad1843.c @@ -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;

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.
Signed-off-by: Takashi Iwai tiwai@suse.de --- sound/arm/pxa2xx-ac97-lib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sound/arm/pxa2xx-ac97-lib.c b/sound/arm/pxa2xx-ac97-lib.c index 99a466822a7d..66de90ed30ca 100644 --- a/sound/arm/pxa2xx-ac97-lib.c +++ b/sound/arm/pxa2xx-ac97-lib.c @@ -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);
participants (1)
-
Takashi Iwai