Skip to content

Commit

Permalink
ALSA: Kill snd_assert() in other places
Browse files Browse the repository at this point in the history
Kill snd_assert() in other places, either removed or replaced with
if () with snd_BUG_ON().

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
  • Loading branch information
tiwai authored and perexg committed Aug 13, 2008
1 parent da3cec3 commit 5e246b8
Show file tree
Hide file tree
Showing 38 changed files with 217 additions and 168 deletions.
13 changes: 8 additions & 5 deletions drivers/media/video/saa7134/saa7134-alsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,10 +488,12 @@ static int snd_card_saa7134_hw_params(struct snd_pcm_substream * substream,
period_size = params_period_bytes(hw_params);
periods = params_periods(hw_params);

snd_assert(period_size >= 0x100 && period_size <= 0x10000,
return -EINVAL);
snd_assert(periods >= 4, return -EINVAL);
snd_assert(period_size * periods <= 1024 * 1024, return -EINVAL);
if (period_size < 0x100 || period_size > 0x10000)
return -EINVAL;
if (periods < 4)
return -EINVAL;
if (period_size * periods > 1024 * 1024)
return -EINVAL;

dev = saa7134->dev;

Expand Down Expand Up @@ -942,7 +944,8 @@ static int snd_card_saa7134_new_mixer(snd_card_saa7134_t * chip)
unsigned int idx;
int err;

snd_assert(chip != NULL, return -EINVAL);
if (snd_BUG_ON(!chip))
return -EINVAL;
strcpy(card->mixername, "SAA7134 Mixer");

for (idx = 0; idx < ARRAY_SIZE(snd_saa7134_controls); idx++) {
Expand Down
9 changes: 0 additions & 9 deletions include/sound/vx_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,37 +235,31 @@ irqreturn_t snd_vx_irq_handler(int irq, void *dev);
*/
static inline int vx_test_and_ack(struct vx_core *chip)
{
snd_assert(chip->ops->test_and_ack, return -ENXIO);
return chip->ops->test_and_ack(chip);
}

static inline void vx_validate_irq(struct vx_core *chip, int enable)
{
snd_assert(chip->ops->validate_irq, return);
chip->ops->validate_irq(chip, enable);
}

static inline unsigned char snd_vx_inb(struct vx_core *chip, int reg)
{
snd_assert(chip->ops->in8, return 0);
return chip->ops->in8(chip, reg);
}

static inline unsigned int snd_vx_inl(struct vx_core *chip, int reg)
{
snd_assert(chip->ops->in32, return 0);
return chip->ops->in32(chip, reg);
}

static inline void snd_vx_outb(struct vx_core *chip, int reg, unsigned char val)
{
snd_assert(chip->ops->out8, return);
chip->ops->out8(chip, reg, val);
}

static inline void snd_vx_outl(struct vx_core *chip, int reg, unsigned int val)
{
snd_assert(chip->ops->out32, return);
chip->ops->out32(chip, reg, val);
}

Expand All @@ -276,7 +270,6 @@ static inline void snd_vx_outl(struct vx_core *chip, int reg, unsigned int val)

static inline void vx_reset_dsp(struct vx_core *chip)
{
snd_assert(chip->ops->reset_dsp, return);
chip->ops->reset_dsp(chip);
}

Expand Down Expand Up @@ -304,14 +297,12 @@ int snd_vx_check_reg_bit(struct vx_core *chip, int reg, int mask, int bit, int t
static inline void vx_pseudo_dma_write(struct vx_core *chip, struct snd_pcm_runtime *runtime,
struct vx_pipe *pipe, int count)
{
snd_assert(chip->ops->dma_write, return);
chip->ops->dma_write(chip, runtime, pipe, count);
}

static inline void vx_pseudo_dma_read(struct vx_core *chip, struct snd_pcm_runtime *runtime,
struct vx_pipe *pipe, int count)
{
snd_assert(chip->ops->dma_read, return);
chip->ops->dma_read(chip, runtime, pipe, count);
}

Expand Down
5 changes: 3 additions & 2 deletions sound/arm/sa11xx-uda1341.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ static void audio_process_dma(struct audio_stream *s)

/* we are requested to process synchronization DMA transfer */
if (s->tx_spin) {
snd_assert(s->stream_id == SNDRV_PCM_STREAM_PLAYBACK, return);
if (snd_BUG_ON(s->stream_id != SNDRV_PCM_STREAM_PLAYBACK))
return;
/* fill the xmit dma buffers and return */
#ifdef HH_VERSION
sa1100_dma_set_spin(s->dmach, FORCE_CLOCK_ADDR, FORCE_CLOCK_SIZE);
Expand Down Expand Up @@ -472,7 +473,7 @@ static void audio_process_dma(struct audio_stream *s)
continue; /* special case */
} else {
offset = dma_size * s->period;
snd_assert(dma_size <= DMA_BUF_SIZE, );
snd_BUG_ON(dma_size > DMA_BUF_SIZE);
}
#ifdef HH_VERSION
ret = sa1100_dma_queue_buffer(s->dmach, s, runtime->dma_addr + offset, dma_size);
Expand Down
3 changes: 2 additions & 1 deletion sound/drivers/dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,8 @@ static int __devinit snd_card_dummy_new_mixer(struct snd_dummy *dummy)
unsigned int idx;
int err;

snd_assert(dummy != NULL, return -EINVAL);
if (snd_BUG_ON(!dummy))
return -EINVAL;
spin_lock_init(&dummy->mixer_lock);
strcpy(card->mixername, "Dummy Mixer");

Expand Down
6 changes: 4 additions & 2 deletions sound/drivers/opl3/opl3_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ static int snd_opl3_detect(struct snd_opl3 * opl3)
* If we had an OPL4 chip, opl3->hardware would have been set
* by the OPL4 driver; so we can assume OPL3 here.
*/
snd_assert(opl3->r_port != 0, return -ENODEV);
if (snd_BUG_ON(!opl3->r_port))
return -ENODEV;
opl3->hardware = OPL3_HW_OPL3;
}
return 0;
Expand Down Expand Up @@ -324,7 +325,8 @@ EXPORT_SYMBOL(snd_opl3_interrupt);

static int snd_opl3_free(struct snd_opl3 *opl3)
{
snd_assert(opl3 != NULL, return -ENXIO);
if (snd_BUG_ON(!opl3))
return -ENXIO;
if (opl3->private_free)
opl3->private_free(opl3);
snd_opl3_clear_patches(opl3);
Expand Down
6 changes: 4 additions & 2 deletions sound/drivers/opl3/opl3_midi.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,8 @@ static void snd_opl3_kill_voice(struct snd_opl3 *opl3, int voice)

struct snd_opl3_voice *vp, *vp2;

snd_assert(voice < MAX_OPL3_VOICES, return);
if (snd_BUG_ON(voice >= MAX_OPL3_VOICES))
return;

vp = &opl3->voices[voice];
if (voice < MAX_OPL2_VOICES) {
Expand Down Expand Up @@ -737,7 +738,8 @@ static void snd_opl3_update_pitch(struct snd_opl3 *opl3, int voice)

struct snd_opl3_voice *vp;

snd_assert(voice < MAX_OPL3_VOICES, return);
if (snd_BUG_ON(voice >= MAX_OPL3_VOICES))
return;

vp = &opl3->voices[voice];
if (vp->chan == NULL)
Expand Down
15 changes: 10 additions & 5 deletions sound/drivers/opl3/opl3_oss.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ static int snd_opl3_open_seq_oss(struct snd_seq_oss_arg *arg, void *closure)
struct snd_opl3 *opl3 = closure;
int err;

snd_assert(arg != NULL, return -ENXIO);
if (snd_BUG_ON(!arg))
return -ENXIO;

if ((err = snd_opl3_synth_setup(opl3)) < 0)
return err;
Expand All @@ -184,7 +185,8 @@ static int snd_opl3_close_seq_oss(struct snd_seq_oss_arg *arg)
{
struct snd_opl3 *opl3;

snd_assert(arg != NULL, return -ENXIO);
if (snd_BUG_ON(!arg))
return -ENXIO;
opl3 = arg->private_data;

snd_opl3_synth_cleanup(opl3);
Expand All @@ -206,7 +208,8 @@ static int snd_opl3_load_patch_seq_oss(struct snd_seq_oss_arg *arg, int format,
char name[32];
int err, type;

snd_assert(arg != NULL, return -ENXIO);
if (snd_BUG_ON(!arg))
return -ENXIO;
opl3 = arg->private_data;

if (format == FM_PATCH)
Expand Down Expand Up @@ -246,7 +249,8 @@ static int snd_opl3_ioctl_seq_oss(struct snd_seq_oss_arg *arg, unsigned int cmd,
{
struct snd_opl3 *opl3;

snd_assert(arg != NULL, return -ENXIO);
if (snd_BUG_ON(!arg))
return -ENXIO;
opl3 = arg->private_data;
switch (cmd) {
case SNDCTL_FM_LOAD_INSTR:
Expand All @@ -271,7 +275,8 @@ static int snd_opl3_reset_seq_oss(struct snd_seq_oss_arg *arg)
{
struct snd_opl3 *opl3;

snd_assert(arg != NULL, return -ENXIO);
if (snd_BUG_ON(!arg))
return -ENXIO;
opl3 = arg->private_data;

return 0;
Expand Down
3 changes: 2 additions & 1 deletion sound/drivers/opl3/opl3_synth.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ int snd_opl3_ioctl(struct snd_hwdep * hw, struct file *file,
struct snd_opl3 *opl3 = hw->private_data;
void __user *argp = (void __user *)arg;

snd_assert(opl3 != NULL, return -EINVAL);
if (snd_BUG_ON(!opl3))
return -EINVAL;

switch (cmd) {
/* get information */
Expand Down
2 changes: 1 addition & 1 deletion sound/drivers/opl4/opl4_synth.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ static struct opl4_voice *snd_opl4_get_voice(struct snd_opl4 *opl4)
if (!list_empty(&opl4->off_voices))
return list_entry(opl4->off_voices.next, struct opl4_voice, list);
/* then get the oldest key-on voice */
snd_assert(!list_empty(&opl4->on_voices), );
snd_BUG_ON(list_empty(&opl4->on_voices));
return list_entry(opl4->on_voices.next, struct opl4_voice, list);
}

Expand Down
3 changes: 2 additions & 1 deletion sound/drivers/vx/vx_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ static struct vx_cmd_info vx_dsp_cmds[] = {
*/
void vx_init_rmh(struct vx_rmh *rmh, unsigned int cmd)
{
snd_assert(cmd < CMD_LAST_INDEX, return);
if (snd_BUG_ON(cmd >= CMD_LAST_INDEX))
return;
rmh->LgCmd = vx_dsp_cmds[cmd].length;
rmh->LgStat = vx_dsp_cmds[cmd].st_length;
rmh->DspStat = vx_dsp_cmds[cmd].st_type;
Expand Down
21 changes: 14 additions & 7 deletions sound/drivers/vx/vx_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ static int vx_read_status(struct vx_core *chip, struct vx_rmh *rmh)

if (size < 1)
return 0;
snd_assert(size <= SIZE_MAX_STATUS, return -EINVAL);
if (snd_BUG_ON(size > SIZE_MAX_STATUS))
return -EINVAL;

for (i = 1; i <= size; i++) {
/* trigger an irq MESS_WRITE_NEXT */
Expand Down Expand Up @@ -425,13 +426,16 @@ int snd_vx_load_boot_image(struct vx_core *chip, const struct firmware *boot)
int no_fillup = vx_has_new_dsp(chip);

/* check the length of boot image */
snd_assert(boot->size > 0, return -EINVAL);
snd_assert(boot->size % 3 == 0, return -EINVAL);
if (boot->size <= 0)
return -EINVAL;
if (boot->size % 3)
return -EINVAL;
#if 0
{
/* more strict check */
unsigned int c = ((u32)boot->data[0] << 16) | ((u32)boot->data[1] << 8) | boot->data[2];
snd_assert(boot->size == (c + 2) * 3, return -EINVAL);
if (boot->size != (c + 2) * 3)
return -EINVAL;
}
#endif

Expand Down Expand Up @@ -554,7 +558,8 @@ EXPORT_SYMBOL(snd_vx_irq_handler);
*/
static void vx_reset_board(struct vx_core *chip, int cold_reset)
{
snd_assert(chip->ops->reset_board, return);
if (snd_BUG_ON(!chip->ops->reset_board))
return;

/* current source, later sync'ed with target */
chip->audio_source = VX_AUDIO_SRC_LINE;
Expand Down Expand Up @@ -673,7 +678,8 @@ int snd_vx_dsp_load(struct vx_core *chip, const struct firmware *dsp)
unsigned int csum = 0;
const unsigned char *image, *cptr;

snd_assert(dsp->size % 3 == 0, return -EINVAL);
if (dsp->size % 3)
return -EINVAL;

vx_toggle_dac_mute(chip, 1);

Expand Down Expand Up @@ -775,7 +781,8 @@ struct vx_core *snd_vx_create(struct snd_card *card, struct snd_vx_hardware *hw,
{
struct vx_core *chip;

snd_assert(card && hw && ops, return NULL);
if (snd_BUG_ON(!card || !hw || !ops))
return NULL;

chip = kzalloc(sizeof(*chip) + extra_size, GFP_KERNEL);
if (! chip) {
Expand Down
6 changes: 4 additions & 2 deletions sound/drivers/vx/vx_hwdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ static int vx_hwdep_dsp_status(struct snd_hwdep *hw,
};
struct vx_core *vx = hw->private_data;

snd_assert(type_ids[vx->type], return -EINVAL);
if (snd_BUG_ON(!type_ids[vx->type]))
return -EINVAL;
strcpy(info->id, type_ids[vx->type]);
if (vx_is_pcmcia(vx))
info->num_dsps = 4;
Expand All @@ -168,7 +169,8 @@ static int vx_hwdep_dsp_load(struct snd_hwdep *hw,
int index, err;
struct firmware *fw;

snd_assert(vx->ops->load_dsp, return -ENXIO);
if (snd_BUG_ON(!vx->ops->load_dsp))
return -ENXIO;

fw = kmalloc(sizeof(*fw), GFP_KERNEL);
if (! fw) {
Expand Down
3 changes: 2 additions & 1 deletion sound/drivers/vx/vx_mixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ static void vx_write_codec_reg(struct vx_core *chip, int codec, unsigned int dat
{
unsigned long flags;

snd_assert(chip->ops->write_codec, return);
if (snd_BUG_ON(!chip->ops->write_codec))
return;

if (chip->chip_status & VX_STAT_IS_STALE)
return;
Expand Down
9 changes: 6 additions & 3 deletions sound/drivers/vx/vx_pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,8 @@ static int vx_pcm_playback_open(struct snd_pcm_substream *subs)
return -EBUSY;

audio = subs->pcm->device * 2;
snd_assert(audio < chip->audio_outs, return -EINVAL);
if (snd_BUG_ON(audio >= chip->audio_outs))
return -EINVAL;

/* playback pipe may have been already allocated for monitoring */
pipe = chip->playback_pipes[audio];
Expand Down Expand Up @@ -996,7 +997,8 @@ static int vx_pcm_capture_open(struct snd_pcm_substream *subs)
return -EBUSY;

audio = subs->pcm->device * 2;
snd_assert(audio < chip->audio_ins, return -EINVAL);
if (snd_BUG_ON(audio >= chip->audio_ins))
return -EINVAL;
err = vx_alloc_pipe(chip, 1, audio, 2, &pipe);
if (err < 0)
return err;
Expand Down Expand Up @@ -1214,7 +1216,8 @@ void vx_pcm_update_intr(struct vx_core *chip, unsigned int events)
}
if (capture)
continue;
snd_assert(p >= 0 && (unsigned int)p < chip->audio_outs,);
if (snd_BUG_ON(p < 0 || p >= chip->audio_outs))
continue;
pipe = chip->playback_pipes[p];
if (pipe && pipe->substream) {
vx_pcm_playback_update(chip, pipe->substream, pipe);
Expand Down
6 changes: 4 additions & 2 deletions sound/drivers/vx/vx_uer.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,15 @@ static int vx_calc_clock_from_freq(struct vx_core *chip, int freq)
{
int hexfreq;

snd_assert(freq > 0, return 0);
if (snd_BUG_ON(freq <= 0))
return 0;

hexfreq = (28224000 * 10) / freq;
hexfreq = (hexfreq + 5) / 10;

/* max freq = 55125 Hz */
snd_assert(hexfreq > 0x00000200, return 0);
if (snd_BUG_ON(hexfreq <= 0x00000200))
return 0;

if (hexfreq <= 0x03ff)
return hexfreq - 0x00000201;
Expand Down
Loading

0 comments on commit 5e246b8

Please sign in to comment.