Skip to content

Commit

Permalink
[ALSA] Remove snd_runtime_check() macro
Browse files Browse the repository at this point in the history
Remove snd_runtime_check() macro.
This macro worsens the readability of codes.  They should be either
normal if() or removable asserts.

Also, the assert displays stack-dump, instead of only the last caller
pointer.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
  • Loading branch information
tiwai authored and Jaroslav Kysela committed Nov 4, 2005
1 parent f01cc52 commit 7c22f1a
Show file tree
Hide file tree
Showing 17 changed files with 126 additions and 102 deletions.
33 changes: 12 additions & 21 deletions Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
</affiliation>
</author>

<date>March 6, 2005</date>
<edition>0.3.4</edition>
<date>October 6, 2005</date>
<edition>0.3.5</edition>

<abstract>
<para>
Expand All @@ -30,7 +30,7 @@

<legalnotice>
<para>
Copyright (c) 2002-2004 Takashi Iwai <email>tiwai@suse.de</email>
Copyright (c) 2002-2005 Takashi Iwai <email>tiwai@suse.de</email>
</para>

<para>
Expand Down Expand Up @@ -5998,32 +5998,23 @@ struct _snd_pcm_runtime {
The first argument is the expression to evaluate, and the
second argument is the action if it fails. When
<constant>CONFIG_SND_DEBUG</constant>, is set, it will show an
error message such as <computeroutput>BUG? (xxx) (called from
yyy)</computeroutput>. When no debug flag is set, this is
ignored.
error message such as <computeroutput>BUG? (xxx)</computeroutput>
together with stack trace.
</para>
</section>

<section id="useful-functions-snd-runtime-check">
<title><function>snd_runtime_check()</function></title>
<para>
This macro is quite similar with
<function>snd_assert()</function>. Unlike
<function>snd_assert()</function>, the expression is always
evaluated regardless of
<constant>CONFIG_SND_DEBUG</constant>. When
<constant>CONFIG_SND_DEBUG</constant> is set, the macro will
show a message like <computeroutput>ERROR (xx) (called from
yyy)</computeroutput>.
When no debug flag is set, this macro is ignored.
</para>
</section>

<section id="useful-functions-snd-bug">
<title><function>snd_BUG()</function></title>
<para>
It calls <function>snd_assert(0,)</function> -- that is, just
prints the error message at the point. It's useful to show that
a fatal error happens there.
It shows <computeroutput>BUG?</computeroutput> message and
stack trace as well as <function>snd_assert</function> at the point.
It's useful to show that a fatal error happens there.
</para>
<para>
When no debug flag is set, this macro is ignored.
</para>
</section>
</chapter>
Expand Down
34 changes: 11 additions & 23 deletions include/sound/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,34 +429,24 @@ void snd_verbose_printd(const char *file, int line, const char *format, ...)
* When CONFIG_SND_DEBUG is not set, the expression is executed but
* not checked.
*/
#define snd_assert(expr, args...) do {\
if (unlikely(!(expr))) { \
snd_printk(KERN_ERR "BUG? (%s) (called from %p)\n", __ASTRING__(expr), __builtin_return_address(0));\
args;\
}\
#define snd_assert(expr, args...) do { \
if (unlikely(!(expr))) { \
snd_printk(KERN_ERR "BUG? (%s)\n", __ASTRING__(expr)); \
dump_stack(); \
args; \
} \
} while (0)
/**
* snd_runtime_check - run-time assertion macro
* @expr: expression
* @args...: the action
*
* This macro checks the expression in run-time and invokes the commands
* given in the rest arguments if the assertion is failed.
* Unlike snd_assert(), the action commands are executed even if
* CONFIG_SND_DEBUG is not set but without any error messages.
*/
#define snd_runtime_check(expr, args...) do {\
if (unlikely(!(expr))) { \
snd_printk(KERN_ERR "ERROR (%s) (called from %p)\n", __ASTRING__(expr), __builtin_return_address(0));\
args;\
}\

#define snd_BUG() do { \
snd_printk(KERN_ERR "BUG?\n"); \
dump_stack(); \
} while (0)

#else /* !CONFIG_SND_DEBUG */

#define snd_printd(fmt, args...) /* nothing */
#define snd_assert(expr, args...) (void)(expr)
#define snd_runtime_check(expr, args...) do { if (!(expr)) { args; } } while (0)
#define snd_BUG() /* nothing */

#endif /* CONFIG_SND_DEBUG */

Expand All @@ -473,8 +463,6 @@ void snd_verbose_printd(const char *file, int line, const char *format, ...)
#define snd_printdd(format, args...) /* nothing */
#endif

#define snd_BUG() snd_assert(0, )


static inline void snd_timestamp_now(struct timespec *tstamp, int timespec)
{
Expand Down
18 changes: 9 additions & 9 deletions sound/core/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void snd_ctl_notify(snd_card_t *card, unsigned int mask, snd_ctl_elem_id_t *id)
snd_ctl_file_t *ctl;
snd_kctl_event_t *ev;

snd_runtime_check(card != NULL && id != NULL, return);
snd_assert(card != NULL && id != NULL, return);
read_lock(&card->ctl_files_rwlock);
#if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
card->mixer_oss_change_count++;
Expand Down Expand Up @@ -193,8 +193,8 @@ snd_kcontrol_t *snd_ctl_new(snd_kcontrol_t * control, unsigned int access)
snd_kcontrol_t *kctl;
unsigned int idx;

snd_runtime_check(control != NULL, return NULL);
snd_runtime_check(control->count > 0, return NULL);
snd_assert(control != NULL, return NULL);
snd_assert(control->count > 0, return NULL);
kctl = kzalloc(sizeof(*kctl) + sizeof(snd_kcontrol_volatile_t) * control->count, GFP_KERNEL);
if (kctl == NULL)
return NULL;
Expand All @@ -220,7 +220,7 @@ snd_kcontrol_t *snd_ctl_new1(const snd_kcontrol_new_t * ncontrol, void *private_
snd_kcontrol_t kctl;
unsigned int access;

snd_runtime_check(ncontrol != NULL, return NULL);
snd_assert(ncontrol != NULL, return NULL);
snd_assert(ncontrol->info != NULL, return NULL);
memset(&kctl, 0, sizeof(kctl));
kctl.id.iface = ncontrol->iface;
Expand Down Expand Up @@ -309,7 +309,7 @@ int snd_ctl_add(snd_card_t * card, snd_kcontrol_t * kcontrol)
snd_ctl_elem_id_t id;
unsigned int idx;

snd_runtime_check(card != NULL && kcontrol != NULL, return -EINVAL);
snd_assert(card != NULL && kcontrol != NULL, return -EINVAL);
snd_assert(kcontrol->info != NULL, return -EINVAL);
id = kcontrol->id;
down_write(&card->controls_rwsem);
Expand Down Expand Up @@ -355,7 +355,7 @@ int snd_ctl_remove(snd_card_t * card, snd_kcontrol_t * kcontrol)
snd_ctl_elem_id_t id;
unsigned int idx;

snd_runtime_check(card != NULL && kcontrol != NULL, return -EINVAL);
snd_assert(card != NULL && kcontrol != NULL, return -EINVAL);
list_del(&kcontrol->list);
card->controls_count -= kcontrol->count;
id = kcontrol->id;
Expand Down Expand Up @@ -468,7 +468,7 @@ snd_kcontrol_t *snd_ctl_find_numid(snd_card_t * card, unsigned int numid)
struct list_head *list;
snd_kcontrol_t *kctl;

snd_runtime_check(card != NULL && numid != 0, return NULL);
snd_assert(card != NULL && numid != 0, return NULL);
list_for_each(list, &card->controls) {
kctl = snd_kcontrol(list);
if (kctl->id.numid <= numid && kctl->id.numid + kctl->count > numid)
Expand All @@ -494,7 +494,7 @@ snd_kcontrol_t *snd_ctl_find_id(snd_card_t * card, snd_ctl_elem_id_t *id)
struct list_head *list;
snd_kcontrol_t *kctl;

snd_runtime_check(card != NULL && id != NULL, return NULL);
snd_assert(card != NULL && id != NULL, return NULL);
if (id->numid != 0)
return snd_ctl_find_numid(card, id->numid);
list_for_each(list, &card->controls) {
Expand Down Expand Up @@ -1215,7 +1215,7 @@ static int _snd_ctl_unregister_ioctl(snd_kctl_ioctl_func_t fcn, struct list_head
struct list_head *list;
snd_kctl_ioctl_t *p;

snd_runtime_check(fcn != NULL, return -EINVAL);
snd_assert(fcn != NULL, return -EINVAL);
down_write(&snd_ioctl_rwsem);
list_for_each(list, lists) {
p = list_entry(list, snd_kctl_ioctl_t, list);
Expand Down
5 changes: 3 additions & 2 deletions sound/core/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ int snd_card_register(snd_card_t * card)
int err;
snd_info_entry_t *entry;

snd_runtime_check(card != NULL, return -EINVAL);
snd_assert(card != NULL, return -EINVAL);
if ((err = snd_device_register_all(card)) < 0)
return err;
write_lock(&snd_card_rwlock);
Expand Down Expand Up @@ -524,7 +524,8 @@ int __init snd_card_info_init(void)
snd_info_entry_t *entry;

entry = snd_info_create_module_entry(THIS_MODULE, "cards", NULL);
snd_runtime_check(entry != NULL, return -ENOMEM);
if (! entry)
return -ENOMEM;
entry->c.text.read_size = PAGE_SIZE;
entry->c.text.read = snd_card_info_read;
if (snd_info_register(entry) < 0) {
Expand Down
59 changes: 41 additions & 18 deletions sound/core/oss/mixer_oss.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,9 +521,13 @@ static void snd_mixer_oss_get_volume1_vol(snd_mixer_oss_file_t *fmixer,
uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
if (uinfo == NULL || uctl == NULL)
goto __unalloc;
snd_runtime_check(!kctl->info(kctl, uinfo), goto __unalloc);
snd_runtime_check(!kctl->get(kctl, uctl), goto __unalloc);
snd_runtime_check(uinfo->type != SNDRV_CTL_ELEM_TYPE_BOOLEAN || uinfo->value.integer.min != 0 || uinfo->value.integer.max != 1, goto __unalloc);
if (kctl->info(kctl, uinfo))
goto __unalloc;
if (kctl->get(kctl, uctl))
goto __unalloc;
if (uinfo->type == SNDRV_CTL_ELEM_TYPE_BOOLEAN &&
uinfo->value.integer.min == 0 && uinfo->value.integer.max == 1)
goto __unalloc;
*left = snd_mixer_oss_conv1(uctl->value.integer.value[0], uinfo->value.integer.min, uinfo->value.integer.max, &pslot->volume[0]);
if (uinfo->count > 1)
*right = snd_mixer_oss_conv1(uctl->value.integer.value[1], uinfo->value.integer.min, uinfo->value.integer.max, &pslot->volume[1]);
Expand Down Expand Up @@ -555,8 +559,10 @@ static void snd_mixer_oss_get_volume1_sw(snd_mixer_oss_file_t *fmixer,
uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
if (uinfo == NULL || uctl == NULL)
goto __unalloc;
snd_runtime_check(!kctl->info(kctl, uinfo), goto __unalloc);
snd_runtime_check(!kctl->get(kctl, uctl), goto __unalloc);
if (kctl->info(kctl, uinfo))
goto __unalloc;
if (kctl->get(kctl, uctl))
goto __unalloc;
if (!uctl->value.integer.value[0]) {
*left = 0;
if (uinfo->count == 1)
Expand Down Expand Up @@ -616,12 +622,16 @@ static void snd_mixer_oss_put_volume1_vol(snd_mixer_oss_file_t *fmixer,
uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
if (uinfo == NULL || uctl == NULL)
goto __unalloc;
snd_runtime_check(!kctl->info(kctl, uinfo), goto __unalloc);
snd_runtime_check(uinfo->type != SNDRV_CTL_ELEM_TYPE_BOOLEAN || uinfo->value.integer.min != 0 || uinfo->value.integer.max != 1, goto __unalloc);
if (kctl->info(kctl, uinfo))
goto __unalloc;
if (uinfo->type == SNDRV_CTL_ELEM_TYPE_BOOLEAN &&
uinfo->value.integer.min == 0 && uinfo->value.integer.max == 1)
goto __unalloc;
uctl->value.integer.value[0] = snd_mixer_oss_conv2(left, uinfo->value.integer.min, uinfo->value.integer.max);
if (uinfo->count > 1)
uctl->value.integer.value[1] = snd_mixer_oss_conv2(right, uinfo->value.integer.min, uinfo->value.integer.max);
snd_runtime_check((res = kctl->put(kctl, uctl)) >= 0, goto __unalloc);
if ((res = kctl->put(kctl, uctl)) < 0)
goto __unalloc;
if (res > 0)
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id);
__unalloc:
Expand Down Expand Up @@ -653,7 +663,8 @@ static void snd_mixer_oss_put_volume1_sw(snd_mixer_oss_file_t *fmixer,
uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
if (uinfo == NULL || uctl == NULL)
goto __unalloc;
snd_runtime_check(!kctl->info(kctl, uinfo), goto __unalloc);
if (kctl->info(kctl, uinfo))
goto __unalloc;
if (uinfo->count > 1) {
uctl->value.integer.value[0] = left > 0 ? 1 : 0;
uctl->value.integer.value[route ? 3 : 1] = right > 0 ? 1 : 0;
Expand All @@ -664,7 +675,8 @@ static void snd_mixer_oss_put_volume1_sw(snd_mixer_oss_file_t *fmixer,
} else {
uctl->value.integer.value[0] = (left > 0 || right > 0) ? 1 : 0;
}
snd_runtime_check((res = kctl->put(kctl, uctl)) >= 0, goto __unalloc);
if ((res = kctl->put(kctl, uctl)) < 0)
goto __unalloc;
if (res > 0)
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id);
__unalloc:
Expand Down Expand Up @@ -776,9 +788,14 @@ static int snd_mixer_oss_get_recsrc2(snd_mixer_oss_file_t *fmixer, unsigned int
}
down_read(&card->controls_rwsem);
kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0);
snd_runtime_check(kctl != NULL, err = -ENOENT; goto __unlock);
snd_runtime_check(!(err = kctl->info(kctl, uinfo)), goto __unlock);
snd_runtime_check(!(err = kctl->get(kctl, uctl)), goto __unlock);
if (! kctl) {
err = -ENOENT;
goto __unlock;
}
if ((err = kctl->info(kctl, uinfo)) < 0)
goto __unlock;
if ((err = kctl->get(kctl, uctl)) < 0)
goto __unlock;
for (idx = 0; idx < 32; idx++) {
if (!(mixer->mask_recsrc & (1 << idx)))
continue;
Expand Down Expand Up @@ -821,8 +838,12 @@ static int snd_mixer_oss_put_recsrc2(snd_mixer_oss_file_t *fmixer, unsigned int
}
down_read(&card->controls_rwsem);
kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0);
snd_runtime_check(kctl != NULL, err = -ENOENT; goto __unlock);
snd_runtime_check(!(err = kctl->info(kctl, uinfo)), goto __unlock);
if (! kctl) {
err = -ENOENT;
goto __unlock;
}
if ((err = kctl->info(kctl, uinfo)) < 0)
goto __unlock;
for (idx = 0; idx < 32; idx++) {
if (!(mixer->mask_recsrc & (1 << idx)))
continue;
Expand All @@ -836,10 +857,11 @@ static int snd_mixer_oss_put_recsrc2(snd_mixer_oss_file_t *fmixer, unsigned int
break;
slot = NULL;
}
snd_runtime_check(slot != NULL, goto __unlock);
if (! slot)
goto __unlock;
for (idx = 0; idx < uinfo->count; idx++)
uctl->value.enumerated.item[idx] = slot->capture_item;
snd_runtime_check((err = kctl->put(kctl, uctl)) >= 0, );
err = kctl->put(kctl, uctl);
if (err > 0)
snd_ctl_notify(fmixer->card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id);
err = 0;
Expand Down Expand Up @@ -1008,7 +1030,8 @@ static int snd_mixer_oss_build_input(snd_mixer_oss_t *mixer, struct snd_mixer_os
up_read(&mixer->card->controls_rwsem);
if (slot.present != 0) {
pslot = (struct slot *)kmalloc(sizeof(slot), GFP_KERNEL);
snd_runtime_check(pslot != NULL, return -ENOMEM);
if (! pslot)
return -ENOMEM;
*pslot = slot;
pslot->signature = SNDRV_MIXER_OSS_SIGNATURE;
pslot->assigned = ptr;
Expand Down
3 changes: 2 additions & 1 deletion sound/core/pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ static void snd_pcm_proc_info_read(snd_pcm_substream_t *substream, snd_info_buff
snd_pcm_info_t *info;
int err;

snd_runtime_check(substream, return);
if (! substream)
return;

info = kmalloc(sizeof(*info), GFP_KERNEL);
if (! info) {
Expand Down
3 changes: 1 addition & 2 deletions sound/core/pcm_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,8 @@ static inline snd_pcm_uframes_t snd_pcm_update_hw_ptr_pos(snd_pcm_substream_t *s
#ifdef CONFIG_SND_DEBUG
if (pos >= runtime->buffer_size) {
snd_printk(KERN_ERR "BUG: stream = %i, pos = 0x%lx, buffer size = 0x%lx, period size = 0x%lx\n", substream->stream, pos, runtime->buffer_size, runtime->period_size);
} else
}
#endif
snd_runtime_check(pos < runtime->buffer_size, return 0);
pos -= pos % runtime->min_align;
return pos;
}
Expand Down
3 changes: 2 additions & 1 deletion sound/core/pcm_native.c
Original file line number Diff line number Diff line change
Expand Up @@ -2053,7 +2053,8 @@ static int snd_pcm_open(struct inode *inode, struct file *file)
snd_pcm_file_t *pcm_file;
wait_queue_t wait;

snd_runtime_check(device >= SNDRV_MINOR_PCM_PLAYBACK && device < SNDRV_MINOR_DEVICES, return -ENXIO);
if (device < SNDRV_MINOR_PCM_PLAYBACK || device >= SNDRV_MINOR_DEVICES)
return -ENXIO;
pcm = snd_pcm_devices[(cardnum * SNDRV_PCM_DEVICES) + (device % SNDRV_MINOR_PCMS)];
if (pcm == NULL) {
err = -ENODEV;
Expand Down
2 changes: 0 additions & 2 deletions sound/core/seq/seq_midi.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,11 +449,9 @@ snd_seq_midisynth_unregister_port(snd_seq_device_t *dev)
client->ports_per_device[device] = 0;
msynth = client->ports[device];
client->ports[device] = NULL;
snd_runtime_check(msynth != NULL || ports <= 0, goto __skip);
for (p = 0; p < ports; p++)
snd_seq_midisynth_delete(&msynth[p]);
kfree(msynth);
__skip:
client->num_ports--;
if (client->num_ports <= 0) {
snd_seq_delete_kernel_client(client->seq_client);
Expand Down
3 changes: 2 additions & 1 deletion sound/core/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,8 @@ void snd_timer_notify(snd_timer_t *timer, enum sndrv_timer_event event, struct t
snd_timer_instance_t *ti, *ts;
struct list_head *p, *n;

snd_runtime_check(timer->hw.flags & SNDRV_TIMER_HW_SLAVE, return);
if (! (timer->hw.flags & SNDRV_TIMER_HW_SLAVE))
return;
snd_assert(event >= SNDRV_TIMER_EVENT_MSTART && event <= SNDRV_TIMER_EVENT_MRESUME, return);
spin_lock_irqsave(&timer->lock, flags);
if (event == SNDRV_TIMER_EVENT_MSTART ||
Expand Down
Loading

0 comments on commit 7c22f1a

Please sign in to comment.