Commit 7c22f1aa authored by Takashi Iwai's avatar Takashi Iwai Committed by Jaroslav Kysela

[ALSA] Remove snd_runtime_check() macro

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: default avatarTakashi Iwai <tiwai@suse.de>
parent f01cc521
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
</affiliation> </affiliation>
</author> </author>
<date>March 6, 2005</date> <date>October 6, 2005</date>
<edition>0.3.4</edition> <edition>0.3.5</edition>
<abstract> <abstract>
<para> <para>
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
<legalnotice> <legalnotice>
<para> <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>
<para> <para>
...@@ -5998,32 +5998,23 @@ struct _snd_pcm_runtime { ...@@ -5998,32 +5998,23 @@ struct _snd_pcm_runtime {
The first argument is the expression to evaluate, and the The first argument is the expression to evaluate, and the
second argument is the action if it fails. When second argument is the action if it fails. When
<constant>CONFIG_SND_DEBUG</constant>, is set, it will show an <constant>CONFIG_SND_DEBUG</constant>, is set, it will show an
error message such as <computeroutput>BUG? (xxx) (called from error message such as <computeroutput>BUG? (xxx)</computeroutput>
yyy)</computeroutput>. When no debug flag is set, this is together with stack trace.
ignored.
</para> </para>
</section>
<section id="useful-functions-snd-runtime-check">
<title><function>snd_runtime_check()</function></title>
<para> <para>
This macro is quite similar with When no debug flag is set, this macro is ignored.
<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>.
</para> </para>
</section> </section>
<section id="useful-functions-snd-bug"> <section id="useful-functions-snd-bug">
<title><function>snd_BUG()</function></title> <title><function>snd_BUG()</function></title>
<para> <para>
It calls <function>snd_assert(0,)</function> -- that is, just It shows <computeroutput>BUG?</computeroutput> message and
prints the error message at the point. It's useful to show that stack trace as well as <function>snd_assert</function> at the point.
a fatal error happens there. It's useful to show that a fatal error happens there.
</para>
<para>
When no debug flag is set, this macro is ignored.
</para> </para>
</section> </section>
</chapter> </chapter>
......
...@@ -429,34 +429,24 @@ void snd_verbose_printd(const char *file, int line, const char *format, ...) ...@@ -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 * When CONFIG_SND_DEBUG is not set, the expression is executed but
* not checked. * not checked.
*/ */
#define snd_assert(expr, args...) do {\ #define snd_assert(expr, args...) do { \
if (unlikely(!(expr))) { \ if (unlikely(!(expr))) { \
snd_printk(KERN_ERR "BUG? (%s) (called from %p)\n", __ASTRING__(expr), __builtin_return_address(0));\ snd_printk(KERN_ERR "BUG? (%s)\n", __ASTRING__(expr)); \
args;\ dump_stack(); \
}\ args; \
} \
} while (0) } while (0)
/**
* snd_runtime_check - run-time assertion macro #define snd_BUG() do { \
* @expr: expression snd_printk(KERN_ERR "BUG?\n"); \
* @args...: the action dump_stack(); \
*
* 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;\
}\
} while (0) } while (0)
#else /* !CONFIG_SND_DEBUG */ #else /* !CONFIG_SND_DEBUG */
#define snd_printd(fmt, args...) /* nothing */ #define snd_printd(fmt, args...) /* nothing */
#define snd_assert(expr, args...) (void)(expr) #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 */ #endif /* CONFIG_SND_DEBUG */
...@@ -473,8 +463,6 @@ void snd_verbose_printd(const char *file, int line, const char *format, ...) ...@@ -473,8 +463,6 @@ void snd_verbose_printd(const char *file, int line, const char *format, ...)
#define snd_printdd(format, args...) /* nothing */ #define snd_printdd(format, args...) /* nothing */
#endif #endif
#define snd_BUG() snd_assert(0, )
static inline void snd_timestamp_now(struct timespec *tstamp, int timespec) static inline void snd_timestamp_now(struct timespec *tstamp, int timespec)
{ {
......
...@@ -144,7 +144,7 @@ void snd_ctl_notify(snd_card_t *card, unsigned int mask, snd_ctl_elem_id_t *id) ...@@ -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_ctl_file_t *ctl;
snd_kctl_event_t *ev; 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); read_lock(&card->ctl_files_rwlock);
#if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE) #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
card->mixer_oss_change_count++; card->mixer_oss_change_count++;
...@@ -193,8 +193,8 @@ snd_kcontrol_t *snd_ctl_new(snd_kcontrol_t * control, unsigned int access) ...@@ -193,8 +193,8 @@ snd_kcontrol_t *snd_ctl_new(snd_kcontrol_t * control, unsigned int access)
snd_kcontrol_t *kctl; snd_kcontrol_t *kctl;
unsigned int idx; unsigned int idx;
snd_runtime_check(control != NULL, return NULL); snd_assert(control != NULL, return NULL);
snd_runtime_check(control->count > 0, return NULL); snd_assert(control->count > 0, return NULL);
kctl = kzalloc(sizeof(*kctl) + sizeof(snd_kcontrol_volatile_t) * control->count, GFP_KERNEL); kctl = kzalloc(sizeof(*kctl) + sizeof(snd_kcontrol_volatile_t) * control->count, GFP_KERNEL);
if (kctl == NULL) if (kctl == NULL)
return NULL; return NULL;
...@@ -220,7 +220,7 @@ snd_kcontrol_t *snd_ctl_new1(const snd_kcontrol_new_t * ncontrol, void *private_ ...@@ -220,7 +220,7 @@ snd_kcontrol_t *snd_ctl_new1(const snd_kcontrol_new_t * ncontrol, void *private_
snd_kcontrol_t kctl; snd_kcontrol_t kctl;
unsigned int access; unsigned int access;
snd_runtime_check(ncontrol != NULL, return NULL); snd_assert(ncontrol != NULL, return NULL);
snd_assert(ncontrol->info != NULL, return NULL); snd_assert(ncontrol->info != NULL, return NULL);
memset(&kctl, 0, sizeof(kctl)); memset(&kctl, 0, sizeof(kctl));
kctl.id.iface = ncontrol->iface; kctl.id.iface = ncontrol->iface;
...@@ -309,7 +309,7 @@ int snd_ctl_add(snd_card_t * card, snd_kcontrol_t * kcontrol) ...@@ -309,7 +309,7 @@ int snd_ctl_add(snd_card_t * card, snd_kcontrol_t * kcontrol)
snd_ctl_elem_id_t id; snd_ctl_elem_id_t id;
unsigned int idx; 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); snd_assert(kcontrol->info != NULL, return -EINVAL);
id = kcontrol->id; id = kcontrol->id;
down_write(&card->controls_rwsem); down_write(&card->controls_rwsem);
...@@ -355,7 +355,7 @@ int snd_ctl_remove(snd_card_t * card, snd_kcontrol_t * kcontrol) ...@@ -355,7 +355,7 @@ int snd_ctl_remove(snd_card_t * card, snd_kcontrol_t * kcontrol)
snd_ctl_elem_id_t id; snd_ctl_elem_id_t id;
unsigned int idx; unsigned int idx;
snd_runtime_check(card != NULL && kcontrol != NULL, return -EINVAL); snd_assert(card != NULL && kcontrol != NULL, return -EINVAL);
list_del(&kcontrol->list); list_del(&kcontrol->list);
card->controls_count -= kcontrol->count; card->controls_count -= kcontrol->count;
id = kcontrol->id; id = kcontrol->id;
...@@ -468,7 +468,7 @@ snd_kcontrol_t *snd_ctl_find_numid(snd_card_t * card, unsigned int numid) ...@@ -468,7 +468,7 @@ snd_kcontrol_t *snd_ctl_find_numid(snd_card_t * card, unsigned int numid)
struct list_head *list; struct list_head *list;
snd_kcontrol_t *kctl; 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) { list_for_each(list, &card->controls) {
kctl = snd_kcontrol(list); kctl = snd_kcontrol(list);
if (kctl->id.numid <= numid && kctl->id.numid + kctl->count > numid) if (kctl->id.numid <= numid && kctl->id.numid + kctl->count > numid)
...@@ -494,7 +494,7 @@ snd_kcontrol_t *snd_ctl_find_id(snd_card_t * card, snd_ctl_elem_id_t *id) ...@@ -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; struct list_head *list;
snd_kcontrol_t *kctl; 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) if (id->numid != 0)
return snd_ctl_find_numid(card, id->numid); return snd_ctl_find_numid(card, id->numid);
list_for_each(list, &card->controls) { list_for_each(list, &card->controls) {
...@@ -1215,7 +1215,7 @@ static int _snd_ctl_unregister_ioctl(snd_kctl_ioctl_func_t fcn, struct list_head ...@@ -1215,7 +1215,7 @@ static int _snd_ctl_unregister_ioctl(snd_kctl_ioctl_func_t fcn, struct list_head
struct list_head *list; struct list_head *list;
snd_kctl_ioctl_t *p; snd_kctl_ioctl_t *p;
snd_runtime_check(fcn != NULL, return -EINVAL); snd_assert(fcn != NULL, return -EINVAL);
down_write(&snd_ioctl_rwsem); down_write(&snd_ioctl_rwsem);
list_for_each(list, lists) { list_for_each(list, lists) {
p = list_entry(list, snd_kctl_ioctl_t, list); p = list_entry(list, snd_kctl_ioctl_t, list);
......
...@@ -420,7 +420,7 @@ int snd_card_register(snd_card_t * card) ...@@ -420,7 +420,7 @@ int snd_card_register(snd_card_t * card)
int err; int err;
snd_info_entry_t *entry; 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) if ((err = snd_device_register_all(card)) < 0)
return err; return err;
write_lock(&snd_card_rwlock); write_lock(&snd_card_rwlock);
...@@ -524,7 +524,8 @@ int __init snd_card_info_init(void) ...@@ -524,7 +524,8 @@ int __init snd_card_info_init(void)
snd_info_entry_t *entry; snd_info_entry_t *entry;
entry = snd_info_create_module_entry(THIS_MODULE, "cards", NULL); 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_size = PAGE_SIZE;
entry->c.text.read = snd_card_info_read; entry->c.text.read = snd_card_info_read;
if (snd_info_register(entry) < 0) { if (snd_info_register(entry) < 0) {
......
...@@ -521,9 +521,13 @@ static void snd_mixer_oss_get_volume1_vol(snd_mixer_oss_file_t *fmixer, ...@@ -521,9 +521,13 @@ static void snd_mixer_oss_get_volume1_vol(snd_mixer_oss_file_t *fmixer,
uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
if (uinfo == NULL || uctl == NULL) if (uinfo == NULL || uctl == NULL)
goto __unalloc; goto __unalloc;
snd_runtime_check(!kctl->info(kctl, uinfo), goto __unalloc); if (kctl->info(kctl, uinfo))
snd_runtime_check(!kctl->get(kctl, uctl), goto __unalloc); 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->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]); *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) 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]); *right = snd_mixer_oss_conv1(uctl->value.integer.value[1], uinfo->value.integer.min, uinfo->value.integer.max, &pslot->volume[1]);
...@@ -555,8 +559,10 @@ static void snd_mixer_oss_get_volume1_sw(snd_mixer_oss_file_t *fmixer, ...@@ -555,8 +559,10 @@ static void snd_mixer_oss_get_volume1_sw(snd_mixer_oss_file_t *fmixer,
uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
if (uinfo == NULL || uctl == NULL) if (uinfo == NULL || uctl == NULL)
goto __unalloc; goto __unalloc;
snd_runtime_check(!kctl->info(kctl, uinfo), goto __unalloc); if (kctl->info(kctl, uinfo))
snd_runtime_check(!kctl->get(kctl, uctl), goto __unalloc); goto __unalloc;
if (kctl->get(kctl, uctl))
goto __unalloc;
if (!uctl->value.integer.value[0]) { if (!uctl->value.integer.value[0]) {
*left = 0; *left = 0;
if (uinfo->count == 1) if (uinfo->count == 1)
...@@ -616,12 +622,16 @@ static void snd_mixer_oss_put_volume1_vol(snd_mixer_oss_file_t *fmixer, ...@@ -616,12 +622,16 @@ static void snd_mixer_oss_put_volume1_vol(snd_mixer_oss_file_t *fmixer,
uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
if (uinfo == NULL || uctl == NULL) if (uinfo == NULL || uctl == NULL)
goto __unalloc; goto __unalloc;
snd_runtime_check(!kctl->info(kctl, uinfo), goto __unalloc); if (kctl->info(kctl, uinfo))
snd_runtime_check(uinfo->type != SNDRV_CTL_ELEM_TYPE_BOOLEAN || uinfo->value.integer.min != 0 || uinfo->value.integer.max != 1, goto __unalloc); 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); uctl->value.integer.value[0] = snd_mixer_oss_conv2(left, uinfo->value.integer.min, uinfo->value.integer.max);
if (uinfo->count > 1) if (uinfo->count > 1)
uctl->value.integer.value[1] = snd_mixer_oss_conv2(right, uinfo->value.integer.min, uinfo->value.integer.max); 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) if (res > 0)
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id); snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id);
__unalloc: __unalloc:
...@@ -653,7 +663,8 @@ static void snd_mixer_oss_put_volume1_sw(snd_mixer_oss_file_t *fmixer, ...@@ -653,7 +663,8 @@ static void snd_mixer_oss_put_volume1_sw(snd_mixer_oss_file_t *fmixer,
uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
if (uinfo == NULL || uctl == NULL) if (uinfo == NULL || uctl == NULL)
goto __unalloc; goto __unalloc;
snd_runtime_check(!kctl->info(kctl, uinfo), goto __unalloc); if (kctl->info(kctl, uinfo))
goto __unalloc;
if (uinfo->count > 1) { if (uinfo->count > 1) {
uctl->value.integer.value[0] = left > 0 ? 1 : 0; uctl->value.integer.value[0] = left > 0 ? 1 : 0;
uctl->value.integer.value[route ? 3 : 1] = right > 0 ? 1 : 0; uctl->value.integer.value[route ? 3 : 1] = right > 0 ? 1 : 0;
...@@ -664,7 +675,8 @@ static void snd_mixer_oss_put_volume1_sw(snd_mixer_oss_file_t *fmixer, ...@@ -664,7 +675,8 @@ static void snd_mixer_oss_put_volume1_sw(snd_mixer_oss_file_t *fmixer,
} else { } else {
uctl->value.integer.value[0] = (left > 0 || right > 0) ? 1 : 0; 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) if (res > 0)
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id); snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id);
__unalloc: __unalloc:
...@@ -776,9 +788,14 @@ static int snd_mixer_oss_get_recsrc2(snd_mixer_oss_file_t *fmixer, unsigned int ...@@ -776,9 +788,14 @@ static int snd_mixer_oss_get_recsrc2(snd_mixer_oss_file_t *fmixer, unsigned int
} }
down_read(&card->controls_rwsem); down_read(&card->controls_rwsem);
kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0); kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0);
snd_runtime_check(kctl != NULL, err = -ENOENT; goto __unlock); if (! kctl) {
snd_runtime_check(!(err = kctl->info(kctl, uinfo)), goto __unlock); err = -ENOENT;
snd_runtime_check(!(err = kctl->get(kctl, uctl)), goto __unlock); 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++) { for (idx = 0; idx < 32; idx++) {
if (!(mixer->mask_recsrc & (1 << idx))) if (!(mixer->mask_recsrc & (1 << idx)))
continue; continue;
...@@ -821,8 +838,12 @@ static int snd_mixer_oss_put_recsrc2(snd_mixer_oss_file_t *fmixer, unsigned int ...@@ -821,8 +838,12 @@ static int snd_mixer_oss_put_recsrc2(snd_mixer_oss_file_t *fmixer, unsigned int
} }
down_read(&card->controls_rwsem); down_read(&card->controls_rwsem);
kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0); kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0);
snd_runtime_check(kctl != NULL, err = -ENOENT; goto __unlock); if (! kctl) {
snd_runtime_check(!(err = kctl->info(kctl, uinfo)), goto __unlock); err = -ENOENT;
goto __unlock;
}
if ((err = kctl->info(kctl, uinfo)) < 0)
goto __unlock;
for (idx = 0; idx < 32; idx++) { for (idx = 0; idx < 32; idx++) {
if (!(mixer->mask_recsrc & (1 << idx))) if (!(mixer->mask_recsrc & (1 << idx)))
continue; continue;
...@@ -836,10 +857,11 @@ static int snd_mixer_oss_put_recsrc2(snd_mixer_oss_file_t *fmixer, unsigned int ...@@ -836,10 +857,11 @@ static int snd_mixer_oss_put_recsrc2(snd_mixer_oss_file_t *fmixer, unsigned int
break; break;
slot = NULL; slot = NULL;
} }
snd_runtime_check(slot != NULL, goto __unlock); if (! slot)
goto __unlock;
for (idx = 0; idx < uinfo->count; idx++) for (idx = 0; idx < uinfo->count; idx++)
uctl->value.enumerated.item[idx] = slot->capture_item; 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) if (err > 0)
snd_ctl_notify(fmixer->card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id); snd_ctl_notify(fmixer->card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id);
err = 0; err = 0;
...@@ -1008,7 +1030,8 @@ static int snd_mixer_oss_build_input(snd_mixer_oss_t *mixer, struct snd_mixer_os ...@@ -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); up_read(&mixer->card->controls_rwsem);
if (slot.present != 0) { if (slot.present != 0) {
pslot = (struct slot *)kmalloc(sizeof(slot), GFP_KERNEL); pslot = (struct slot *)kmalloc(sizeof(slot), GFP_KERNEL);
snd_runtime_check(pslot != NULL, return -ENOMEM); if (! pslot)
return -ENOMEM;
*pslot = slot; *pslot = slot;
pslot->signature = SNDRV_MIXER_OSS_SIGNATURE; pslot->signature = SNDRV_MIXER_OSS_SIGNATURE;
pslot->assigned = ptr; pslot->assigned = ptr;
......
...@@ -273,7 +273,8 @@ static void snd_pcm_proc_info_read(snd_pcm_substream_t *substream, snd_info_buff ...@@ -273,7 +273,8 @@ static void snd_pcm_proc_info_read(snd_pcm_substream_t *substream, snd_info_buff
snd_pcm_info_t *info; snd_pcm_info_t *info;
int err; int err;
snd_runtime_check(substream, return); if (! substream)
return;
info = kmalloc(sizeof(*info), GFP_KERNEL); info = kmalloc(sizeof(*info), GFP_KERNEL);
if (! info) { if (! info) {
......
...@@ -156,9 +156,8 @@ static inline snd_pcm_uframes_t snd_pcm_update_hw_ptr_pos(snd_pcm_substream_t *s ...@@ -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 #ifdef CONFIG_SND_DEBUG
if (pos >= runtime->buffer_size) { 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); 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 #endif
snd_runtime_check(pos < runtime->buffer_size, return 0);
pos -= pos % runtime->min_align; pos -= pos % runtime->min_align;
return pos; return pos;
} }
......
...@@ -2053,7 +2053,8 @@ static int snd_pcm_open(struct inode *inode, struct file *file) ...@@ -2053,7 +2053,8 @@ static int snd_pcm_open(struct inode *inode, struct file *file)
snd_pcm_file_t *pcm_file; snd_pcm_file_t *pcm_file;
wait_queue_t wait; 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)]; pcm = snd_pcm_devices[(cardnum * SNDRV_PCM_DEVICES) + (device % SNDRV_MINOR_PCMS)];
if (pcm == NULL) { if (pcm == NULL) {
err = -ENODEV; err = -ENODEV;
......
...@@ -449,11 +449,9 @@ snd_seq_midisynth_unregister_port(snd_seq_device_t *dev) ...@@ -449,11 +449,9 @@ snd_seq_midisynth_unregister_port(snd_seq_device_t *dev)
client->ports_per_device[device] = 0; client->ports_per_device[device] = 0;
msynth = client->ports[device]; msynth = client->ports[device];
client->ports[device] = NULL; client->ports[device] = NULL;
snd_runtime_check(msynth != NULL || ports <= 0, goto __skip);
for (p = 0; p < ports; p++) for (p = 0; p < ports; p++)
snd_seq_midisynth_delete(&msynth[p]); snd_seq_midisynth_delete(&msynth[p]);
kfree(msynth); kfree(msynth);
__skip:
client->num_ports--; client->num_ports--;
if (client->num_ports <= 0) { if (client->num_ports <= 0) {
snd_seq_delete_kernel_client(client->seq_client); snd_seq_delete_kernel_client(client->seq_client);
......
...@@ -879,7 +879,8 @@ void snd_timer_notify(snd_timer_t *timer, enum sndrv_timer_event event, struct t ...@@ -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; snd_timer_instance_t *ti, *ts;
struct list_head *p, *n; 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); snd_assert(event >= SNDRV_TIMER_EVENT_MSTART && event <= SNDRV_TIMER_EVENT_MRESUME, return);
spin_lock_irqsave(&timer->lock, flags); spin_lock_irqsave(&timer->lock, flags);
if (event == SNDRV_TIMER_EVENT_MSTART || if (event == SNDRV_TIMER_EVENT_MSTART ||
......
...@@ -173,7 +173,10 @@ static unsigned char divisor_to_rate_register(unsigned int divisor) ...@@ -173,7 +173,10 @@ static unsigned char divisor_to_rate_register(unsigned int divisor)
case 2117: return 6; case 2117: return 6;
case 2558: return 7; case 2558: return 7;
default: default:
snd_runtime_check(divisor >= 21 && divisor <= 192, return 192); if (divisor < 21 || divisor > 192) {
snd_BUG();
return 192;
}
return divisor; return divisor;
} }
} }
......
...@@ -1127,7 +1127,6 @@ snd_kcontrol_t *snd_ac97_cnew(const snd_kcontrol_new_t *_template, ac97_t * ac97 ...@@ -1127,7 +1127,6 @@ snd_kcontrol_t *snd_ac97_cnew(const snd_kcontrol_new_t *_template, ac97_t * ac97
{ {
snd_kcontrol_new_t template; snd_kcontrol_new_t template;
memcpy(&template, _template, sizeof(template)); memcpy(&template, _template, sizeof(template));
snd_runtime_check(!template.index, return NULL);
template.index = ac97->num; template.index = ac97->num;
return snd_ctl_new1(&template, ac97); return snd_ctl_new1(&template, ac97);
} }
......
...@@ -1460,7 +1460,8 @@ int patch_ad1881(ac97_t * ac97) ...@@ -1460,7 +1460,8 @@ int patch_ad1881(ac97_t * ac97)
codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14)); codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14));
codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13)); codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13));
snd_runtime_check(codecs[0] | codecs[1] | codecs[2], goto __end); if (! (codecs[0] || codecs[1] || codecs[2]))
goto __end;
for (idx = 0; idx < 3; idx++) for (idx = 0; idx < 3; idx++)
if (ac97->spec.ad18xx.unchained[idx]) if (ac97->spec.ad18xx.unchained[idx])
......
...@@ -364,12 +364,18 @@ static int snd_emu10k1_gpr_ctl_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value ...@@ -364,12 +364,18 @@ static int snd_emu10k1_gpr_ctl_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value
snd_emu10k1_ptr_write(emu, emu->gpr_base + ctl->gpr[i], 0, db_table[val]); snd_emu10k1_ptr_write(emu, emu->gpr_base + ctl->gpr[i], 0, db_table[val]);
break; break;
case EMU10K1_GPR_TRANSLATION_BASS: case EMU10K1_GPR_TRANSLATION_BASS:
snd_runtime_check((ctl->count % 5) == 0 && (ctl->count / 5) == ctl->vcount, change = -EIO; goto __error); if ((ctl->count % 5) != 0 || (ctl->count / 5) != ctl->vcount) {
change = -EIO;
goto __error;
}
for (j = 0; j < 5; j++) for (j = 0; j < 5; j++)
snd_emu10k1_ptr_write(emu, emu->gpr_base + ctl->gpr[j * ctl->vcount + i], 0, bass_table[val][j]); snd_emu10k1_ptr_write(emu, emu->gpr_base + ctl->gpr[j * ctl->vcount + i], 0, bass_table[val][j]);
break; break;
case EMU10K1_GPR_TRANSLATION_TREBLE: case EMU10K1_GPR_TRANSLATION_TREBLE:
snd_runtime_check((ctl->count % 5) == 0 && (ctl->count / 5) == ctl->vcount, change = -EIO; goto __error); if ((ctl->count % 5) != 0 || (ctl->count / 5) != ctl->vcount) {
change = -EIO;
goto __error;
}
for (j = 0; j < 5; j++) for (j = 0; j < 5; j++)
snd_emu10k1_ptr_write(emu, emu->gpr_base + ctl->gpr[j * ctl->vcount + i], 0, treble_table[val][j]); snd_emu10k1_ptr_write(emu, emu->gpr_base + ctl->gpr[j * ctl->vcount + i], 0, treble_table[val][j]);
break; break;
...@@ -412,8 +418,6 @@ int snd_emu10k1_fx8010_register_irq_handler(emu10k1_t *emu, ...@@ -412,8 +418,6 @@ int snd_emu10k1_fx8010_register_irq_handler(emu10k1_t *emu,
snd_emu10k1_fx8010_irq_t *irq; snd_emu10k1_fx8010_irq_t *irq;
unsigned long flags; unsigned long flags;
snd_runtime_check(emu, return -EINVAL);
snd_runtime_check(handler, return -EINVAL);
irq = kmalloc(sizeof(*irq), GFP_ATOMIC); irq = kmalloc(sizeof(*irq), GFP_ATOMIC);
if (irq == NULL) if (irq == NULL)
return -ENOMEM; return -ENOMEM;
...@@ -442,7 +446,6 @@ int snd_emu10k1_fx8010_unregister_irq_handler(emu10k1_t *emu, ...@@ -442,7 +446,6 @@ int snd_emu10k1_fx8010_unregister_irq_handler(emu10k1_t *emu,
snd_emu10k1_fx8010_irq_t *tmp; snd_emu10k1_fx8010_irq_t *tmp;
unsigned long flags; unsigned long flags;
snd_runtime_check(irq, return -EINVAL);
spin_lock_irqsave(&emu->fx8010.irq_lock, flags); spin_lock_irqsave(&emu->fx8010.irq_lock, flags);
if ((tmp = emu->fx8010.irq_handlers) == irq) { if ((tmp = emu->fx8010.irq_handlers) == irq) {
emu->fx8010.irq_handlers = tmp->next; emu->fx8010.irq_handlers = tmp->next;
...@@ -717,9 +720,15 @@ static int snd_emu10k1_add_controls(emu10k1_t *emu, emu10k1_fx8010_code_t *icode ...@@ -717,9 +720,15 @@ static int snd_emu10k1_add_controls(emu10k1_t *emu, emu10k1_fx8010_code_t *icode
err = -EFAULT; err = -EFAULT;
goto __error; goto __error;
} }
snd_runtime_check(gctl->id.iface == SNDRV_CTL_ELEM_IFACE_MIXER || if (gctl->id.iface != SNDRV_CTL_ELEM_IFACE_MIXER &&
gctl->id.iface == SNDRV_CTL_ELEM_IFACE_PCM, err = -EINVAL; goto __error); gctl->id.iface != SNDRV_CTL_ELEM_IFACE_PCM) {
snd_runtime_check(gctl->id.name[0] != '\0', err = -EINVAL; goto __error); err = -EINVAL;
goto __error;
}
if (! gctl->id.name[0]) {
err = -EINVAL;
goto __error;
}
ctl = snd_emu10k1_look_for_ctl(emu, &gctl->id); ctl = snd_emu10k1_look_for_ctl(emu, &gctl->id);
memset(&knew, 0, sizeof(knew)); memset(&knew, 0, sizeof(knew));
knew.iface = gctl->id.iface; knew.iface = gctl->id.iface;
...@@ -783,7 +792,8 @@ static int snd_emu10k1_del_controls(emu10k1_t *emu, emu10k1_fx8010_code_t *icode ...@@ -783,7 +792,8 @@ static int snd_emu10k1_del_controls(emu10k1_t *emu, emu10k1_fx8010_code_t *icode
for (i = 0, _id = icode->gpr_del_controls; for (i = 0, _id = icode->gpr_del_controls;
i < icode->gpr_del_control_count; i++, _id++) { i < icode->gpr_del_control_count; i++, _id++) {
snd_runtime_check(copy_from_user(&id, _id, sizeof(id)) == 0, return -EFAULT); if (copy_from_user(&id, _id, sizeof(id)))
return -EFAULT;
down_write(&card->controls_rwsem); down_write(&card->controls_rwsem);
ctl = snd_emu10k1_look_for_ctl(emu, &id); ctl = snd_emu10k1_look_for_ctl(emu, &id);
if (ctl) if (ctl)
...@@ -2075,14 +2085,16 @@ void snd_emu10k1_free_efx(emu10k1_t *emu) ...@@ -2075,14 +2085,16 @@ void snd_emu10k1_free_efx(emu10k1_t *emu)
#if 0 // FIXME: who use them? #if 0 // FIXME: who use them?
int snd_emu10k1_fx8010_tone_control_activate(emu10k1_t *emu, int output) int snd_emu10k1_fx8010_tone_control_activate(emu10k1_t *emu, int output)
{ {
snd_runtime_check(output >= 0 && output < 6, return -EINVAL); if (output < 0 || output >= 6)
return -EINVAL;
snd_emu10k1_ptr_write(emu, emu->gpr_base + 0x94 + output, 0, 1); snd_emu10k1_ptr_write(emu, emu->gpr_base + 0x94 + output, 0, 1);
return 0; return 0;
} }
int snd_emu10k1_fx8010_tone_control_deactivate(emu10k1_t *emu, int output) int snd_emu10k1_fx8010_tone_control_deactivate(emu10k1_t *emu, int output)
{ {
snd_runtime_check(output >= 0 && output < 6, return -EINVAL); if (output < 0 || output >= 6)
return -EINVAL;
snd_emu10k1_ptr_write(emu, emu->gpr_base + 0x94 + output, 0, 0); snd_emu10k1_ptr_write(emu, emu->gpr_base + 0x94 + output, 0, 0);
return 0; return 0;
} }
......
...@@ -965,7 +965,8 @@ static void snd_emu10k1_pcm_mixer_notify1(emu10k1_t *emu, snd_kcontrol_t *kctl, ...@@ -965,7 +965,8 @@ static void snd_emu10k1_pcm_mixer_notify1(emu10k1_t *emu, snd_kcontrol_t *kctl,
{ {
snd_ctl_elem_id_t id; snd_ctl_elem_id_t id;
snd_runtime_check(kctl != NULL, return); if (! kctl)
return;
if (activate) if (activate)
kctl->vd[idx].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; kctl->vd[idx].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
else else
......
...@@ -2893,7 +2893,8 @@ static void snd_trident_notify_pcm_change1(snd_card_t * card, snd_kcontrol_t *kc ...@@ -2893,7 +2893,8 @@ static void snd_trident_notify_pcm_change1(snd_card_t * card, snd_kcontrol_t *kc
{ {
snd_ctl_elem_id_t id; snd_ctl_elem_id_t id;
snd_runtime_check(kctl != NULL, return); if (! kctl)
return;
if (activate) if (activate)
kctl->vd[num].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; kctl->vd[num].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
else else
......
...@@ -220,7 +220,8 @@ static int snd_pmac_pcm_prepare(pmac_t *chip, pmac_stream_t *rec, snd_pcm_substr ...@@ -220,7 +220,8 @@ static int snd_pmac_pcm_prepare(pmac_t *chip, pmac_stream_t *rec, snd_pcm_substr
/* set up constraints */ /* set up constraints */
astr = snd_pmac_get_stream(chip, another_stream(rec->stream)); astr = snd_pmac_get_stream(chip, another_stream(rec->stream));
snd_runtime_check(astr, return -EINVAL); if (! astr)
return -EINVAL;
astr->cur_freqs = 1 << rate_index; astr->cur_freqs = 1 << rate_index;
astr->cur_formats = 1 << runtime->format; astr->cur_formats = 1 << runtime->format;
chip->rate_index = rate_index; chip->rate_index = rate_index;
...@@ -467,7 +468,8 @@ static int snd_pmac_hw_rule_rate(snd_pcm_hw_params_t *params, ...@@ -467,7 +468,8 @@ static int snd_pmac_hw_rule_rate(snd_pcm_hw_params_t *params,
pmac_stream_t *rec = snd_pmac_get_stream(chip, rule->deps[0]); pmac_stream_t *rec = snd_pmac_get_stream(chip, rule->deps[0]);
int i, freq_table[8], num_freqs; int i, freq_table[8], num_freqs;
snd_runtime_check(rec, return -EINVAL); if (! rec)
return -EINVAL;
num_freqs = 0; num_freqs = 0;
for (i = chip->num_freqs - 1; i >= 0; i--) { for (i = chip->num_freqs - 1; i >= 0; i--) {
if (rec->cur_freqs & (1 << i)) if (rec->cur_freqs & (1 << i))
...@@ -484,7 +486,8 @@ static int snd_pmac_hw_rule_format(snd_pcm_hw_params_t *params, ...@@ -484,7 +486,8 @@ static int snd_pmac_hw_rule_format(snd_pcm_hw_params_t *params,
pmac_t *chip = rule->private; pmac_t *chip = rule->private;
pmac_stream_t *rec = snd_pmac_get_stream(chip, rule->deps[0]); pmac_stream_t *rec = snd_pmac_get_stream(chip, rule->deps[0]);
snd_runtime_check(rec, return -EINVAL); if (! rec)
return -EINVAL;
return snd_mask_refine_set(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), return snd_mask_refine_set(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT),
rec->cur_formats); rec->cur_formats);
} }
...@@ -569,7 +572,8 @@ static int snd_pmac_pcm_close(pmac_t *chip, pmac_stream_t *rec, snd_pcm_substrea ...@@ -569,7 +572,8 @@ static int snd_pmac_pcm_close(pmac_t *chip, pmac_stream_t *rec, snd_pcm_substrea
snd_pmac_dma_stop(rec); snd_pmac_dma_stop(rec);
astr = snd_pmac_get_stream(chip, another_stream(rec->stream)); astr = snd_pmac_get_stream(chip, another_stream(rec->stream));
snd_runtime_check(astr, return -EINVAL); if (! astr)
return -EINVAL;
/* reset constraints */ /* reset constraints */
astr->cur_freqs = chip->freqs_ok; astr->cur_freqs = chip->freqs_ok;
...@@ -1158,7 +1162,6 @@ int __init snd_pmac_new(snd_card_t *card, pmac_t **chip_return) ...@@ -1158,7 +1162,6 @@ int __init snd_pmac_new(snd_card_t *card, pmac_t **chip_return)
.dev_free = snd_pmac_dev_free, .dev_free = snd_pmac_dev_free,
}; };
snd_runtime_check(chip_return, return -EINVAL);
*chip_return = NULL; *chip_return = NULL;
chip = kzalloc(sizeof(*chip), GFP_KERNEL); chip = kzalloc(sizeof(*chip), GFP_KERNEL);
...@@ -1382,7 +1385,8 @@ static int snd_pmac_sleep_notify(struct pmu_sleep_notifier *self, int when) ...@@ -1382,7 +1385,8 @@ static int snd_pmac_sleep_notify(struct pmu_sleep_notifier *self, int when)
pmac_t *chip; pmac_t *chip;
chip = sleeping_pmac; chip = sleeping_pmac;
snd_runtime_check(chip, return 0); if (! chip)
return 0;
switch (when) { switch (when) {
case PBOOK_SLEEP_NOW: case PBOOK_SLEEP_NOW:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment