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

ALSA: Kill snd_assert() in sound/core/*

Kill snd_assert() in sound/core/*, either removed or replaced with
if () with snd_BUG_ON().
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
Signed-off-by: default avatarJaroslav Kysela <perex@perex.cz>
parent 5ef03460
...@@ -1015,4 +1015,6 @@ static inline void snd_pcm_limit_isa_dma_size(int dma, size_t *max) ...@@ -1015,4 +1015,6 @@ static inline void snd_pcm_limit_isa_dma_size(int dma, size_t *max)
(IEC958_AES1_CON_PCM_CODER<<8)|\ (IEC958_AES1_CON_PCM_CODER<<8)|\
(IEC958_AES3_CON_FS_48000<<24)) (IEC958_AES3_CON_FS_48000<<24))
#define PCM_RUNTIME_CHECK(sub) snd_BUG_ON(!(sub) || !(sub)->runtime)
#endif /* __SOUND_PCM_H */ #endif /* __SOUND_PCM_H */
...@@ -139,7 +139,8 @@ void snd_ctl_notify(struct snd_card *card, unsigned int mask, ...@@ -139,7 +139,8 @@ void snd_ctl_notify(struct snd_card *card, unsigned int mask,
struct snd_ctl_file *ctl; struct snd_ctl_file *ctl;
struct snd_kctl_event *ev; struct snd_kctl_event *ev;
snd_assert(card != NULL && id != NULL, return); if (snd_BUG_ON(!card || !id))
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++;
...@@ -188,8 +189,8 @@ static struct snd_kcontrol *snd_ctl_new(struct snd_kcontrol *control, ...@@ -188,8 +189,8 @@ static struct snd_kcontrol *snd_ctl_new(struct snd_kcontrol *control,
struct snd_kcontrol *kctl; struct snd_kcontrol *kctl;
unsigned int idx; unsigned int idx;
snd_assert(control != NULL, return NULL); if (snd_BUG_ON(!control || !control->count))
snd_assert(control->count > 0, return NULL); return NULL;
kctl = kzalloc(sizeof(*kctl) + sizeof(struct snd_kcontrol_volatile) * control->count, GFP_KERNEL); kctl = kzalloc(sizeof(*kctl) + sizeof(struct snd_kcontrol_volatile) * control->count, GFP_KERNEL);
if (kctl == NULL) { if (kctl == NULL) {
snd_printk(KERN_ERR "Cannot allocate control instance\n"); snd_printk(KERN_ERR "Cannot allocate control instance\n");
...@@ -218,8 +219,8 @@ struct snd_kcontrol *snd_ctl_new1(const struct snd_kcontrol_new *ncontrol, ...@@ -218,8 +219,8 @@ struct snd_kcontrol *snd_ctl_new1(const struct snd_kcontrol_new *ncontrol,
struct snd_kcontrol kctl; struct snd_kcontrol kctl;
unsigned int access; unsigned int access;
snd_assert(ncontrol != NULL, return NULL); if (snd_BUG_ON(!ncontrol || !ncontrol->info))
snd_assert(ncontrol->info != NULL, return NULL); return NULL;
memset(&kctl, 0, sizeof(kctl)); memset(&kctl, 0, sizeof(kctl));
kctl.id.iface = ncontrol->iface; kctl.id.iface = ncontrol->iface;
kctl.id.device = ncontrol->device; kctl.id.device = ncontrol->device;
...@@ -315,8 +316,8 @@ int snd_ctl_add(struct snd_card *card, struct snd_kcontrol *kcontrol) ...@@ -315,8 +316,8 @@ int snd_ctl_add(struct snd_card *card, struct snd_kcontrol *kcontrol)
if (! kcontrol) if (! kcontrol)
return err; return err;
snd_assert(card != NULL, goto error); if (snd_BUG_ON(!card || !kcontrol->info))
snd_assert(kcontrol->info != NULL, goto error); goto error;
id = kcontrol->id; id = kcontrol->id;
down_write(&card->controls_rwsem); down_write(&card->controls_rwsem);
if (snd_ctl_find_id(card, &id)) { if (snd_ctl_find_id(card, &id)) {
...@@ -367,7 +368,8 @@ int snd_ctl_remove(struct snd_card *card, struct snd_kcontrol *kcontrol) ...@@ -367,7 +368,8 @@ int snd_ctl_remove(struct snd_card *card, struct snd_kcontrol *kcontrol)
struct snd_ctl_elem_id id; struct snd_ctl_elem_id id;
unsigned int idx; unsigned int idx;
snd_assert(card != NULL && kcontrol != NULL, return -EINVAL); if (snd_BUG_ON(!card || !kcontrol))
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;
...@@ -487,7 +489,8 @@ struct snd_kcontrol *snd_ctl_find_numid(struct snd_card *card, unsigned int numi ...@@ -487,7 +489,8 @@ struct snd_kcontrol *snd_ctl_find_numid(struct snd_card *card, unsigned int numi
{ {
struct snd_kcontrol *kctl; struct snd_kcontrol *kctl;
snd_assert(card != NULL && numid != 0, return NULL); if (snd_BUG_ON(!card || !numid))
return NULL;
list_for_each_entry(kctl, &card->controls, list) { list_for_each_entry(kctl, &card->controls, list) {
if (kctl->id.numid <= numid && kctl->id.numid + kctl->count > numid) if (kctl->id.numid <= numid && kctl->id.numid + kctl->count > numid)
return kctl; return kctl;
...@@ -514,7 +517,8 @@ struct snd_kcontrol *snd_ctl_find_id(struct snd_card *card, ...@@ -514,7 +517,8 @@ struct snd_kcontrol *snd_ctl_find_id(struct snd_card *card,
{ {
struct snd_kcontrol *kctl; struct snd_kcontrol *kctl;
snd_assert(card != NULL && id != NULL, return NULL); if (snd_BUG_ON(!card || !id))
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_entry(kctl, &card->controls, list) { list_for_each_entry(kctl, &card->controls, list) {
...@@ -647,7 +651,7 @@ static int snd_ctl_elem_info(struct snd_ctl_file *ctl, ...@@ -647,7 +651,7 @@ static int snd_ctl_elem_info(struct snd_ctl_file *ctl,
#endif #endif
result = kctl->info(kctl, info); result = kctl->info(kctl, info);
if (result >= 0) { if (result >= 0) {
snd_assert(info->access == 0, ); snd_BUG_ON(info->access);
index_offset = snd_ctl_get_ioff(kctl, &info->id); index_offset = snd_ctl_get_ioff(kctl, &info->id);
vd = &kctl->vd[index_offset]; vd = &kctl->vd[index_offset];
snd_ctl_build_ioff(&info->id, kctl, index_offset); snd_ctl_build_ioff(&info->id, kctl, index_offset);
...@@ -1160,7 +1164,8 @@ static long snd_ctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg ...@@ -1160,7 +1164,8 @@ static long snd_ctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg
ctl = file->private_data; ctl = file->private_data;
card = ctl->card; card = ctl->card;
snd_assert(card != NULL, return -ENXIO); if (snd_BUG_ON(!card))
return -ENXIO;
switch (cmd) { switch (cmd) {
case SNDRV_CTL_IOCTL_PVERSION: case SNDRV_CTL_IOCTL_PVERSION:
return put_user(SNDRV_CTL_VERSION, ip) ? -EFAULT : 0; return put_user(SNDRV_CTL_VERSION, ip) ? -EFAULT : 0;
...@@ -1222,7 +1227,8 @@ static ssize_t snd_ctl_read(struct file *file, char __user *buffer, ...@@ -1222,7 +1227,8 @@ static ssize_t snd_ctl_read(struct file *file, char __user *buffer,
ssize_t result = 0; ssize_t result = 0;
ctl = file->private_data; ctl = file->private_data;
snd_assert(ctl != NULL && ctl->card != NULL, return -ENXIO); if (snd_BUG_ON(!ctl || !ctl->card))
return -ENXIO;
if (!ctl->subscribed) if (!ctl->subscribed)
return -EBADFD; return -EBADFD;
if (count < sizeof(struct snd_ctl_event)) if (count < sizeof(struct snd_ctl_event))
...@@ -1328,7 +1334,8 @@ static int _snd_ctl_unregister_ioctl(snd_kctl_ioctl_func_t fcn, ...@@ -1328,7 +1334,8 @@ static int _snd_ctl_unregister_ioctl(snd_kctl_ioctl_func_t fcn,
{ {
struct snd_kctl_ioctl *p; struct snd_kctl_ioctl *p;
snd_assert(fcn != NULL, return -EINVAL); if (snd_BUG_ON(!fcn))
return -EINVAL;
down_write(&snd_ioctl_rwsem); down_write(&snd_ioctl_rwsem);
list_for_each_entry(p, lists, list) { list_for_each_entry(p, lists, list) {
if (p->fioctl == fcn) { if (p->fioctl == fcn) {
...@@ -1404,9 +1411,11 @@ static int snd_ctl_dev_register(struct snd_device *device) ...@@ -1404,9 +1411,11 @@ static int snd_ctl_dev_register(struct snd_device *device)
int err, cardnum; int err, cardnum;
char name[16]; char name[16];
snd_assert(card != NULL, return -ENXIO); if (snd_BUG_ON(!card))
return -ENXIO;
cardnum = card->number; cardnum = card->number;
snd_assert(cardnum >= 0 && cardnum < SNDRV_CARDS, return -ENXIO); if (snd_BUG_ON(cardnum < 0 || cardnum >= SNDRV_CARDS))
return -ENXIO;
sprintf(name, "controlC%i", cardnum); sprintf(name, "controlC%i", cardnum);
if ((err = snd_register_device(SNDRV_DEVICE_TYPE_CONTROL, card, -1, if ((err = snd_register_device(SNDRV_DEVICE_TYPE_CONTROL, card, -1,
&snd_ctl_f_ops, card, name)) < 0) &snd_ctl_f_ops, card, name)) < 0)
...@@ -1423,9 +1432,11 @@ static int snd_ctl_dev_disconnect(struct snd_device *device) ...@@ -1423,9 +1432,11 @@ static int snd_ctl_dev_disconnect(struct snd_device *device)
struct snd_ctl_file *ctl; struct snd_ctl_file *ctl;
int err, cardnum; int err, cardnum;
snd_assert(card != NULL, return -ENXIO); if (snd_BUG_ON(!card))
return -ENXIO;
cardnum = card->number; cardnum = card->number;
snd_assert(cardnum >= 0 && cardnum < SNDRV_CARDS, return -ENXIO); if (snd_BUG_ON(cardnum < 0 || cardnum >= SNDRV_CARDS))
return -ENXIO;
down_read(&card->controls_rwsem); down_read(&card->controls_rwsem);
list_for_each_entry(ctl, &card->ctl_files, list) { list_for_each_entry(ctl, &card->ctl_files, list) {
...@@ -1469,7 +1480,8 @@ int snd_ctl_create(struct snd_card *card) ...@@ -1469,7 +1480,8 @@ int snd_ctl_create(struct snd_card *card)
.dev_disconnect = snd_ctl_dev_disconnect, .dev_disconnect = snd_ctl_dev_disconnect,
}; };
snd_assert(card != NULL, return -ENXIO); if (snd_BUG_ON(!card))
return -ENXIO;
return snd_device_new(card, SNDRV_DEV_CONTROL, card, &ops); return snd_device_new(card, SNDRV_DEV_CONTROL, card, &ops);
} }
......
...@@ -398,7 +398,8 @@ static inline long snd_ctl_ioctl_compat(struct file *file, unsigned int cmd, uns ...@@ -398,7 +398,8 @@ static inline long snd_ctl_ioctl_compat(struct file *file, unsigned int cmd, uns
int err; int err;
ctl = file->private_data; ctl = file->private_data;
snd_assert(ctl && ctl->card, return -ENXIO); if (snd_BUG_ON(!ctl || !ctl->card))
return -ENXIO;
switch (cmd) { switch (cmd) {
case SNDRV_CTL_IOCTL_PVERSION: case SNDRV_CTL_IOCTL_PVERSION:
......
...@@ -45,9 +45,8 @@ int snd_device_new(struct snd_card *card, snd_device_type_t type, ...@@ -45,9 +45,8 @@ int snd_device_new(struct snd_card *card, snd_device_type_t type,
{ {
struct snd_device *dev; struct snd_device *dev;
snd_assert(card != NULL, return -ENXIO); if (snd_BUG_ON(!card || !device_data || !ops))
snd_assert(device_data != NULL, return -ENXIO); return -ENXIO;
snd_assert(ops != NULL, return -ENXIO);
dev = kzalloc(sizeof(*dev), GFP_KERNEL); dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (dev == NULL) { if (dev == NULL) {
snd_printk(KERN_ERR "Cannot allocate device\n"); snd_printk(KERN_ERR "Cannot allocate device\n");
...@@ -80,8 +79,8 @@ int snd_device_free(struct snd_card *card, void *device_data) ...@@ -80,8 +79,8 @@ int snd_device_free(struct snd_card *card, void *device_data)
{ {
struct snd_device *dev; struct snd_device *dev;
snd_assert(card != NULL, return -ENXIO); if (snd_BUG_ON(!card || !device_data))
snd_assert(device_data != NULL, return -ENXIO); return -ENXIO;
list_for_each_entry(dev, &card->devices, list) { list_for_each_entry(dev, &card->devices, list) {
if (dev->device_data != device_data) if (dev->device_data != device_data)
continue; continue;
...@@ -123,8 +122,8 @@ int snd_device_disconnect(struct snd_card *card, void *device_data) ...@@ -123,8 +122,8 @@ int snd_device_disconnect(struct snd_card *card, void *device_data)
{ {
struct snd_device *dev; struct snd_device *dev;
snd_assert(card != NULL, return -ENXIO); if (snd_BUG_ON(!card || !device_data))
snd_assert(device_data != NULL, return -ENXIO); return -ENXIO;
list_for_each_entry(dev, &card->devices, list) { list_for_each_entry(dev, &card->devices, list) {
if (dev->device_data != device_data) if (dev->device_data != device_data)
continue; continue;
...@@ -159,8 +158,8 @@ int snd_device_register(struct snd_card *card, void *device_data) ...@@ -159,8 +158,8 @@ int snd_device_register(struct snd_card *card, void *device_data)
struct snd_device *dev; struct snd_device *dev;
int err; int err;
snd_assert(card != NULL, return -ENXIO); if (snd_BUG_ON(!card || !device_data))
snd_assert(device_data != NULL, return -ENXIO); return -ENXIO;
list_for_each_entry(dev, &card->devices, list) { list_for_each_entry(dev, &card->devices, list) {
if (dev->device_data != device_data) if (dev->device_data != device_data)
continue; continue;
...@@ -188,7 +187,8 @@ int snd_device_register_all(struct snd_card *card) ...@@ -188,7 +187,8 @@ int snd_device_register_all(struct snd_card *card)
struct snd_device *dev; struct snd_device *dev;
int err; int err;
snd_assert(card != NULL, return -ENXIO); if (snd_BUG_ON(!card))
return -ENXIO;
list_for_each_entry(dev, &card->devices, list) { list_for_each_entry(dev, &card->devices, list) {
if (dev->state == SNDRV_DEV_BUILD && dev->ops->dev_register) { if (dev->state == SNDRV_DEV_BUILD && dev->ops->dev_register) {
if ((err = dev->ops->dev_register(dev)) < 0) if ((err = dev->ops->dev_register(dev)) < 0)
...@@ -208,7 +208,8 @@ int snd_device_disconnect_all(struct snd_card *card) ...@@ -208,7 +208,8 @@ int snd_device_disconnect_all(struct snd_card *card)
struct snd_device *dev; struct snd_device *dev;
int err = 0; int err = 0;
snd_assert(card != NULL, return -ENXIO); if (snd_BUG_ON(!card))
return -ENXIO;
list_for_each_entry(dev, &card->devices, list) { list_for_each_entry(dev, &card->devices, list) {
if (snd_device_disconnect(card, dev->device_data) < 0) if (snd_device_disconnect(card, dev->device_data) < 0)
err = -ENXIO; err = -ENXIO;
...@@ -226,7 +227,8 @@ int snd_device_free_all(struct snd_card *card, snd_device_cmd_t cmd) ...@@ -226,7 +227,8 @@ int snd_device_free_all(struct snd_card *card, snd_device_cmd_t cmd)
int err; int err;
unsigned int range_low, range_high; unsigned int range_low, range_high;
snd_assert(card != NULL, return -ENXIO); if (snd_BUG_ON(!card))
return -ENXIO;
range_low = cmd * SNDRV_DEV_TYPE_RANGE_SIZE; range_low = cmd * SNDRV_DEV_TYPE_RANGE_SIZE;
range_high = range_low + SNDRV_DEV_TYPE_RANGE_SIZE - 1; range_high = range_low + SNDRV_DEV_TYPE_RANGE_SIZE - 1;
__again: __again:
......
...@@ -353,9 +353,10 @@ int snd_hwdep_new(struct snd_card *card, char *id, int device, ...@@ -353,9 +353,10 @@ int snd_hwdep_new(struct snd_card *card, char *id, int device,
.dev_disconnect = snd_hwdep_dev_disconnect, .dev_disconnect = snd_hwdep_dev_disconnect,
}; };
snd_assert(rhwdep != NULL, return -EINVAL); if (snd_BUG_ON(!card))
return -ENXIO;
if (rhwdep)
*rhwdep = NULL; *rhwdep = NULL;
snd_assert(card != NULL, return -ENXIO);
hwdep = kzalloc(sizeof(*hwdep), GFP_KERNEL); hwdep = kzalloc(sizeof(*hwdep), GFP_KERNEL);
if (hwdep == NULL) { if (hwdep == NULL) {
snd_printk(KERN_ERR "hwdep: cannot allocate\n"); snd_printk(KERN_ERR "hwdep: cannot allocate\n");
...@@ -374,13 +375,15 @@ int snd_hwdep_new(struct snd_card *card, char *id, int device, ...@@ -374,13 +375,15 @@ int snd_hwdep_new(struct snd_card *card, char *id, int device,
} }
init_waitqueue_head(&hwdep->open_wait); init_waitqueue_head(&hwdep->open_wait);
mutex_init(&hwdep->open_mutex); mutex_init(&hwdep->open_mutex);
if (rhwdep)
*rhwdep = hwdep; *rhwdep = hwdep;
return 0; return 0;
} }
static int snd_hwdep_free(struct snd_hwdep *hwdep) static int snd_hwdep_free(struct snd_hwdep *hwdep)
{ {
snd_assert(hwdep != NULL, return -ENXIO); if (!hwdep)
return 0;
if (hwdep->private_free) if (hwdep->private_free)
hwdep->private_free(hwdep); hwdep->private_free(hwdep);
kfree(hwdep); kfree(hwdep);
...@@ -440,7 +443,8 @@ static int snd_hwdep_dev_disconnect(struct snd_device *device) ...@@ -440,7 +443,8 @@ static int snd_hwdep_dev_disconnect(struct snd_device *device)
{ {
struct snd_hwdep *hwdep = device->device_data; struct snd_hwdep *hwdep = device->device_data;
snd_assert(hwdep != NULL, return -ENXIO); if (snd_BUG_ON(!hwdep))
return -ENXIO;
mutex_lock(&register_mutex); mutex_lock(&register_mutex);
if (snd_hwdep_search(hwdep->card, hwdep->device) != hwdep) { if (snd_hwdep_search(hwdep->card, hwdep->device) != hwdep) {
mutex_unlock(&register_mutex); mutex_unlock(&register_mutex);
......
...@@ -217,7 +217,8 @@ static ssize_t snd_info_entry_read(struct file *file, char __user *buffer, ...@@ -217,7 +217,8 @@ static ssize_t snd_info_entry_read(struct file *file, char __user *buffer,
loff_t pos; loff_t pos;
data = file->private_data; data = file->private_data;
snd_assert(data != NULL, return -ENXIO); if (snd_BUG_ON(!data))
return -ENXIO;
pos = *offset; pos = *offset;
if (pos < 0 || (long) pos != pos || (ssize_t) count < 0) if (pos < 0 || (long) pos != pos || (ssize_t) count < 0)
return -EIO; return -EIO;
...@@ -258,7 +259,8 @@ static ssize_t snd_info_entry_write(struct file *file, const char __user *buffer ...@@ -258,7 +259,8 @@ static ssize_t snd_info_entry_write(struct file *file, const char __user *buffer
loff_t pos; loff_t pos;
data = file->private_data; data = file->private_data;
snd_assert(data != NULL, return -ENXIO); if (snd_BUG_ON(!data))
return -ENXIO;
entry = data->entry; entry = data->entry;
pos = *offset; pos = *offset;
if (pos < 0 || (long) pos != pos || (ssize_t) count < 0) if (pos < 0 || (long) pos != pos || (ssize_t) count < 0)
...@@ -614,7 +616,8 @@ int snd_info_card_create(struct snd_card *card) ...@@ -614,7 +616,8 @@ int snd_info_card_create(struct snd_card *card)
char str[8]; char str[8];
struct snd_info_entry *entry; struct snd_info_entry *entry;
snd_assert(card != NULL, return -ENXIO); if (snd_BUG_ON(!card))
return -ENXIO;
sprintf(str, "card%i", card->number); sprintf(str, "card%i", card->number);
if ((entry = snd_info_create_module_entry(card->module, str, NULL)) == NULL) if ((entry = snd_info_create_module_entry(card->module, str, NULL)) == NULL)
...@@ -636,7 +639,8 @@ int snd_info_card_register(struct snd_card *card) ...@@ -636,7 +639,8 @@ int snd_info_card_register(struct snd_card *card)
{ {
struct proc_dir_entry *p; struct proc_dir_entry *p;
snd_assert(card != NULL, return -ENXIO); if (snd_BUG_ON(!card))
return -ENXIO;
if (!strcmp(card->id, card->proc_root->name)) if (!strcmp(card->id, card->proc_root->name))
return 0; return 0;
...@@ -654,7 +658,8 @@ int snd_info_card_register(struct snd_card *card) ...@@ -654,7 +658,8 @@ int snd_info_card_register(struct snd_card *card)
*/ */
void snd_info_card_disconnect(struct snd_card *card) void snd_info_card_disconnect(struct snd_card *card)
{ {
snd_assert(card != NULL, return); if (!card)
return;
mutex_lock(&info_mutex); mutex_lock(&info_mutex);
if (card->proc_root_link) { if (card->proc_root_link) {
snd_remove_proc_entry(snd_proc_root, card->proc_root_link); snd_remove_proc_entry(snd_proc_root, card->proc_root_link);
...@@ -671,7 +676,8 @@ void snd_info_card_disconnect(struct snd_card *card) ...@@ -671,7 +676,8 @@ void snd_info_card_disconnect(struct snd_card *card)
*/ */
int snd_info_card_free(struct snd_card *card) int snd_info_card_free(struct snd_card *card)
{ {
snd_assert(card != NULL, return -ENXIO); if (!card)
return 0;
snd_info_free_entry(card->proc_root); snd_info_free_entry(card->proc_root);
card->proc_root = NULL; card->proc_root = NULL;
return 0; return 0;
...@@ -849,7 +855,7 @@ static void snd_info_disconnect(struct snd_info_entry *entry) ...@@ -849,7 +855,7 @@ static void snd_info_disconnect(struct snd_info_entry *entry)
return; return;
list_del_init(&entry->list); list_del_init(&entry->list);
root = entry->parent == NULL ? snd_proc_root : entry->parent->p; root = entry->parent == NULL ? snd_proc_root : entry->parent->p;
snd_assert(root, return); snd_BUG_ON(!root);
snd_remove_proc_entry(root, entry->p); snd_remove_proc_entry(root, entry->p);
entry->p = NULL; entry->p = NULL;
} }
...@@ -947,7 +953,8 @@ int snd_info_register(struct snd_info_entry * entry) ...@@ -947,7 +953,8 @@ int snd_info_register(struct snd_info_entry * entry)
{ {
struct proc_dir_entry *root, *p = NULL; struct proc_dir_entry *root, *p = NULL;
snd_assert(entry != NULL, return -ENXIO); if (snd_BUG_ON(!entry))
return -ENXIO;
root = entry->parent == NULL ? snd_proc_root : entry->parent->p; root = entry->parent == NULL ? snd_proc_root : entry->parent->p;
mutex_lock(&info_mutex); mutex_lock(&info_mutex);
p = snd_create_proc_entry(entry->name, entry->mode, root); p = snd_create_proc_entry(entry->name, entry->mode, root);
......
...@@ -43,8 +43,10 @@ int snd_oss_info_register(int dev, int num, char *string) ...@@ -43,8 +43,10 @@ int snd_oss_info_register(int dev, int num, char *string)
{ {
char *x; char *x;
snd_assert(dev >= 0 && dev < SNDRV_OSS_INFO_DEV_COUNT, return -ENXIO); if (snd_BUG_ON(dev < 0 || dev >= SNDRV_OSS_INFO_DEV_COUNT))
snd_assert(num >= 0 && num < SNDRV_CARDS, return -ENXIO); return -ENXIO;
if (snd_BUG_ON(num < 0 || num >= SNDRV_CARDS))
return -ENXIO;
mutex_lock(&strings); mutex_lock(&strings);
if (string == NULL) { if (string == NULL) {
if ((x = snd_sndstat_strings[num][dev]) != NULL) { if ((x = snd_sndstat_strings[num][dev]) != NULL) {
......
...@@ -545,7 +545,8 @@ int snd_card_register(struct snd_card *card) ...@@ -545,7 +545,8 @@ int snd_card_register(struct snd_card *card)
{ {
int err; int err;
snd_assert(card != NULL, return -EINVAL); if (snd_BUG_ON(!card))
return -EINVAL;
#ifndef CONFIG_SYSFS_DEPRECATED #ifndef CONFIG_SYSFS_DEPRECATED
if (!card->card_dev) { if (!card->card_dev) {
card->card_dev = device_create_drvdata(sound_class, card->dev, card->card_dev = device_create_drvdata(sound_class, card->dev,
......
...@@ -67,18 +67,6 @@ struct snd_mem_list { ...@@ -67,18 +67,6 @@ struct snd_mem_list {
/* id for pre-allocated buffers */ /* id for pre-allocated buffers */
#define SNDRV_DMA_DEVICE_UNUSED (unsigned int)-1 #define SNDRV_DMA_DEVICE_UNUSED (unsigned int)-1
#ifdef CONFIG_SND_DEBUG
#define __ASTRING__(x) #x
#define snd_assert(expr, args...) do {\
if (!(expr)) {\
printk(KERN_ERR "snd-malloc: BUG? (%s) (called from %p)\n", __ASTRING__(expr), __builtin_return_address(0));\
args;\
}\
} while (0)
#else
#define snd_assert(expr, args...) /**/
#endif
/* /*
* *
* Generic memory allocators * Generic memory allocators
...@@ -111,8 +99,10 @@ void *snd_malloc_pages(size_t size, gfp_t gfp_flags) ...@@ -111,8 +99,10 @@ void *snd_malloc_pages(size_t size, gfp_t gfp_flags)
int pg; int pg;
void *res; void *res;
snd_assert(size > 0, return NULL); if (WARN_ON(!size))
snd_assert(gfp_flags != 0, return NULL); return NULL;
if (WARN_ON(!gfp_flags))
return NULL;
gfp_flags |= __GFP_COMP; /* compound page lets parts be mapped */ gfp_flags |= __GFP_COMP; /* compound page lets parts be mapped */
pg = get_order(size); pg = get_order(size);
if ((res = (void *) __get_free_pages(gfp_flags, pg)) != NULL) if ((res = (void *) __get_free_pages(gfp_flags, pg)) != NULL)
...@@ -152,8 +142,8 @@ static void *snd_malloc_dev_pages(struct device *dev, size_t size, dma_addr_t *d ...@@ -152,8 +142,8 @@ static void *snd_malloc_dev_pages(struct device *dev, size_t size, dma_addr_t *d
void *res; void *res;
gfp_t gfp_flags; gfp_t gfp_flags;
snd_assert(size > 0, return NULL); if (WARN_ON(!dma))
snd_assert(dma != NULL, return NULL); return NULL;
pg = get_order(size); pg = get_order(size);
gfp_flags = GFP_KERNEL gfp_flags = GFP_KERNEL
| __GFP_COMP /* compound page lets parts be mapped */ | __GFP_COMP /* compound page lets parts be mapped */
...@@ -189,8 +179,8 @@ static void *snd_malloc_sbus_pages(struct device *dev, size_t size, ...@@ -189,8 +179,8 @@ static void *snd_malloc_sbus_pages(struct device *dev, size_t size,
int pg; int pg;
void *res; void *res;
snd_assert(size > 0, return NULL); if (WARN_ON(!dma_addr))
snd_assert(dma_addr != NULL, return NULL); return NULL;
pg = get_order(size); pg = get_order(size);
res = sbus_alloc_consistent(sdev, PAGE_SIZE * (1 << pg), dma_addr); res = sbus_alloc_consistent(sdev, PAGE_SIZE * (1 << pg), dma_addr);
if (res != NULL) if (res != NULL)
...@@ -236,8 +226,10 @@ static void snd_free_sbus_pages(struct device *dev, size_t size, ...@@ -236,8 +226,10 @@ static void snd_free_sbus_pages(struct device *dev, size_t size,
int snd_dma_alloc_pages(int type, struct device *device, size_t size, int snd_dma_alloc_pages(int type, struct device *device, size_t size,
struct snd_dma_buffer *dmab) struct snd_dma_buffer *dmab)
{ {
snd_assert(size > 0, return -ENXIO); if (WARN_ON(!size))
snd_assert(dmab != NULL, return -ENXIO); return -ENXIO;
if (WARN_ON(!dmab))
return -ENXIO;
dmab->dev.type = type; dmab->dev.type = type;
dmab->dev.dev = device; dmab->dev.dev = device;
...@@ -292,9 +284,6 @@ int snd_dma_alloc_pages_fallback(int type, struct device *device, size_t size, ...@@ -292,9 +284,6 @@ int snd_dma_alloc_pages_fallback(int type, struct device *device, size_t size,
{ {
int err; int err;
snd_assert(size > 0, return -ENXIO);
snd_assert(dmab != NULL, return -ENXIO);
while ((err = snd_dma_alloc_pages(type, device, size, dmab)) < 0) { while ((err = snd_dma_alloc_pages(type, device, size, dmab)) < 0) {
if (err != -ENOMEM) if (err != -ENOMEM)
return err; return err;
...@@ -353,7 +342,8 @@ size_t snd_dma_get_reserved_buf(struct snd_dma_buffer *dmab, unsigned int id) ...@@ -353,7 +342,8 @@ size_t snd_dma_get_reserved_buf(struct snd_dma_buffer *dmab, unsigned int id)
{ {
struct snd_mem_list *mem; struct snd_mem_list *mem;
snd_assert(dmab, return 0); if (WARN_ON(!dmab))
return 0;
mutex_lock(&list_mutex); mutex_lock(&list_mutex);
list_for_each_entry(mem, &mem_list_head, list) { list_for_each_entry(mem, &mem_list_head, list) {
...@@ -387,7 +377,8 @@ int snd_dma_reserve_buf(struct snd_dma_buffer *dmab, unsigned int id) ...@@ -387,7 +377,8 @@ int snd_dma_reserve_buf(struct snd_dma_buffer *dmab, unsigned int id)
{ {
struct snd_mem_list *mem; struct snd_mem_list *mem;
snd_assert(dmab, return -EINVAL); if (WARN_ON(!dmab))
return -EINVAL;
mem = kmalloc(sizeof(*mem), GFP_KERNEL); mem = kmalloc(sizeof(*mem), GFP_KERNEL);
if (! mem) if (! mem)
return -ENOMEM; return -ENOMEM;
......
...@@ -32,17 +32,18 @@ static snd_pcm_sframes_t copy_transfer(struct snd_pcm_plugin *plugin, ...@@ -32,17 +32,18 @@ static snd_pcm_sframes_t copy_transfer(struct snd_pcm_plugin *plugin,
unsigned int channel; unsigned int channel;
unsigned int nchannels; unsigned int nchannels;
snd_assert(plugin != NULL && src_channels != NULL && dst_channels != NULL, return -ENXIO); if (snd_BUG_ON(!plugin || !src_channels || !dst_channels))
return -ENXIO;
if (frames == 0) if (frames == 0)
return 0; return 0;
nchannels = plugin->src_format.channels; nchannels = plugin->src_format.channels;
for (channel = 0; channel < nchannels; channel++) { for (channel = 0; channel < nchannels; channel++) {
snd_assert(src_channels->area.first % 8 == 0 && if (snd_BUG_ON(src_channels->area.first % 8 ||
src_channels->area.step % 8 == 0, src_channels->area.step % 8))
return -ENXIO); return -ENXIO;
snd_assert(dst_channels->area.first % 8 == 0 && if (snd_BUG_ON(dst_channels->area.first % 8 ||
dst_channels->area.step % 8 == 0, dst_channels->area.step % 8))
return -ENXIO); return -ENXIO;
if (!src_channels->enabled) { if (!src_channels->enabled) {
if (dst_channels->wanted) if (dst_channels->wanted)
snd_pcm_area_silence(&dst_channels->area, 0, frames, plugin->dst_format.format); snd_pcm_area_silence(&dst_channels->area, 0, frames, plugin->dst_format.format);
...@@ -66,15 +67,20 @@ int snd_pcm_plugin_build_copy(struct snd_pcm_substream *plug, ...@@ -66,15 +67,20 @@ int snd_pcm_plugin_build_copy(struct snd_pcm_substream *plug,
struct snd_pcm_plugin *plugin; struct snd_pcm_plugin *plugin;
int width; int width;
snd_assert(r_plugin != NULL, return -ENXIO); if (snd_BUG_ON(!r_plugin))
return -ENXIO;
*r_plugin = NULL; *r_plugin = NULL;
snd_assert(src_format->format == dst_format->format, return -ENXIO); if (snd_BUG_ON(src_format->format != dst_format->format))
snd_assert(src_format->rate == dst_format->rate, return -ENXIO); return -ENXIO;
snd_assert(src_format->channels == dst_format->channels, return -ENXIO); if (snd_BUG_ON(src_format->rate != dst_format->rate))
return -ENXIO;
if (snd_BUG_ON(src_format->channels != dst_format->channels))
return -ENXIO;
width = snd_pcm_format_physical_width(src_format->format); width = snd_pcm_format_physical_width(src_format->format);
snd_assert(width > 0, return -ENXIO); if (snd_BUG_ON(width <= 0))
return -ENXIO;
err = snd_pcm_plugin_build(plug, "copy", src_format, dst_format, err = snd_pcm_plugin_build(plug, "copy", src_format, dst_format,
0, &plugin); 0, &plugin);
......
...@@ -39,14 +39,17 @@ static snd_pcm_sframes_t io_playback_transfer(struct snd_pcm_plugin *plugin, ...@@ -39,14 +39,17 @@ static snd_pcm_sframes_t io_playback_transfer(struct snd_pcm_plugin *plugin,
struct snd_pcm_plugin_channel *dst_channels, struct snd_pcm_plugin_channel *dst_channels,
snd_pcm_uframes_t frames) snd_pcm_uframes_t frames)
{ {
snd_assert(plugin != NULL, return -ENXIO); if (snd_BUG_ON(!plugin))
snd_assert(src_channels != NULL, return -ENXIO); return -ENXIO;
if (snd_BUG_ON(!src_channels))
return -ENXIO;
if (plugin->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED) { if (plugin->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED) {
return pcm_write(plugin->plug, src_channels->area.addr, frames); return pcm_write(plugin->plug, src_channels->area.addr, frames);
} else { } else {
int channel, channels = plugin->dst_format.channels; int channel, channels = plugin->dst_format.channels;
void **bufs = (void**)plugin->extra_data; void **bufs = (void**)plugin->extra_data;
snd_assert(bufs != NULL, return -ENXIO); if (snd_BUG_ON(!bufs))
return -ENXIO;
for (channel = 0; channel < channels; channel++) { for (channel = 0; channel < channels; channel++) {
if (src_channels[channel].enabled) if (src_channels[channel].enabled)
bufs[channel] = src_channels[channel].area.addr; bufs[channel] = src_channels[channel].area.addr;
...@@ -62,14 +65,17 @@ static snd_pcm_sframes_t io_capture_transfer(struct snd_pcm_plugin *plugin, ...@@ -62,14 +65,17 @@ static snd_pcm_sframes_t io_capture_transfer(struct snd_pcm_plugin *plugin,
struct snd_pcm_plugin_channel *dst_channels, struct snd_pcm_plugin_channel *dst_channels,
snd_pcm_uframes_t frames) snd_pcm_uframes_t frames)
{ {
snd_assert(plugin != NULL, return -ENXIO); if (snd_BUG_ON(!plugin))
snd_assert(dst_channels != NULL, return -ENXIO); return -ENXIO;
if (snd_BUG_ON(!dst_channels))
return -ENXIO;
if (plugin->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED) { if (plugin->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED) {
return pcm_read(plugin->plug, dst_channels->area.addr, frames); return pcm_read(plugin->plug, dst_channels->area.addr, frames);
} else { } else {
int channel, channels = plugin->dst_format.channels; int channel, channels = plugin->dst_format.channels;
void **bufs = (void**)plugin->extra_data; void **bufs = (void**)plugin->extra_data;
snd_assert(bufs != NULL, return -ENXIO); if (snd_BUG_ON(!bufs))
return -ENXIO;
for (channel = 0; channel < channels; channel++) { for (channel = 0; channel < channels; channel++) {
if (dst_channels[channel].enabled) if (dst_channels[channel].enabled)
bufs[channel] = dst_channels[channel].area.addr; bufs[channel] = dst_channels[channel].area.addr;
...@@ -107,9 +113,11 @@ int snd_pcm_plugin_build_io(struct snd_pcm_substream *plug, ...@@ -107,9 +113,11 @@ int snd_pcm_plugin_build_io(struct snd_pcm_substream *plug,
struct snd_pcm_plugin_format format; struct snd_pcm_plugin_format format;
struct snd_pcm_plugin *plugin; struct snd_pcm_plugin *plugin;
snd_assert(r_plugin != NULL, return -ENXIO); if (snd_BUG_ON(!r_plugin))
return -ENXIO;
*r_plugin = NULL; *r_plugin = NULL;
snd_assert(plug != NULL && params != NULL, return -ENXIO); if (snd_BUG_ON(!plug || !params))
return -ENXIO;
format.format = params_format(params); format.format = params_format(params);
format.rate = params_rate(params); format.rate = params_rate(params);
format.channels = params_channels(params); format.channels = params_channels(params);
......
...@@ -92,7 +92,8 @@ static snd_pcm_sframes_t linear_transfer(struct snd_pcm_plugin *plugin, ...@@ -92,7 +92,8 @@ static snd_pcm_sframes_t linear_transfer(struct snd_pcm_plugin *plugin,
{ {
struct linear_priv *data; struct linear_priv *data;
snd_assert(plugin != NULL && src_channels != NULL && dst_channels != NULL, return -ENXIO); if (snd_BUG_ON(!plugin || !src_channels || !dst_channels))
return -ENXIO;
data = (struct linear_priv *)plugin->extra_data; data = (struct linear_priv *)plugin->extra_data;
if (frames == 0) if (frames == 0)
return 0; return 0;
...@@ -100,12 +101,12 @@ static snd_pcm_sframes_t linear_transfer(struct snd_pcm_plugin *plugin, ...@@ -100,12 +101,12 @@ static snd_pcm_sframes_t linear_transfer(struct snd_pcm_plugin *plugin,
{ {
unsigned int channel; unsigned int channel;
for (channel = 0; channel < plugin->src_format.channels; channel++) { for (channel = 0; channel < plugin->src_format.channels; channel++) {
snd_assert(src_channels[channel].area.first % 8 == 0 && if (snd_BUG_ON(src_channels[channel].area.first % 8 ||
src_channels[channel].area.step % 8 == 0, src_channels[channel].area.step % 8))
return -ENXIO); return -ENXIO;
snd_assert(dst_channels[channel].area.first % 8 == 0 && if (snd_BUG_ON(dst_channels[channel].area.first % 8 ||
dst_channels[channel].area.step % 8 == 0, dst_channels[channel].area.step % 8))
return -ENXIO); return -ENXIO;
} }
} }
#endif #endif
...@@ -154,13 +155,17 @@ int snd_pcm_plugin_build_linear(struct snd_pcm_substream *plug, ...@@ -154,13 +155,17 @@ int snd_pcm_plugin_build_linear(struct snd_pcm_substream *plug,
struct linear_priv *data; struct linear_priv *data;
struct snd_pcm_plugin *plugin; struct snd_pcm_plugin *plugin;
snd_assert(r_plugin != NULL, return -ENXIO); if (snd_BUG_ON(!r_plugin))
return -ENXIO;
*r_plugin = NULL; *r_plugin = NULL;
snd_assert(src_format->rate == dst_format->rate, return -ENXIO); if (snd_BUG_ON(src_format->rate != dst_format->rate))
snd_assert(src_format->channels == dst_format->channels, return -ENXIO); return -ENXIO;
snd_assert(snd_pcm_format_linear(src_format->format) && if (snd_BUG_ON(src_format->channels != dst_format->channels))
snd_pcm_format_linear(dst_format->format), return -ENXIO); return -ENXIO;
if (snd_BUG_ON(!snd_pcm_format_linear(src_format->format) ||
!snd_pcm_format_linear(dst_format->format)))
return -ENXIO;
err = snd_pcm_plugin_build(plug, "linear format conversion", err = snd_pcm_plugin_build(plug, "linear format conversion",
src_format, dst_format, src_format, dst_format,
......
...@@ -257,8 +257,10 @@ static int snd_mixer_oss_get_volume(struct snd_mixer_oss_file *fmixer, int slot) ...@@ -257,8 +257,10 @@ static int snd_mixer_oss_get_volume(struct snd_mixer_oss_file *fmixer, int slot)
result = pslot->get_volume(fmixer, pslot, &left, &right); result = pslot->get_volume(fmixer, pslot, &left, &right);
if (!pslot->stereo) if (!pslot->stereo)
right = left; right = left;
snd_assert(left >= 0 && left <= 100, return -EIO); if (snd_BUG_ON(left < 0 || left > 100))
snd_assert(right >= 0 && right <= 100, return -EIO); return -EIO;
if (snd_BUG_ON(right < 0 || right > 100))
return -EIO;
if (result >= 0) { if (result >= 0) {
pslot->volume[0] = left; pslot->volume[0] = left;
pslot->volume[1] = right; pslot->volume[1] = right;
...@@ -298,7 +300,8 @@ static int snd_mixer_oss_ioctl1(struct snd_mixer_oss_file *fmixer, unsigned int ...@@ -298,7 +300,8 @@ static int snd_mixer_oss_ioctl1(struct snd_mixer_oss_file *fmixer, unsigned int
int __user *p = argp; int __user *p = argp;
int tmp; int tmp;
snd_assert(fmixer != NULL, return -ENXIO); if (snd_BUG_ON(!fmixer))
return -ENXIO;
if (((cmd >> 8) & 0xff) == 'M') { if (((cmd >> 8) & 0xff) == 'M') {
switch (cmd) { switch (cmd) {
case SOUND_MIXER_INFO: case SOUND_MIXER_INFO:
...@@ -368,7 +371,8 @@ int snd_mixer_oss_ioctl_card(struct snd_card *card, unsigned int cmd, unsigned l ...@@ -368,7 +371,8 @@ int snd_mixer_oss_ioctl_card(struct snd_card *card, unsigned int cmd, unsigned l
{ {
struct snd_mixer_oss_file fmixer; struct snd_mixer_oss_file fmixer;
snd_assert(card != NULL, return -ENXIO); if (snd_BUG_ON(!card))
return -ENXIO;
if (card->mixer_oss == NULL) if (card->mixer_oss == NULL)
return -ENXIO; return -ENXIO;
memset(&fmixer, 0, sizeof(fmixer)); memset(&fmixer, 0, sizeof(fmixer));
...@@ -1284,9 +1288,11 @@ static int snd_mixer_oss_free1(void *private) ...@@ -1284,9 +1288,11 @@ static int snd_mixer_oss_free1(void *private)
struct snd_card *card; struct snd_card *card;
int idx; int idx;
snd_assert(mixer != NULL, return -ENXIO); if (!mixer)
return 0;
card = mixer->card; card = mixer->card;
snd_assert(mixer == card->mixer_oss, return -ENXIO); if (snd_BUG_ON(mixer != card->mixer_oss))
return -ENXIO;
card->mixer_oss = NULL; card->mixer_oss = NULL;
for (idx = 0; idx < SNDRV_OSS_MAX_MIXERS; idx++) { for (idx = 0; idx < SNDRV_OSS_MAX_MIXERS; idx++) {
struct snd_mixer_oss_slot *chn = &mixer->slots[idx]; struct snd_mixer_oss_slot *chn = &mixer->slots[idx];
......
...@@ -252,19 +252,20 @@ static snd_pcm_sframes_t mulaw_transfer(struct snd_pcm_plugin *plugin, ...@@ -252,19 +252,20 @@ static snd_pcm_sframes_t mulaw_transfer(struct snd_pcm_plugin *plugin,
{ {
struct mulaw_priv *data; struct mulaw_priv *data;
snd_assert(plugin != NULL && src_channels != NULL && dst_channels != NULL, return -ENXIO); if (snd_BUG_ON(!plugin || !src_channels || !dst_channels))
return -ENXIO;
if (frames == 0) if (frames == 0)
return 0; return 0;
#ifdef CONFIG_SND_DEBUG #ifdef CONFIG_SND_DEBUG
{ {
unsigned int channel; unsigned int channel;
for (channel = 0; channel < plugin->src_format.channels; channel++) { for (channel = 0; channel < plugin->src_format.channels; channel++) {
snd_assert(src_channels[channel].area.first % 8 == 0 && if (snd_BUG_ON(src_channels[channel].area.first % 8 ||
src_channels[channel].area.step % 8 == 0, src_channels[channel].area.step % 8))
return -ENXIO); return -ENXIO;
snd_assert(dst_channels[channel].area.first % 8 == 0 && if (snd_BUG_ON(dst_channels[channel].area.first % 8 ||
dst_channels[channel].area.step % 8 == 0, dst_channels[channel].area.step % 8))
return -ENXIO); return -ENXIO;
} }
} }
#endif #endif
...@@ -305,11 +306,14 @@ int snd_pcm_plugin_build_mulaw(struct snd_pcm_substream *plug, ...@@ -305,11 +306,14 @@ int snd_pcm_plugin_build_mulaw(struct snd_pcm_substream *plug,
struct snd_pcm_plugin_format *format; struct snd_pcm_plugin_format *format;
mulaw_f func; mulaw_f func;
snd_assert(r_plugin != NULL, return -ENXIO); if (snd_BUG_ON(!r_plugin))
return -ENXIO;
*r_plugin = NULL; *r_plugin = NULL;
snd_assert(src_format->rate == dst_format->rate, return -ENXIO); if (snd_BUG_ON(src_format->rate != dst_format->rate))
snd_assert(src_format->channels == dst_format->channels, return -ENXIO); return -ENXIO;
if (snd_BUG_ON(src_format->channels != dst_format->channels))
return -ENXIO;
if (dst_format->format == SNDRV_PCM_FORMAT_MU_LAW) { if (dst_format->format == SNDRV_PCM_FORMAT_MU_LAW) {
format = src_format; format = src_format;
...@@ -323,7 +327,8 @@ int snd_pcm_plugin_build_mulaw(struct snd_pcm_substream *plug, ...@@ -323,7 +327,8 @@ int snd_pcm_plugin_build_mulaw(struct snd_pcm_substream *plug,
snd_BUG(); snd_BUG();
return -EINVAL; return -EINVAL;
} }
snd_assert(snd_pcm_format_linear(format->format) != 0, return -ENXIO); if (snd_BUG_ON(!snd_pcm_format_linear(format->format)))
return -ENXIO;
err = snd_pcm_plugin_build(plug, "Mu-Law<->linear conversion", err = snd_pcm_plugin_build(plug, "Mu-Law<->linear conversion",
src_format, dst_format, src_format, dst_format,
......
...@@ -452,7 +452,8 @@ static int snd_pcm_hw_param_near(struct snd_pcm_substream *pcm, ...@@ -452,7 +452,8 @@ static int snd_pcm_hw_param_near(struct snd_pcm_substream *pcm,
} else { } else {
*params = *save; *params = *save;
max = snd_pcm_hw_param_max(pcm, params, var, max, &maxdir); max = snd_pcm_hw_param_max(pcm, params, var, max, &maxdir);
snd_assert(max >= 0, return -EINVAL); if (max < 0)
return max;
last = 1; last = 1;
} }
_end: _end:
...@@ -461,7 +462,7 @@ static int snd_pcm_hw_param_near(struct snd_pcm_substream *pcm, ...@@ -461,7 +462,7 @@ static int snd_pcm_hw_param_near(struct snd_pcm_substream *pcm,
v = snd_pcm_hw_param_last(pcm, params, var, dir); v = snd_pcm_hw_param_last(pcm, params, var, dir);
else else
v = snd_pcm_hw_param_first(pcm, params, var, dir); v = snd_pcm_hw_param_first(pcm, params, var, dir);
snd_assert(v >= 0, return -EINVAL); snd_BUG_ON(v < 0);
return v; return v;
} }
...@@ -778,7 +779,8 @@ static int snd_pcm_oss_period_size(struct snd_pcm_substream *substream, ...@@ -778,7 +779,8 @@ static int snd_pcm_oss_period_size(struct snd_pcm_substream *substream,
while (oss_period_size * oss_periods > oss_buffer_size) while (oss_period_size * oss_periods > oss_buffer_size)
oss_period_size /= 2; oss_period_size /= 2;
snd_assert(oss_period_size >= 16, return -EINVAL); if (oss_period_size < 16)
return -EINVAL;
runtime->oss.period_bytes = oss_period_size; runtime->oss.period_bytes = oss_period_size;
runtime->oss.period_frames = 1; runtime->oss.period_frames = 1;
runtime->oss.periods = oss_periods; runtime->oss.periods = oss_periods;
...@@ -895,7 +897,8 @@ static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream) ...@@ -895,7 +897,8 @@ static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream)
} }
} }
err = _snd_pcm_hw_param_set(sparams, SNDRV_PCM_HW_PARAM_FORMAT, sformat, 0); err = _snd_pcm_hw_param_set(sparams, SNDRV_PCM_HW_PARAM_FORMAT, sformat, 0);
snd_assert(err >= 0, goto failure); if (err < 0)
goto failure;
if (direct) { if (direct) {
memcpy(params, sparams, sizeof(*params)); memcpy(params, sparams, sizeof(*params));
...@@ -958,11 +961,13 @@ static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream) ...@@ -958,11 +961,13 @@ static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream)
n = snd_pcm_plug_slave_size(substream, runtime->oss.period_bytes / oss_frame_size); n = snd_pcm_plug_slave_size(substream, runtime->oss.period_bytes / oss_frame_size);
err = snd_pcm_hw_param_near(substream, sparams, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, n, NULL); err = snd_pcm_hw_param_near(substream, sparams, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, n, NULL);
snd_assert(err >= 0, goto failure); if (err < 0)
goto failure;
err = snd_pcm_hw_param_near(substream, sparams, SNDRV_PCM_HW_PARAM_PERIODS, err = snd_pcm_hw_param_near(substream, sparams, SNDRV_PCM_HW_PARAM_PERIODS,
runtime->oss.periods, NULL); runtime->oss.periods, NULL);
snd_assert(err >= 0, goto failure); if (err < 0)
goto failure;
snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DROP, NULL); snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DROP, NULL);
...@@ -1006,7 +1011,10 @@ static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream) ...@@ -1006,7 +1011,10 @@ static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream)
runtime->oss.periods = params_periods(sparams); runtime->oss.periods = params_periods(sparams);
oss_period_size = snd_pcm_plug_client_size(substream, params_period_size(sparams)); oss_period_size = snd_pcm_plug_client_size(substream, params_period_size(sparams));
snd_assert(oss_period_size >= 0, err = -EINVAL; goto failure); if (oss_period_size < 0) {
err = -EINVAL;
goto failure;
}
#ifdef CONFIG_SND_PCM_OSS_PLUGINS #ifdef CONFIG_SND_PCM_OSS_PLUGINS
if (runtime->oss.plugin_first) { if (runtime->oss.plugin_first) {
err = snd_pcm_plug_alloc(substream, oss_period_size); err = snd_pcm_plug_alloc(substream, oss_period_size);
...@@ -1017,7 +1025,10 @@ static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream) ...@@ -1017,7 +1025,10 @@ static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream)
oss_period_size *= oss_frame_size; oss_period_size *= oss_frame_size;
oss_buffer_size = oss_period_size * runtime->oss.periods; oss_buffer_size = oss_period_size * runtime->oss.periods;
snd_assert(oss_buffer_size >= 0, err = -EINVAL; goto failure); if (oss_buffer_size < 0) {
err = -EINVAL;
goto failure;
}
runtime->oss.period_bytes = oss_period_size; runtime->oss.period_bytes = oss_period_size;
runtime->oss.buffer_bytes = oss_buffer_size; runtime->oss.buffer_bytes = oss_buffer_size;
...@@ -1069,7 +1080,8 @@ static int snd_pcm_oss_get_active_substream(struct snd_pcm_oss_file *pcm_oss_fil ...@@ -1069,7 +1080,8 @@ static int snd_pcm_oss_get_active_substream(struct snd_pcm_oss_file *pcm_oss_fil
return err; return err;
} }
} }
snd_assert(asubstream != NULL, return -EIO); if (!asubstream)
return -EIO;
if (r_substream) if (r_substream)
*r_substream = asubstream; *r_substream = asubstream;
return 0; return 0;
...@@ -1764,7 +1776,8 @@ static int snd_pcm_oss_get_formats(struct snd_pcm_oss_file *pcm_oss_file) ...@@ -1764,7 +1776,8 @@ static int snd_pcm_oss_get_formats(struct snd_pcm_oss_file *pcm_oss_file)
err = snd_pcm_hw_refine(substream, params); err = snd_pcm_hw_refine(substream, params);
format_mask = *hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); format_mask = *hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
kfree(params); kfree(params);
snd_assert(err >= 0, return err); if (err < 0)
return err;
for (fmt = 0; fmt < 32; ++fmt) { for (fmt = 0; fmt < 32; ++fmt) {
if (snd_mask_test(&format_mask, fmt)) { if (snd_mask_test(&format_mask, fmt)) {
int f = snd_pcm_oss_format_to(fmt); int f = snd_pcm_oss_format_to(fmt);
...@@ -2250,7 +2263,8 @@ static void snd_pcm_oss_init_substream(struct snd_pcm_substream *substream, ...@@ -2250,7 +2263,8 @@ static void snd_pcm_oss_init_substream(struct snd_pcm_substream *substream,
static int snd_pcm_oss_release_file(struct snd_pcm_oss_file *pcm_oss_file) static int snd_pcm_oss_release_file(struct snd_pcm_oss_file *pcm_oss_file)
{ {
int cidx; int cidx;
snd_assert(pcm_oss_file != NULL, return -ENXIO); if (!pcm_oss_file)
return 0;
for (cidx = 0; cidx < 2; ++cidx) { for (cidx = 0; cidx < 2; ++cidx) {
struct snd_pcm_substream *substream = pcm_oss_file->streams[cidx]; struct snd_pcm_substream *substream = pcm_oss_file->streams[cidx];
if (substream) if (substream)
...@@ -2271,7 +2285,7 @@ static int snd_pcm_oss_open_file(struct file *file, ...@@ -2271,7 +2285,7 @@ static int snd_pcm_oss_open_file(struct file *file,
struct snd_pcm_substream *substream; struct snd_pcm_substream *substream;
unsigned int f_mode = file->f_mode; unsigned int f_mode = file->f_mode;
snd_assert(rpcm_oss_file != NULL, return -EINVAL); if (rpcm_oss_file)
*rpcm_oss_file = NULL; *rpcm_oss_file = NULL;
pcm_oss_file = kzalloc(sizeof(*pcm_oss_file), GFP_KERNEL); pcm_oss_file = kzalloc(sizeof(*pcm_oss_file), GFP_KERNEL);
...@@ -2312,6 +2326,7 @@ static int snd_pcm_oss_open_file(struct file *file, ...@@ -2312,6 +2326,7 @@ static int snd_pcm_oss_open_file(struct file *file,
} }
file->private_data = pcm_oss_file; file->private_data = pcm_oss_file;
if (rpcm_oss_file)
*rpcm_oss_file = pcm_oss_file; *rpcm_oss_file = pcm_oss_file;
return 0; return 0;
} }
...@@ -2321,7 +2336,8 @@ static int snd_task_name(struct task_struct *task, char *name, size_t size) ...@@ -2321,7 +2336,8 @@ static int snd_task_name(struct task_struct *task, char *name, size_t size)
{ {
unsigned int idx; unsigned int idx;
snd_assert(task != NULL && name != NULL && size >= 2, return -EINVAL); if (snd_BUG_ON(!task || !name || size < 2))
return -EINVAL;
for (idx = 0; idx < sizeof(task->comm) && idx + 1 < size; idx++) for (idx = 0; idx < sizeof(task->comm) && idx + 1 < size; idx++)
name[idx] = task->comm[idx]; name[idx] = task->comm[idx];
name[idx] = '\0'; name[idx] = '\0';
...@@ -2415,7 +2431,8 @@ static int snd_pcm_oss_release(struct inode *inode, struct file *file) ...@@ -2415,7 +2431,8 @@ static int snd_pcm_oss_release(struct inode *inode, struct file *file)
substream = pcm_oss_file->streams[SNDRV_PCM_STREAM_PLAYBACK]; substream = pcm_oss_file->streams[SNDRV_PCM_STREAM_PLAYBACK];
if (substream == NULL) if (substream == NULL)
substream = pcm_oss_file->streams[SNDRV_PCM_STREAM_CAPTURE]; substream = pcm_oss_file->streams[SNDRV_PCM_STREAM_CAPTURE];
snd_assert(substream != NULL, return -ENXIO); if (snd_BUG_ON(!substream))
return -ENXIO;
pcm = substream->pcm; pcm = substream->pcm;
if (!pcm->card->shutdown) if (!pcm->card->shutdown)
snd_pcm_oss_sync(pcm_oss_file); snd_pcm_oss_sync(pcm_oss_file);
...@@ -2448,7 +2465,8 @@ static long snd_pcm_oss_ioctl(struct file *file, unsigned int cmd, unsigned long ...@@ -2448,7 +2465,8 @@ static long snd_pcm_oss_ioctl(struct file *file, unsigned int cmd, unsigned long
if (substream != NULL) if (substream != NULL)
break; break;
} }
snd_assert(substream != NULL, return -ENXIO); if (snd_BUG_ON(idx >= 2))
return -ENXIO;
return snd_mixer_oss_ioctl_card(substream->pcm->card, cmd, arg); return snd_mixer_oss_ioctl_card(substream->pcm->card, cmd, arg);
} }
#endif #endif
......
...@@ -62,7 +62,8 @@ static int snd_pcm_plugin_alloc(struct snd_pcm_plugin *plugin, snd_pcm_uframes_t ...@@ -62,7 +62,8 @@ static int snd_pcm_plugin_alloc(struct snd_pcm_plugin *plugin, snd_pcm_uframes_t
if ((width = snd_pcm_format_physical_width(format->format)) < 0) if ((width = snd_pcm_format_physical_width(format->format)) < 0)
return width; return width;
size = frames * format->channels * width; size = frames * format->channels * width;
snd_assert((size % 8) == 0, return -ENXIO); if (snd_BUG_ON(size % 8))
return -ENXIO;
size /= 8; size /= 8;
if (plugin->buf_frames < frames) { if (plugin->buf_frames < frames) {
vfree(plugin->buf); vfree(plugin->buf);
...@@ -84,7 +85,8 @@ static int snd_pcm_plugin_alloc(struct snd_pcm_plugin *plugin, snd_pcm_uframes_t ...@@ -84,7 +85,8 @@ static int snd_pcm_plugin_alloc(struct snd_pcm_plugin *plugin, snd_pcm_uframes_t
c->area.step = format->channels * width; c->area.step = format->channels * width;
} }
} else if (plugin->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) { } else if (plugin->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
snd_assert((size % format->channels) == 0,); if (snd_BUG_ON(size % format->channels))
return -EINVAL;
size /= format->channels; size /= format->channels;
for (channel = 0; channel < format->channels; channel++, c++) { for (channel = 0; channel < format->channels; channel++, c++) {
c->frames = frames; c->frames = frames;
...@@ -102,13 +104,15 @@ static int snd_pcm_plugin_alloc(struct snd_pcm_plugin *plugin, snd_pcm_uframes_t ...@@ -102,13 +104,15 @@ static int snd_pcm_plugin_alloc(struct snd_pcm_plugin *plugin, snd_pcm_uframes_t
int snd_pcm_plug_alloc(struct snd_pcm_substream *plug, snd_pcm_uframes_t frames) int snd_pcm_plug_alloc(struct snd_pcm_substream *plug, snd_pcm_uframes_t frames)
{ {
int err; int err;
snd_assert(snd_pcm_plug_first(plug) != NULL, return -ENXIO); if (snd_BUG_ON(!snd_pcm_plug_first(plug)))
return -ENXIO;
if (snd_pcm_plug_stream(plug) == SNDRV_PCM_STREAM_PLAYBACK) { if (snd_pcm_plug_stream(plug) == SNDRV_PCM_STREAM_PLAYBACK) {
struct snd_pcm_plugin *plugin = snd_pcm_plug_first(plug); struct snd_pcm_plugin *plugin = snd_pcm_plug_first(plug);
while (plugin->next) { while (plugin->next) {
if (plugin->dst_frames) if (plugin->dst_frames)
frames = plugin->dst_frames(plugin, frames); frames = plugin->dst_frames(plugin, frames);
snd_assert(frames > 0, return -ENXIO); if (snd_BUG_ON(frames <= 0))
return -ENXIO;
plugin = plugin->next; plugin = plugin->next;
err = snd_pcm_plugin_alloc(plugin, frames); err = snd_pcm_plugin_alloc(plugin, frames);
if (err < 0) if (err < 0)
...@@ -119,7 +123,8 @@ int snd_pcm_plug_alloc(struct snd_pcm_substream *plug, snd_pcm_uframes_t frames) ...@@ -119,7 +123,8 @@ int snd_pcm_plug_alloc(struct snd_pcm_substream *plug, snd_pcm_uframes_t frames)
while (plugin->prev) { while (plugin->prev) {
if (plugin->src_frames) if (plugin->src_frames)
frames = plugin->src_frames(plugin, frames); frames = plugin->src_frames(plugin, frames);
snd_assert(frames > 0, return -ENXIO); if (snd_BUG_ON(frames <= 0))
return -ENXIO;
plugin = plugin->prev; plugin = plugin->prev;
err = snd_pcm_plugin_alloc(plugin, frames); err = snd_pcm_plugin_alloc(plugin, frames);
if (err < 0) if (err < 0)
...@@ -148,8 +153,10 @@ int snd_pcm_plugin_build(struct snd_pcm_substream *plug, ...@@ -148,8 +153,10 @@ int snd_pcm_plugin_build(struct snd_pcm_substream *plug,
struct snd_pcm_plugin *plugin; struct snd_pcm_plugin *plugin;
unsigned int channels; unsigned int channels;
snd_assert(plug != NULL, return -ENXIO); if (snd_BUG_ON(!plug))
snd_assert(src_format != NULL && dst_format != NULL, return -ENXIO); return -ENXIO;
if (snd_BUG_ON(!src_format || !dst_format))
return -ENXIO;
plugin = kzalloc(sizeof(*plugin) + extra, GFP_KERNEL); plugin = kzalloc(sizeof(*plugin) + extra, GFP_KERNEL);
if (plugin == NULL) if (plugin == NULL)
return -ENOMEM; return -ENOMEM;
...@@ -159,10 +166,10 @@ int snd_pcm_plugin_build(struct snd_pcm_substream *plug, ...@@ -159,10 +166,10 @@ int snd_pcm_plugin_build(struct snd_pcm_substream *plug,
plugin->access = SNDRV_PCM_ACCESS_RW_INTERLEAVED; plugin->access = SNDRV_PCM_ACCESS_RW_INTERLEAVED;
plugin->src_format = *src_format; plugin->src_format = *src_format;
plugin->src_width = snd_pcm_format_physical_width(src_format->format); plugin->src_width = snd_pcm_format_physical_width(src_format->format);
snd_assert(plugin->src_width > 0, ); snd_BUG_ON(plugin->src_width <= 0);
plugin->dst_format = *dst_format; plugin->dst_format = *dst_format;
plugin->dst_width = snd_pcm_format_physical_width(dst_format->format); plugin->dst_width = snd_pcm_format_physical_width(dst_format->format);
snd_assert(plugin->dst_width > 0, ); snd_BUG_ON(plugin->dst_width <= 0);
if (plugin->stream == SNDRV_PCM_STREAM_PLAYBACK) if (plugin->stream == SNDRV_PCM_STREAM_PLAYBACK)
channels = src_format->channels; channels = src_format->channels;
else else
...@@ -194,7 +201,8 @@ snd_pcm_sframes_t snd_pcm_plug_client_size(struct snd_pcm_substream *plug, snd_p ...@@ -194,7 +201,8 @@ snd_pcm_sframes_t snd_pcm_plug_client_size(struct snd_pcm_substream *plug, snd_p
struct snd_pcm_plugin *plugin, *plugin_prev, *plugin_next; struct snd_pcm_plugin *plugin, *plugin_prev, *plugin_next;
int stream = snd_pcm_plug_stream(plug); int stream = snd_pcm_plug_stream(plug);
snd_assert(plug != NULL, return -ENXIO); if (snd_BUG_ON(!plug))
return -ENXIO;
if (drv_frames == 0) if (drv_frames == 0)
return 0; return 0;
if (stream == SNDRV_PCM_STREAM_PLAYBACK) { if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
...@@ -224,7 +232,8 @@ snd_pcm_sframes_t snd_pcm_plug_slave_size(struct snd_pcm_substream *plug, snd_pc ...@@ -224,7 +232,8 @@ snd_pcm_sframes_t snd_pcm_plug_slave_size(struct snd_pcm_substream *plug, snd_pc
snd_pcm_sframes_t frames; snd_pcm_sframes_t frames;
int stream = snd_pcm_plug_stream(plug); int stream = snd_pcm_plug_stream(plug);
snd_assert(plug != NULL, return -ENXIO); if (snd_BUG_ON(!plug))
return -ENXIO;
if (clt_frames == 0) if (clt_frames == 0)
return 0; return 0;
frames = clt_frames; frames = clt_frames;
...@@ -540,7 +549,8 @@ snd_pcm_sframes_t snd_pcm_plug_client_channels_buf(struct snd_pcm_substream *plu ...@@ -540,7 +549,8 @@ snd_pcm_sframes_t snd_pcm_plug_client_channels_buf(struct snd_pcm_substream *plu
int width, nchannels, channel; int width, nchannels, channel;
int stream = snd_pcm_plug_stream(plug); int stream = snd_pcm_plug_stream(plug);
snd_assert(buf != NULL, return -ENXIO); if (snd_BUG_ON(!buf))
return -ENXIO;
if (stream == SNDRV_PCM_STREAM_PLAYBACK) { if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
plugin = snd_pcm_plug_first(plug); plugin = snd_pcm_plug_first(plug);
format = &plugin->src_format; format = &plugin->src_format;
...@@ -553,7 +563,9 @@ snd_pcm_sframes_t snd_pcm_plug_client_channels_buf(struct snd_pcm_substream *plu ...@@ -553,7 +563,9 @@ snd_pcm_sframes_t snd_pcm_plug_client_channels_buf(struct snd_pcm_substream *plu
if ((width = snd_pcm_format_physical_width(format->format)) < 0) if ((width = snd_pcm_format_physical_width(format->format)) < 0)
return width; return width;
nchannels = format->channels; nchannels = format->channels;
snd_assert(plugin->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED || format->channels <= 1, return -ENXIO); if (snd_BUG_ON(plugin->access != SNDRV_PCM_ACCESS_RW_INTERLEAVED &&
format->channels > 1))
return -ENXIO;
for (channel = 0; channel < nchannels; channel++, v++) { for (channel = 0; channel < nchannels; channel++, v++) {
v->frames = count; v->frames = count;
v->enabled = 1; v->enabled = 1;
......
...@@ -185,7 +185,8 @@ static snd_pcm_sframes_t rate_src_frames(struct snd_pcm_plugin *plugin, snd_pcm_ ...@@ -185,7 +185,8 @@ static snd_pcm_sframes_t rate_src_frames(struct snd_pcm_plugin *plugin, snd_pcm_
struct rate_priv *data; struct rate_priv *data;
snd_pcm_sframes_t res; snd_pcm_sframes_t res;
snd_assert(plugin != NULL, return -ENXIO); if (snd_BUG_ON(!plugin))
return -ENXIO;
if (frames == 0) if (frames == 0)
return 0; return 0;
data = (struct rate_priv *)plugin->extra_data; data = (struct rate_priv *)plugin->extra_data;
...@@ -217,7 +218,8 @@ static snd_pcm_sframes_t rate_dst_frames(struct snd_pcm_plugin *plugin, snd_pcm_ ...@@ -217,7 +218,8 @@ static snd_pcm_sframes_t rate_dst_frames(struct snd_pcm_plugin *plugin, snd_pcm_
struct rate_priv *data; struct rate_priv *data;
snd_pcm_sframes_t res; snd_pcm_sframes_t res;
snd_assert(plugin != NULL, return -ENXIO); if (snd_BUG_ON(!plugin))
return -ENXIO;
if (frames == 0) if (frames == 0)
return 0; return 0;
data = (struct rate_priv *)plugin->extra_data; data = (struct rate_priv *)plugin->extra_data;
...@@ -252,19 +254,20 @@ static snd_pcm_sframes_t rate_transfer(struct snd_pcm_plugin *plugin, ...@@ -252,19 +254,20 @@ static snd_pcm_sframes_t rate_transfer(struct snd_pcm_plugin *plugin,
snd_pcm_uframes_t dst_frames; snd_pcm_uframes_t dst_frames;
struct rate_priv *data; struct rate_priv *data;
snd_assert(plugin != NULL && src_channels != NULL && dst_channels != NULL, return -ENXIO); if (snd_BUG_ON(!plugin || !src_channels || !dst_channels))
return -ENXIO;
if (frames == 0) if (frames == 0)
return 0; return 0;
#ifdef CONFIG_SND_DEBUG #ifdef CONFIG_SND_DEBUG
{ {
unsigned int channel; unsigned int channel;
for (channel = 0; channel < plugin->src_format.channels; channel++) { for (channel = 0; channel < plugin->src_format.channels; channel++) {
snd_assert(src_channels[channel].area.first % 8 == 0 && if (snd_BUG_ON(src_channels[channel].area.first % 8 ||
src_channels[channel].area.step % 8 == 0, src_channels[channel].area.step % 8))
return -ENXIO); return -ENXIO;
snd_assert(dst_channels[channel].area.first % 8 == 0 && if (snd_BUG_ON(dst_channels[channel].area.first % 8 ||
dst_channels[channel].area.step % 8 == 0, dst_channels[channel].area.step % 8))
return -ENXIO); return -ENXIO;
} }
} }
#endif #endif
...@@ -281,7 +284,8 @@ static int rate_action(struct snd_pcm_plugin *plugin, ...@@ -281,7 +284,8 @@ static int rate_action(struct snd_pcm_plugin *plugin,
enum snd_pcm_plugin_action action, enum snd_pcm_plugin_action action,
unsigned long udata) unsigned long udata)
{ {
snd_assert(plugin != NULL, return -ENXIO); if (snd_BUG_ON(!plugin))
return -ENXIO;
switch (action) { switch (action) {
case INIT: case INIT:
case PREPARE: case PREPARE:
...@@ -302,14 +306,20 @@ int snd_pcm_plugin_build_rate(struct snd_pcm_substream *plug, ...@@ -302,14 +306,20 @@ int snd_pcm_plugin_build_rate(struct snd_pcm_substream *plug,
struct rate_priv *data; struct rate_priv *data;
struct snd_pcm_plugin *plugin; struct snd_pcm_plugin *plugin;
snd_assert(r_plugin != NULL, return -ENXIO); if (snd_BUG_ON(!r_plugin))
return -ENXIO;
*r_plugin = NULL; *r_plugin = NULL;
snd_assert(src_format->channels == dst_format->channels, return -ENXIO); if (snd_BUG_ON(src_format->channels != dst_format->channels))
snd_assert(src_format->channels > 0, return -ENXIO); return -ENXIO;
snd_assert(src_format->format == SNDRV_PCM_FORMAT_S16, return -ENXIO); if (snd_BUG_ON(src_format->channels <= 0))
snd_assert(dst_format->format == SNDRV_PCM_FORMAT_S16, return -ENXIO); return -ENXIO;
snd_assert(src_format->rate != dst_format->rate, return -ENXIO); if (snd_BUG_ON(src_format->format != SNDRV_PCM_FORMAT_S16))
return -ENXIO;
if (snd_BUG_ON(dst_format->format != SNDRV_PCM_FORMAT_S16))
return -ENXIO;
if (snd_BUG_ON(src_format->rate == dst_format->rate))
return -ENXIO;
err = snd_pcm_plugin_build(plug, "rate conversion", err = snd_pcm_plugin_build(plug, "rate conversion",
src_format, dst_format, src_format, dst_format,
......
...@@ -54,7 +54,8 @@ static snd_pcm_sframes_t route_transfer(struct snd_pcm_plugin *plugin, ...@@ -54,7 +54,8 @@ static snd_pcm_sframes_t route_transfer(struct snd_pcm_plugin *plugin,
struct snd_pcm_plugin_channel *dvp; struct snd_pcm_plugin_channel *dvp;
int format; int format;
snd_assert(plugin != NULL && src_channels != NULL && dst_channels != NULL, return -ENXIO); if (snd_BUG_ON(!plugin || !src_channels || !dst_channels))
return -ENXIO;
if (frames == 0) if (frames == 0)
return 0; return 0;
...@@ -90,10 +91,13 @@ int snd_pcm_plugin_build_route(struct snd_pcm_substream *plug, ...@@ -90,10 +91,13 @@ int snd_pcm_plugin_build_route(struct snd_pcm_substream *plug,
struct snd_pcm_plugin *plugin; struct snd_pcm_plugin *plugin;
int err; int err;
snd_assert(r_plugin != NULL, return -ENXIO); if (snd_BUG_ON(!r_plugin))
return -ENXIO;
*r_plugin = NULL; *r_plugin = NULL;
snd_assert(src_format->rate == dst_format->rate, return -ENXIO); if (snd_BUG_ON(src_format->rate != dst_format->rate))
snd_assert(src_format->format == dst_format->format, return -ENXIO); return -ENXIO;
if (snd_BUG_ON(src_format->format != dst_format->format))
return -ENXIO;
err = snd_pcm_plugin_build(plug, "route conversion", err = snd_pcm_plugin_build(plug, "route conversion",
src_format, dst_format, 0, &plugin); src_format, dst_format, 0, &plugin);
......
...@@ -256,7 +256,6 @@ static char *snd_pcm_tstamp_mode_names[] = { ...@@ -256,7 +256,6 @@ static char *snd_pcm_tstamp_mode_names[] = {
static const char *snd_pcm_stream_name(int stream) static const char *snd_pcm_stream_name(int stream)
{ {
snd_assert(stream <= SNDRV_PCM_STREAM_LAST, return NULL);
return snd_pcm_stream_names[stream]; return snd_pcm_stream_names[stream];
} }
...@@ -272,7 +271,6 @@ static const char *snd_pcm_subformat_name(snd_pcm_subformat_t subformat) ...@@ -272,7 +271,6 @@ static const char *snd_pcm_subformat_name(snd_pcm_subformat_t subformat)
static const char *snd_pcm_tstamp_mode_name(int mode) static const char *snd_pcm_tstamp_mode_name(int mode)
{ {
snd_assert(mode <= SNDRV_PCM_TSTAMP_LAST, return NULL);
return snd_pcm_tstamp_mode_names[mode]; return snd_pcm_tstamp_mode_names[mode];
} }
...@@ -706,9 +704,10 @@ int snd_pcm_new(struct snd_card *card, char *id, int device, ...@@ -706,9 +704,10 @@ int snd_pcm_new(struct snd_card *card, char *id, int device,
.dev_disconnect = snd_pcm_dev_disconnect, .dev_disconnect = snd_pcm_dev_disconnect,
}; };
snd_assert(rpcm != NULL, return -EINVAL); if (snd_BUG_ON(!card))
return -ENXIO;
if (rpcm)
*rpcm = NULL; *rpcm = NULL;
snd_assert(card != NULL, return -ENXIO);
pcm = kzalloc(sizeof(*pcm), GFP_KERNEL); pcm = kzalloc(sizeof(*pcm), GFP_KERNEL);
if (pcm == NULL) { if (pcm == NULL) {
snd_printk(KERN_ERR "Cannot allocate PCM\n"); snd_printk(KERN_ERR "Cannot allocate PCM\n");
...@@ -732,6 +731,7 @@ int snd_pcm_new(struct snd_card *card, char *id, int device, ...@@ -732,6 +731,7 @@ int snd_pcm_new(struct snd_card *card, char *id, int device,
snd_pcm_free(pcm); snd_pcm_free(pcm);
return err; return err;
} }
if (rpcm)
*rpcm = pcm; *rpcm = pcm;
return 0; return 0;
} }
...@@ -766,7 +766,8 @@ static int snd_pcm_free(struct snd_pcm *pcm) ...@@ -766,7 +766,8 @@ static int snd_pcm_free(struct snd_pcm *pcm)
{ {
struct snd_pcm_notify *notify; struct snd_pcm_notify *notify;
snd_assert(pcm != NULL, return -ENXIO); if (!pcm)
return 0;
list_for_each_entry(notify, &snd_pcm_notify_list, list) { list_for_each_entry(notify, &snd_pcm_notify_list, list) {
notify->n_unregister(pcm); notify->n_unregister(pcm);
} }
...@@ -797,9 +798,9 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream, ...@@ -797,9 +798,9 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,
int prefer_subdevice = -1; int prefer_subdevice = -1;
size_t size; size_t size;
snd_assert(rsubstream != NULL, return -EINVAL); if (snd_BUG_ON(!pcm || !rsubstream))
return -ENXIO;
*rsubstream = NULL; *rsubstream = NULL;
snd_assert(pcm != NULL, return -ENXIO);
pstr = &pcm->streams[stream]; pstr = &pcm->streams[stream];
if (pstr->substream == NULL || pstr->substream_count == 0) if (pstr->substream == NULL || pstr->substream_count == 0)
return -ENODEV; return -ENODEV;
...@@ -907,8 +908,9 @@ void snd_pcm_detach_substream(struct snd_pcm_substream *substream) ...@@ -907,8 +908,9 @@ void snd_pcm_detach_substream(struct snd_pcm_substream *substream)
{ {
struct snd_pcm_runtime *runtime; struct snd_pcm_runtime *runtime;
if (PCM_RUNTIME_CHECK(substream))
return;
runtime = substream->runtime; runtime = substream->runtime;
snd_assert(runtime != NULL, return);
if (runtime->private_free != NULL) if (runtime->private_free != NULL)
runtime->private_free(runtime); runtime->private_free(runtime);
snd_free_pages((void*)runtime->status, snd_free_pages((void*)runtime->status,
...@@ -953,7 +955,8 @@ static int snd_pcm_dev_register(struct snd_device *device) ...@@ -953,7 +955,8 @@ static int snd_pcm_dev_register(struct snd_device *device)
struct snd_pcm *pcm = device->device_data; struct snd_pcm *pcm = device->device_data;
struct device *dev; struct device *dev;
snd_assert(pcm != NULL && device != NULL, return -ENXIO); if (snd_BUG_ON(!pcm || !device))
return -ENXIO;
mutex_lock(&register_mutex); mutex_lock(&register_mutex);
err = snd_pcm_add(pcm); err = snd_pcm_add(pcm);
if (err) { if (err) {
...@@ -1043,10 +1046,11 @@ int snd_pcm_notify(struct snd_pcm_notify *notify, int nfree) ...@@ -1043,10 +1046,11 @@ int snd_pcm_notify(struct snd_pcm_notify *notify, int nfree)
{ {
struct snd_pcm *pcm; struct snd_pcm *pcm;
snd_assert(notify != NULL && if (snd_BUG_ON(!notify ||
notify->n_register != NULL && !notify->n_register ||
notify->n_unregister != NULL && !notify->n_unregister ||
notify->n_disconnect, return -EINVAL); !notify->n_disconnect))
return -EINVAL;
mutex_lock(&register_mutex); mutex_lock(&register_mutex);
if (nfree) { if (nfree) {
list_del(&notify->list); list_del(&notify->list);
......
...@@ -397,7 +397,8 @@ static int snd_pcm_ioctl_sync_ptr_compat(struct snd_pcm_substream *substream, ...@@ -397,7 +397,8 @@ static int snd_pcm_ioctl_sync_ptr_compat(struct snd_pcm_substream *substream,
snd_pcm_uframes_t boundary; snd_pcm_uframes_t boundary;
int err; int err;
snd_assert(runtime, return -EINVAL); if (snd_BUG_ON(!runtime))
return -EINVAL;
if (get_user(sflags, &src->flags) || if (get_user(sflags, &src->flags) ||
get_user(scontrol.appl_ptr, &src->c.control.appl_ptr) || get_user(scontrol.appl_ptr, &src->c.control.appl_ptr) ||
......
...@@ -85,7 +85,8 @@ void snd_pcm_playback_silence(struct snd_pcm_substream *substream, snd_pcm_ufram ...@@ -85,7 +85,8 @@ void snd_pcm_playback_silence(struct snd_pcm_substream *substream, snd_pcm_ufram
} }
frames = runtime->buffer_size - runtime->silence_filled; frames = runtime->buffer_size - runtime->silence_filled;
} }
snd_assert(frames <= runtime->buffer_size, return); if (snd_BUG_ON(frames > runtime->buffer_size))
return;
if (frames == 0) if (frames == 0)
return; return;
ofs = runtime->silence_start % runtime->buffer_size; ofs = runtime->silence_start % runtime->buffer_size;
...@@ -96,7 +97,7 @@ void snd_pcm_playback_silence(struct snd_pcm_substream *substream, snd_pcm_ufram ...@@ -96,7 +97,7 @@ void snd_pcm_playback_silence(struct snd_pcm_substream *substream, snd_pcm_ufram
if (substream->ops->silence) { if (substream->ops->silence) {
int err; int err;
err = substream->ops->silence(substream, -1, ofs, transfer); err = substream->ops->silence(substream, -1, ofs, transfer);
snd_assert(err >= 0, ); snd_BUG_ON(err < 0);
} else { } else {
char *hwbuf = runtime->dma_area + frames_to_bytes(runtime, ofs); char *hwbuf = runtime->dma_area + frames_to_bytes(runtime, ofs);
snd_pcm_format_set_silence(runtime->format, hwbuf, transfer * runtime->channels); snd_pcm_format_set_silence(runtime->format, hwbuf, transfer * runtime->channels);
...@@ -108,7 +109,7 @@ void snd_pcm_playback_silence(struct snd_pcm_substream *substream, snd_pcm_ufram ...@@ -108,7 +109,7 @@ void snd_pcm_playback_silence(struct snd_pcm_substream *substream, snd_pcm_ufram
for (c = 0; c < channels; ++c) { for (c = 0; c < channels; ++c) {
int err; int err;
err = substream->ops->silence(substream, c, ofs, transfer); err = substream->ops->silence(substream, c, ofs, transfer);
snd_assert(err >= 0, ); snd_BUG_ON(err < 0);
} }
} else { } else {
size_t dma_csize = runtime->dma_bytes / channels; size_t dma_csize = runtime->dma_bytes / channels;
...@@ -354,7 +355,7 @@ static inline unsigned int muldiv32(unsigned int a, unsigned int b, ...@@ -354,7 +355,7 @@ static inline unsigned int muldiv32(unsigned int a, unsigned int b,
{ {
u_int64_t n = (u_int64_t) a * b; u_int64_t n = (u_int64_t) a * b;
if (c == 0) { if (c == 0) {
snd_assert(n > 0, ); snd_BUG_ON(!n);
*r = 0; *r = 0;
return UINT_MAX; return UINT_MAX;
} }
...@@ -380,7 +381,8 @@ static inline unsigned int muldiv32(unsigned int a, unsigned int b, ...@@ -380,7 +381,8 @@ static inline unsigned int muldiv32(unsigned int a, unsigned int b,
int snd_interval_refine(struct snd_interval *i, const struct snd_interval *v) int snd_interval_refine(struct snd_interval *i, const struct snd_interval *v)
{ {
int changed = 0; int changed = 0;
snd_assert(!snd_interval_empty(i), return -EINVAL); if (snd_BUG_ON(snd_interval_empty(i)))
return -EINVAL;
if (i->min < v->min) { if (i->min < v->min) {
i->min = v->min; i->min = v->min;
i->openmin = v->openmin; i->openmin = v->openmin;
...@@ -423,7 +425,8 @@ EXPORT_SYMBOL(snd_interval_refine); ...@@ -423,7 +425,8 @@ EXPORT_SYMBOL(snd_interval_refine);
static int snd_interval_refine_first(struct snd_interval *i) static int snd_interval_refine_first(struct snd_interval *i)
{ {
snd_assert(!snd_interval_empty(i), return -EINVAL); if (snd_BUG_ON(snd_interval_empty(i)))
return -EINVAL;
if (snd_interval_single(i)) if (snd_interval_single(i))
return 0; return 0;
i->max = i->min; i->max = i->min;
...@@ -435,7 +438,8 @@ static int snd_interval_refine_first(struct snd_interval *i) ...@@ -435,7 +438,8 @@ static int snd_interval_refine_first(struct snd_interval *i)
static int snd_interval_refine_last(struct snd_interval *i) static int snd_interval_refine_last(struct snd_interval *i)
{ {
snd_assert(!snd_interval_empty(i), return -EINVAL); if (snd_BUG_ON(snd_interval_empty(i)))
return -EINVAL;
if (snd_interval_single(i)) if (snd_interval_single(i))
return 0; return 0;
i->min = i->max; i->min = i->max;
...@@ -889,7 +893,8 @@ int snd_pcm_hw_rule_add(struct snd_pcm_runtime *runtime, unsigned int cond, ...@@ -889,7 +893,8 @@ int snd_pcm_hw_rule_add(struct snd_pcm_runtime *runtime, unsigned int cond,
c->private = private; c->private = private;
k = 0; k = 0;
while (1) { while (1) {
snd_assert(k < ARRAY_SIZE(c->deps), return -EINVAL); if (snd_BUG_ON(k >= ARRAY_SIZE(c->deps)))
return -EINVAL;
c->deps[k++] = dep; c->deps[k++] = dep;
if (dep < 0) if (dep < 0)
break; break;
...@@ -1285,7 +1290,8 @@ int snd_pcm_hw_param_first(struct snd_pcm_substream *pcm, ...@@ -1285,7 +1290,8 @@ int snd_pcm_hw_param_first(struct snd_pcm_substream *pcm,
return changed; return changed;
if (params->rmask) { if (params->rmask) {
int err = snd_pcm_hw_refine(pcm, params); int err = snd_pcm_hw_refine(pcm, params);
snd_assert(err >= 0, return err); if (snd_BUG_ON(err < 0))
return err;
} }
return snd_pcm_hw_param_value(params, var, dir); return snd_pcm_hw_param_value(params, var, dir);
} }
...@@ -1330,7 +1336,8 @@ int snd_pcm_hw_param_last(struct snd_pcm_substream *pcm, ...@@ -1330,7 +1336,8 @@ int snd_pcm_hw_param_last(struct snd_pcm_substream *pcm,
return changed; return changed;
if (params->rmask) { if (params->rmask) {
int err = snd_pcm_hw_refine(pcm, params); int err = snd_pcm_hw_refine(pcm, params);
snd_assert(err >= 0, return err); if (snd_BUG_ON(err < 0))
return err;
} }
return snd_pcm_hw_param_value(params, var, dir); return snd_pcm_hw_param_value(params, var, dir);
} }
...@@ -1368,7 +1375,8 @@ int snd_pcm_hw_params_choose(struct snd_pcm_substream *pcm, ...@@ -1368,7 +1375,8 @@ int snd_pcm_hw_params_choose(struct snd_pcm_substream *pcm,
err = snd_pcm_hw_param_first(pcm, params, *v, NULL); err = snd_pcm_hw_param_first(pcm, params, *v, NULL);
else else
err = snd_pcm_hw_param_last(pcm, params, *v, NULL); err = snd_pcm_hw_param_last(pcm, params, *v, NULL);
snd_assert(err >= 0, return err); if (snd_BUG_ON(err < 0))
return err;
} }
return 0; return 0;
} }
...@@ -1466,9 +1474,9 @@ void snd_pcm_period_elapsed(struct snd_pcm_substream *substream) ...@@ -1466,9 +1474,9 @@ void snd_pcm_period_elapsed(struct snd_pcm_substream *substream)
struct snd_pcm_runtime *runtime; struct snd_pcm_runtime *runtime;
unsigned long flags; unsigned long flags;
snd_assert(substream != NULL, return); if (PCM_RUNTIME_CHECK(substream))
return;
runtime = substream->runtime; runtime = substream->runtime;
snd_assert(runtime != NULL, return);
if (runtime->transfer_ack_begin) if (runtime->transfer_ack_begin)
runtime->transfer_ack_begin(substream); runtime->transfer_ack_begin(substream);
...@@ -1567,7 +1575,6 @@ static int snd_pcm_lib_write_transfer(struct snd_pcm_substream *substream, ...@@ -1567,7 +1575,6 @@ static int snd_pcm_lib_write_transfer(struct snd_pcm_substream *substream,
return err; return err;
} else { } else {
char *hwbuf = runtime->dma_area + frames_to_bytes(runtime, hwoff); char *hwbuf = runtime->dma_area + frames_to_bytes(runtime, hwoff);
snd_assert(runtime->dma_area, return -EFAULT);
if (copy_from_user(hwbuf, buf, frames_to_bytes(runtime, frames))) if (copy_from_user(hwbuf, buf, frames_to_bytes(runtime, frames)))
return -EFAULT; return -EFAULT;
} }
...@@ -1629,7 +1636,10 @@ static snd_pcm_sframes_t snd_pcm_lib_write1(struct snd_pcm_substream *substream, ...@@ -1629,7 +1636,10 @@ static snd_pcm_sframes_t snd_pcm_lib_write1(struct snd_pcm_substream *substream,
cont = runtime->buffer_size - runtime->control->appl_ptr % runtime->buffer_size; cont = runtime->buffer_size - runtime->control->appl_ptr % runtime->buffer_size;
if (frames > cont) if (frames > cont)
frames = cont; frames = cont;
snd_assert(frames != 0, snd_pcm_stream_unlock_irq(substream); return -EINVAL); if (snd_BUG_ON(!frames)) {
snd_pcm_stream_unlock_irq(substream);
return -EINVAL;
}
appl_ptr = runtime->control->appl_ptr; appl_ptr = runtime->control->appl_ptr;
appl_ofs = appl_ptr % runtime->buffer_size; appl_ofs = appl_ptr % runtime->buffer_size;
snd_pcm_stream_unlock_irq(substream); snd_pcm_stream_unlock_irq(substream);
...@@ -1669,18 +1679,30 @@ static snd_pcm_sframes_t snd_pcm_lib_write1(struct snd_pcm_substream *substream, ...@@ -1669,18 +1679,30 @@ static snd_pcm_sframes_t snd_pcm_lib_write1(struct snd_pcm_substream *substream,
return xfer > 0 ? (snd_pcm_sframes_t)xfer : err; return xfer > 0 ? (snd_pcm_sframes_t)xfer : err;
} }
snd_pcm_sframes_t snd_pcm_lib_write(struct snd_pcm_substream *substream, const void __user *buf, snd_pcm_uframes_t size) /* sanity-check for read/write methods */
static int pcm_sanity_check(struct snd_pcm_substream *substream)
{ {
struct snd_pcm_runtime *runtime; struct snd_pcm_runtime *runtime;
int nonblock; if (PCM_RUNTIME_CHECK(substream))
return -ENXIO;
snd_assert(substream != NULL, return -ENXIO);
runtime = substream->runtime; runtime = substream->runtime;
snd_assert(runtime != NULL, return -ENXIO); if (snd_BUG_ON(!substream->ops->copy && !runtime->dma_area))
snd_assert(substream->ops->copy != NULL || runtime->dma_area != NULL, return -EINVAL); return -EINVAL;
if (runtime->status->state == SNDRV_PCM_STATE_OPEN) if (runtime->status->state == SNDRV_PCM_STATE_OPEN)
return -EBADFD; return -EBADFD;
return 0;
}
snd_pcm_sframes_t snd_pcm_lib_write(struct snd_pcm_substream *substream, const void __user *buf, snd_pcm_uframes_t size)
{
struct snd_pcm_runtime *runtime;
int nonblock;
int err;
err = pcm_sanity_check(substream);
if (err < 0)
return err;
runtime = substream->runtime;
nonblock = !!(substream->f_flags & O_NONBLOCK); nonblock = !!(substream->f_flags & O_NONBLOCK);
if (runtime->access != SNDRV_PCM_ACCESS_RW_INTERLEAVED && if (runtime->access != SNDRV_PCM_ACCESS_RW_INTERLEAVED &&
...@@ -1703,7 +1725,8 @@ static int snd_pcm_lib_writev_transfer(struct snd_pcm_substream *substream, ...@@ -1703,7 +1725,8 @@ static int snd_pcm_lib_writev_transfer(struct snd_pcm_substream *substream,
int channels = runtime->channels; int channels = runtime->channels;
int c; int c;
if (substream->ops->copy) { if (substream->ops->copy) {
snd_assert(substream->ops->silence != NULL, return -EINVAL); if (snd_BUG_ON(!substream->ops->silence))
return -EINVAL;
for (c = 0; c < channels; ++c, ++bufs) { for (c = 0; c < channels; ++c, ++bufs) {
if (*bufs == NULL) { if (*bufs == NULL) {
if ((err = substream->ops->silence(substream, c, hwoff, frames)) < 0) if ((err = substream->ops->silence(substream, c, hwoff, frames)) < 0)
...@@ -1717,7 +1740,6 @@ static int snd_pcm_lib_writev_transfer(struct snd_pcm_substream *substream, ...@@ -1717,7 +1740,6 @@ static int snd_pcm_lib_writev_transfer(struct snd_pcm_substream *substream,
} else { } else {
/* default transfer behaviour */ /* default transfer behaviour */
size_t dma_csize = runtime->dma_bytes / channels; size_t dma_csize = runtime->dma_bytes / channels;
snd_assert(runtime->dma_area, return -EFAULT);
for (c = 0; c < channels; ++c, ++bufs) { for (c = 0; c < channels; ++c, ++bufs) {
char *hwbuf = runtime->dma_area + (c * dma_csize) + samples_to_bytes(runtime, hwoff); char *hwbuf = runtime->dma_area + (c * dma_csize) + samples_to_bytes(runtime, hwoff);
if (*bufs == NULL) { if (*bufs == NULL) {
...@@ -1738,14 +1760,12 @@ snd_pcm_sframes_t snd_pcm_lib_writev(struct snd_pcm_substream *substream, ...@@ -1738,14 +1760,12 @@ snd_pcm_sframes_t snd_pcm_lib_writev(struct snd_pcm_substream *substream,
{ {
struct snd_pcm_runtime *runtime; struct snd_pcm_runtime *runtime;
int nonblock; int nonblock;
int err;
snd_assert(substream != NULL, return -ENXIO); err = pcm_sanity_check(substream);
if (err < 0)
return err;
runtime = substream->runtime; runtime = substream->runtime;
snd_assert(runtime != NULL, return -ENXIO);
snd_assert(substream->ops->copy != NULL || runtime->dma_area != NULL, return -EINVAL);
if (runtime->status->state == SNDRV_PCM_STATE_OPEN)
return -EBADFD;
nonblock = !!(substream->f_flags & O_NONBLOCK); nonblock = !!(substream->f_flags & O_NONBLOCK);
if (runtime->access != SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) if (runtime->access != SNDRV_PCM_ACCESS_RW_NONINTERLEAVED)
...@@ -1769,7 +1789,6 @@ static int snd_pcm_lib_read_transfer(struct snd_pcm_substream *substream, ...@@ -1769,7 +1789,6 @@ static int snd_pcm_lib_read_transfer(struct snd_pcm_substream *substream,
return err; return err;
} else { } else {
char *hwbuf = runtime->dma_area + frames_to_bytes(runtime, hwoff); char *hwbuf = runtime->dma_area + frames_to_bytes(runtime, hwoff);
snd_assert(runtime->dma_area, return -EFAULT);
if (copy_to_user(buf, hwbuf, frames_to_bytes(runtime, frames))) if (copy_to_user(buf, hwbuf, frames_to_bytes(runtime, frames)))
return -EFAULT; return -EFAULT;
} }
...@@ -1841,7 +1860,10 @@ static snd_pcm_sframes_t snd_pcm_lib_read1(struct snd_pcm_substream *substream, ...@@ -1841,7 +1860,10 @@ static snd_pcm_sframes_t snd_pcm_lib_read1(struct snd_pcm_substream *substream,
cont = runtime->buffer_size - runtime->control->appl_ptr % runtime->buffer_size; cont = runtime->buffer_size - runtime->control->appl_ptr % runtime->buffer_size;
if (frames > cont) if (frames > cont)
frames = cont; frames = cont;
snd_assert(frames != 0, snd_pcm_stream_unlock_irq(substream); return -EINVAL); if (snd_BUG_ON(!frames)) {
snd_pcm_stream_unlock_irq(substream);
return -EINVAL;
}
appl_ptr = runtime->control->appl_ptr; appl_ptr = runtime->control->appl_ptr;
appl_ofs = appl_ptr % runtime->buffer_size; appl_ofs = appl_ptr % runtime->buffer_size;
snd_pcm_stream_unlock_irq(substream); snd_pcm_stream_unlock_irq(substream);
...@@ -1879,14 +1901,12 @@ snd_pcm_sframes_t snd_pcm_lib_read(struct snd_pcm_substream *substream, void __u ...@@ -1879,14 +1901,12 @@ snd_pcm_sframes_t snd_pcm_lib_read(struct snd_pcm_substream *substream, void __u
{ {
struct snd_pcm_runtime *runtime; struct snd_pcm_runtime *runtime;
int nonblock; int nonblock;
int err;
snd_assert(substream != NULL, return -ENXIO); err = pcm_sanity_check(substream);
if (err < 0)
return err;
runtime = substream->runtime; runtime = substream->runtime;
snd_assert(runtime != NULL, return -ENXIO);
snd_assert(substream->ops->copy != NULL || runtime->dma_area != NULL, return -EINVAL);
if (runtime->status->state == SNDRV_PCM_STATE_OPEN)
return -EBADFD;
nonblock = !!(substream->f_flags & O_NONBLOCK); nonblock = !!(substream->f_flags & O_NONBLOCK);
if (runtime->access != SNDRV_PCM_ACCESS_RW_INTERLEAVED) if (runtime->access != SNDRV_PCM_ACCESS_RW_INTERLEAVED)
return -EINVAL; return -EINVAL;
...@@ -1916,7 +1936,6 @@ static int snd_pcm_lib_readv_transfer(struct snd_pcm_substream *substream, ...@@ -1916,7 +1936,6 @@ static int snd_pcm_lib_readv_transfer(struct snd_pcm_substream *substream,
} }
} else { } else {
snd_pcm_uframes_t dma_csize = runtime->dma_bytes / channels; snd_pcm_uframes_t dma_csize = runtime->dma_bytes / channels;
snd_assert(runtime->dma_area, return -EFAULT);
for (c = 0; c < channels; ++c, ++bufs) { for (c = 0; c < channels; ++c, ++bufs) {
char *hwbuf; char *hwbuf;
char __user *buf; char __user *buf;
...@@ -1938,11 +1957,12 @@ snd_pcm_sframes_t snd_pcm_lib_readv(struct snd_pcm_substream *substream, ...@@ -1938,11 +1957,12 @@ snd_pcm_sframes_t snd_pcm_lib_readv(struct snd_pcm_substream *substream,
{ {
struct snd_pcm_runtime *runtime; struct snd_pcm_runtime *runtime;
int nonblock; int nonblock;
int err;
snd_assert(substream != NULL, return -ENXIO); err = pcm_sanity_check(substream);
if (err < 0)
return err;
runtime = substream->runtime; runtime = substream->runtime;
snd_assert(runtime != NULL, return -ENXIO);
snd_assert(substream->ops->copy != NULL || runtime->dma_area != NULL, return -EINVAL);
if (runtime->status->state == SNDRV_PCM_STATE_OPEN) if (runtime->status->state == SNDRV_PCM_STATE_OPEN)
return -EBADFD; return -EBADFD;
......
...@@ -50,8 +50,6 @@ static int preallocate_pcm_pages(struct snd_pcm_substream *substream, size_t siz ...@@ -50,8 +50,6 @@ static int preallocate_pcm_pages(struct snd_pcm_substream *substream, size_t siz
struct snd_dma_buffer *dmab = &substream->dma_buffer; struct snd_dma_buffer *dmab = &substream->dma_buffer;
int err; int err;
snd_assert(size > 0, return -EINVAL);
/* already reserved? */ /* already reserved? */
if (snd_dma_get_reserved_buf(dmab, substream->dma_buf_id) > 0) { if (snd_dma_get_reserved_buf(dmab, substream->dma_buf_id) > 0) {
if (dmab->bytes >= size) if (dmab->bytes >= size)
...@@ -342,10 +340,12 @@ int snd_pcm_lib_malloc_pages(struct snd_pcm_substream *substream, size_t size) ...@@ -342,10 +340,12 @@ int snd_pcm_lib_malloc_pages(struct snd_pcm_substream *substream, size_t size)
struct snd_pcm_runtime *runtime; struct snd_pcm_runtime *runtime;
struct snd_dma_buffer *dmab = NULL; struct snd_dma_buffer *dmab = NULL;
snd_assert(substream->dma_buffer.dev.type != SNDRV_DMA_TYPE_UNKNOWN, return -EINVAL); if (PCM_RUNTIME_CHECK(substream))
snd_assert(substream != NULL, return -EINVAL); return -EINVAL;
if (snd_BUG_ON(substream->dma_buffer.dev.type ==
SNDRV_DMA_TYPE_UNKNOWN))
return -EINVAL;
runtime = substream->runtime; runtime = substream->runtime;
snd_assert(runtime != NULL, return -EINVAL);
if (runtime->dma_buffer_p) { if (runtime->dma_buffer_p) {
/* perphaps, we might free the large DMA memory region /* perphaps, we might free the large DMA memory region
...@@ -391,9 +391,9 @@ int snd_pcm_lib_free_pages(struct snd_pcm_substream *substream) ...@@ -391,9 +391,9 @@ int snd_pcm_lib_free_pages(struct snd_pcm_substream *substream)
{ {
struct snd_pcm_runtime *runtime; struct snd_pcm_runtime *runtime;
snd_assert(substream != NULL, return -EINVAL); if (PCM_RUNTIME_CHECK(substream))
return -EINVAL;
runtime = substream->runtime; runtime = substream->runtime;
snd_assert(runtime != NULL, return -EINVAL);
if (runtime->dma_area == NULL) if (runtime->dma_area == NULL)
return 0; return 0;
if (runtime->dma_buffer_p != &substream->dma_buffer) { if (runtime->dma_buffer_p != &substream->dma_buffer) {
......
...@@ -95,7 +95,6 @@ int snd_pcm_info(struct snd_pcm_substream *substream, struct snd_pcm_info *info) ...@@ -95,7 +95,6 @@ int snd_pcm_info(struct snd_pcm_substream *substream, struct snd_pcm_info *info)
struct snd_pcm *pcm = substream->pcm; struct snd_pcm *pcm = substream->pcm;
struct snd_pcm_str *pstr = substream->pstr; struct snd_pcm_str *pstr = substream->pstr;
snd_assert(substream != NULL, return -ENXIO);
memset(info, 0, sizeof(*info)); memset(info, 0, sizeof(*info));
info->card = pcm->card->number; info->card = pcm->card->number;
info->device = pcm->device; info->device = pcm->device;
...@@ -370,9 +369,9 @@ static int snd_pcm_hw_params(struct snd_pcm_substream *substream, ...@@ -370,9 +369,9 @@ static int snd_pcm_hw_params(struct snd_pcm_substream *substream,
unsigned int bits; unsigned int bits;
snd_pcm_uframes_t frames; snd_pcm_uframes_t frames;
snd_assert(substream != NULL, return -ENXIO); if (PCM_RUNTIME_CHECK(substream))
return -ENXIO;
runtime = substream->runtime; runtime = substream->runtime;
snd_assert(runtime != NULL, return -ENXIO);
snd_pcm_stream_lock_irq(substream); snd_pcm_stream_lock_irq(substream);
switch (runtime->status->state) { switch (runtime->status->state) {
case SNDRV_PCM_STATE_OPEN: case SNDRV_PCM_STATE_OPEN:
...@@ -490,9 +489,9 @@ static int snd_pcm_hw_free(struct snd_pcm_substream *substream) ...@@ -490,9 +489,9 @@ static int snd_pcm_hw_free(struct snd_pcm_substream *substream)
struct snd_pcm_runtime *runtime; struct snd_pcm_runtime *runtime;
int result = 0; int result = 0;
snd_assert(substream != NULL, return -ENXIO); if (PCM_RUNTIME_CHECK(substream))
return -ENXIO;
runtime = substream->runtime; runtime = substream->runtime;
snd_assert(runtime != NULL, return -ENXIO);
snd_pcm_stream_lock_irq(substream); snd_pcm_stream_lock_irq(substream);
switch (runtime->status->state) { switch (runtime->status->state) {
case SNDRV_PCM_STATE_SETUP: case SNDRV_PCM_STATE_SETUP:
...@@ -518,9 +517,9 @@ static int snd_pcm_sw_params(struct snd_pcm_substream *substream, ...@@ -518,9 +517,9 @@ static int snd_pcm_sw_params(struct snd_pcm_substream *substream,
{ {
struct snd_pcm_runtime *runtime; struct snd_pcm_runtime *runtime;
snd_assert(substream != NULL, return -ENXIO); if (PCM_RUNTIME_CHECK(substream))
return -ENXIO;
runtime = substream->runtime; runtime = substream->runtime;
snd_assert(runtime != NULL, return -ENXIO);
snd_pcm_stream_lock_irq(substream); snd_pcm_stream_lock_irq(substream);
if (runtime->status->state == SNDRV_PCM_STATE_OPEN) { if (runtime->status->state == SNDRV_PCM_STATE_OPEN) {
snd_pcm_stream_unlock_irq(substream); snd_pcm_stream_unlock_irq(substream);
...@@ -622,11 +621,8 @@ static int snd_pcm_status_user(struct snd_pcm_substream *substream, ...@@ -622,11 +621,8 @@ static int snd_pcm_status_user(struct snd_pcm_substream *substream,
struct snd_pcm_status __user * _status) struct snd_pcm_status __user * _status)
{ {
struct snd_pcm_status status; struct snd_pcm_status status;
struct snd_pcm_runtime *runtime;
int res; int res;
snd_assert(substream != NULL, return -ENXIO);
runtime = substream->runtime;
memset(&status, 0, sizeof(status)); memset(&status, 0, sizeof(status));
res = snd_pcm_status(substream, &status); res = snd_pcm_status(substream, &status);
if (res < 0) if (res < 0)
...@@ -642,7 +638,6 @@ static int snd_pcm_channel_info(struct snd_pcm_substream *substream, ...@@ -642,7 +638,6 @@ static int snd_pcm_channel_info(struct snd_pcm_substream *substream,
struct snd_pcm_runtime *runtime; struct snd_pcm_runtime *runtime;
unsigned int channel; unsigned int channel;
snd_assert(substream != NULL, return -ENXIO);
channel = info->channel; channel = info->channel;
runtime = substream->runtime; runtime = substream->runtime;
snd_pcm_stream_lock_irq(substream); snd_pcm_stream_lock_irq(substream);
...@@ -1250,7 +1245,6 @@ static int snd_pcm_do_reset(struct snd_pcm_substream *substream, int state) ...@@ -1250,7 +1245,6 @@ static int snd_pcm_do_reset(struct snd_pcm_substream *substream, int state)
int err = substream->ops->ioctl(substream, SNDRV_PCM_IOCTL1_RESET, NULL); int err = substream->ops->ioctl(substream, SNDRV_PCM_IOCTL1_RESET, NULL);
if (err < 0) if (err < 0)
return err; return err;
// snd_assert(runtime->status->hw_ptr < runtime->buffer_size, );
runtime->hw_ptr_base = 0; runtime->hw_ptr_base = 0;
runtime->hw_ptr_interrupt = runtime->status->hw_ptr - runtime->hw_ptr_interrupt = runtime->status->hw_ptr -
runtime->status->hw_ptr % runtime->period_size; runtime->status->hw_ptr % runtime->period_size;
...@@ -1421,7 +1415,6 @@ static int snd_pcm_drain(struct snd_pcm_substream *substream) ...@@ -1421,7 +1415,6 @@ static int snd_pcm_drain(struct snd_pcm_substream *substream)
int i, num_drecs; int i, num_drecs;
struct drain_rec *drec, drec_tmp, *d; struct drain_rec *drec, drec_tmp, *d;
snd_assert(substream != NULL, return -ENXIO);
card = substream->pcm->card; card = substream->pcm->card;
runtime = substream->runtime; runtime = substream->runtime;
...@@ -1541,7 +1534,8 @@ static int snd_pcm_drop(struct snd_pcm_substream *substream) ...@@ -1541,7 +1534,8 @@ static int snd_pcm_drop(struct snd_pcm_substream *substream)
struct snd_card *card; struct snd_card *card;
int result = 0; int result = 0;
snd_assert(substream != NULL, return -ENXIO); if (PCM_RUNTIME_CHECK(substream))
return -ENXIO;
runtime = substream->runtime; runtime = substream->runtime;
card = substream->pcm->card; card = substream->pcm->card;
...@@ -1934,33 +1928,41 @@ int snd_pcm_hw_constraints_complete(struct snd_pcm_substream *substream) ...@@ -1934,33 +1928,41 @@ int snd_pcm_hw_constraints_complete(struct snd_pcm_substream *substream)
mask |= 1 << SNDRV_PCM_ACCESS_MMAP_COMPLEX; mask |= 1 << SNDRV_PCM_ACCESS_MMAP_COMPLEX;
} }
err = snd_pcm_hw_constraint_mask(runtime, SNDRV_PCM_HW_PARAM_ACCESS, mask); err = snd_pcm_hw_constraint_mask(runtime, SNDRV_PCM_HW_PARAM_ACCESS, mask);
snd_assert(err >= 0, return -EINVAL); if (err < 0)
return err;
err = snd_pcm_hw_constraint_mask64(runtime, SNDRV_PCM_HW_PARAM_FORMAT, hw->formats); err = snd_pcm_hw_constraint_mask64(runtime, SNDRV_PCM_HW_PARAM_FORMAT, hw->formats);
snd_assert(err >= 0, return -EINVAL); if (err < 0)
return err;
err = snd_pcm_hw_constraint_mask(runtime, SNDRV_PCM_HW_PARAM_SUBFORMAT, 1 << SNDRV_PCM_SUBFORMAT_STD); err = snd_pcm_hw_constraint_mask(runtime, SNDRV_PCM_HW_PARAM_SUBFORMAT, 1 << SNDRV_PCM_SUBFORMAT_STD);
snd_assert(err >= 0, return -EINVAL); if (err < 0)
return err;
err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_CHANNELS, err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_CHANNELS,
hw->channels_min, hw->channels_max); hw->channels_min, hw->channels_max);
snd_assert(err >= 0, return -EINVAL); if (err < 0)
return err;
err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_RATE, err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_RATE,
hw->rate_min, hw->rate_max); hw->rate_min, hw->rate_max);
snd_assert(err >= 0, return -EINVAL); if (err < 0)
return err;
err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
hw->period_bytes_min, hw->period_bytes_max); hw->period_bytes_min, hw->period_bytes_max);
snd_assert(err >= 0, return -EINVAL); if (err < 0)
return err;
err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIODS, err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIODS,
hw->periods_min, hw->periods_max); hw->periods_min, hw->periods_max);
snd_assert(err >= 0, return -EINVAL); if (err < 0)
return err;
err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
hw->period_bytes_min, hw->buffer_bytes_max); hw->period_bytes_min, hw->buffer_bytes_max);
snd_assert(err >= 0, return -EINVAL); if (err < 0)
return err;
err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
snd_pcm_hw_rule_buffer_bytes_max, substream, snd_pcm_hw_rule_buffer_bytes_max, substream,
...@@ -1971,7 +1973,8 @@ int snd_pcm_hw_constraints_complete(struct snd_pcm_substream *substream) ...@@ -1971,7 +1973,8 @@ int snd_pcm_hw_constraints_complete(struct snd_pcm_substream *substream)
/* FIXME: remove */ /* FIXME: remove */
if (runtime->dma_bytes) { if (runtime->dma_bytes) {
err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 0, runtime->dma_bytes); err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 0, runtime->dma_bytes);
snd_assert(err >= 0, return -EINVAL); if (err < 0)
return -EINVAL;
} }
if (!(hw->rates & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))) { if (!(hw->rates & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))) {
...@@ -2067,7 +2070,7 @@ static int snd_pcm_open_file(struct file *file, ...@@ -2067,7 +2070,7 @@ static int snd_pcm_open_file(struct file *file,
struct snd_pcm_str *str; struct snd_pcm_str *str;
int err; int err;
snd_assert(rpcm_file != NULL, return -EINVAL); if (rpcm_file)
*rpcm_file = NULL; *rpcm_file = NULL;
err = snd_pcm_open_substream(pcm, stream, file, &substream); err = snd_pcm_open_substream(pcm, stream, file, &substream);
...@@ -2086,6 +2089,7 @@ static int snd_pcm_open_file(struct file *file, ...@@ -2086,6 +2089,7 @@ static int snd_pcm_open_file(struct file *file,
substream->pcm_release = pcm_release_private; substream->pcm_release = pcm_release_private;
} }
file->private_data = pcm_file; file->private_data = pcm_file;
if (rpcm_file)
*rpcm_file = pcm_file; *rpcm_file = pcm_file;
return 0; return 0;
} }
...@@ -2170,7 +2174,8 @@ static int snd_pcm_release(struct inode *inode, struct file *file) ...@@ -2170,7 +2174,8 @@ static int snd_pcm_release(struct inode *inode, struct file *file)
pcm_file = file->private_data; pcm_file = file->private_data;
substream = pcm_file->substream; substream = pcm_file->substream;
snd_assert(substream != NULL, return -ENXIO); if (snd_BUG_ON(!substream))
return -ENXIO;
pcm = substream->pcm; pcm = substream->pcm;
fasync_helper(-1, file, 0, &substream->runtime->fasync); fasync_helper(-1, file, 0, &substream->runtime->fasync);
mutex_lock(&pcm->open_mutex); mutex_lock(&pcm->open_mutex);
...@@ -2493,8 +2498,6 @@ static int snd_pcm_common_ioctl1(struct file *file, ...@@ -2493,8 +2498,6 @@ static int snd_pcm_common_ioctl1(struct file *file,
struct snd_pcm_substream *substream, struct snd_pcm_substream *substream,
unsigned int cmd, void __user *arg) unsigned int cmd, void __user *arg)
{ {
snd_assert(substream != NULL, return -ENXIO);
switch (cmd) { switch (cmd) {
case SNDRV_PCM_IOCTL_PVERSION: case SNDRV_PCM_IOCTL_PVERSION:
return put_user(SNDRV_PCM_VERSION, (int __user *)arg) ? -EFAULT : 0; return put_user(SNDRV_PCM_VERSION, (int __user *)arg) ? -EFAULT : 0;
...@@ -2563,8 +2566,10 @@ static int snd_pcm_playback_ioctl1(struct file *file, ...@@ -2563,8 +2566,10 @@ static int snd_pcm_playback_ioctl1(struct file *file,
struct snd_pcm_substream *substream, struct snd_pcm_substream *substream,
unsigned int cmd, void __user *arg) unsigned int cmd, void __user *arg)
{ {
snd_assert(substream != NULL, return -ENXIO); if (snd_BUG_ON(!substream))
snd_assert(substream->stream == SNDRV_PCM_STREAM_PLAYBACK, return -EINVAL); return -ENXIO;
if (snd_BUG_ON(substream->stream != SNDRV_PCM_STREAM_PLAYBACK))
return -EINVAL;
switch (cmd) { switch (cmd) {
case SNDRV_PCM_IOCTL_WRITEI_FRAMES: case SNDRV_PCM_IOCTL_WRITEI_FRAMES:
{ {
...@@ -2643,8 +2648,10 @@ static int snd_pcm_capture_ioctl1(struct file *file, ...@@ -2643,8 +2648,10 @@ static int snd_pcm_capture_ioctl1(struct file *file,
struct snd_pcm_substream *substream, struct snd_pcm_substream *substream,
unsigned int cmd, void __user *arg) unsigned int cmd, void __user *arg)
{ {
snd_assert(substream != NULL, return -ENXIO); if (snd_BUG_ON(!substream))
snd_assert(substream->stream == SNDRV_PCM_STREAM_CAPTURE, return -EINVAL); return -ENXIO;
if (snd_BUG_ON(substream->stream != SNDRV_PCM_STREAM_CAPTURE))
return -EINVAL;
switch (cmd) { switch (cmd) {
case SNDRV_PCM_IOCTL_READI_FRAMES: case SNDRV_PCM_IOCTL_READI_FRAMES:
{ {
...@@ -2783,7 +2790,8 @@ static ssize_t snd_pcm_read(struct file *file, char __user *buf, size_t count, ...@@ -2783,7 +2790,8 @@ static ssize_t snd_pcm_read(struct file *file, char __user *buf, size_t count,
pcm_file = file->private_data; pcm_file = file->private_data;
substream = pcm_file->substream; substream = pcm_file->substream;
snd_assert(substream != NULL, return -ENXIO); if (PCM_RUNTIME_CHECK(substream))
return -ENXIO;
runtime = substream->runtime; runtime = substream->runtime;
if (runtime->status->state == SNDRV_PCM_STATE_OPEN) if (runtime->status->state == SNDRV_PCM_STATE_OPEN)
return -EBADFD; return -EBADFD;
...@@ -2806,21 +2814,17 @@ static ssize_t snd_pcm_write(struct file *file, const char __user *buf, ...@@ -2806,21 +2814,17 @@ static ssize_t snd_pcm_write(struct file *file, const char __user *buf,
pcm_file = file->private_data; pcm_file = file->private_data;
substream = pcm_file->substream; substream = pcm_file->substream;
snd_assert(substream != NULL, result = -ENXIO; goto end); if (PCM_RUNTIME_CHECK(substream))
return -ENXIO;
runtime = substream->runtime; runtime = substream->runtime;
if (runtime->status->state == SNDRV_PCM_STATE_OPEN) { if (runtime->status->state == SNDRV_PCM_STATE_OPEN)
result = -EBADFD; return -EBADFD;
goto end; if (!frame_aligned(runtime, count))
} return -EINVAL;
if (!frame_aligned(runtime, count)) {
result = -EINVAL;
goto end;
}
count = bytes_to_frames(runtime, count); count = bytes_to_frames(runtime, count);
result = snd_pcm_lib_write(substream, buf, count); result = snd_pcm_lib_write(substream, buf, count);
if (result > 0) if (result > 0)
result = frames_to_bytes(runtime, result); result = frames_to_bytes(runtime, result);
end:
return result; return result;
} }
...@@ -2838,7 +2842,8 @@ static ssize_t snd_pcm_aio_read(struct kiocb *iocb, const struct iovec *iov, ...@@ -2838,7 +2842,8 @@ static ssize_t snd_pcm_aio_read(struct kiocb *iocb, const struct iovec *iov,
pcm_file = iocb->ki_filp->private_data; pcm_file = iocb->ki_filp->private_data;
substream = pcm_file->substream; substream = pcm_file->substream;
snd_assert(substream != NULL, return -ENXIO); if (PCM_RUNTIME_CHECK(substream))
return -ENXIO;
runtime = substream->runtime; runtime = substream->runtime;
if (runtime->status->state == SNDRV_PCM_STATE_OPEN) if (runtime->status->state == SNDRV_PCM_STATE_OPEN)
return -EBADFD; return -EBADFD;
...@@ -2872,17 +2877,14 @@ static ssize_t snd_pcm_aio_write(struct kiocb *iocb, const struct iovec *iov, ...@@ -2872,17 +2877,14 @@ static ssize_t snd_pcm_aio_write(struct kiocb *iocb, const struct iovec *iov,
pcm_file = iocb->ki_filp->private_data; pcm_file = iocb->ki_filp->private_data;
substream = pcm_file->substream; substream = pcm_file->substream;
snd_assert(substream != NULL, result = -ENXIO; goto end); if (PCM_RUNTIME_CHECK(substream))
return -ENXIO;
runtime = substream->runtime; runtime = substream->runtime;
if (runtime->status->state == SNDRV_PCM_STATE_OPEN) { if (runtime->status->state == SNDRV_PCM_STATE_OPEN)
result = -EBADFD; return -EBADFD;
goto end;
}
if (nr_segs > 128 || nr_segs != runtime->channels || if (nr_segs > 128 || nr_segs != runtime->channels ||
!frame_aligned(runtime, iov->iov_len)) { !frame_aligned(runtime, iov->iov_len))
result = -EINVAL; return -EINVAL;
goto end;
}
frames = bytes_to_samples(runtime, iov->iov_len); frames = bytes_to_samples(runtime, iov->iov_len);
bufs = kmalloc(sizeof(void *) * nr_segs, GFP_KERNEL); bufs = kmalloc(sizeof(void *) * nr_segs, GFP_KERNEL);
if (bufs == NULL) if (bufs == NULL)
...@@ -2893,7 +2895,6 @@ static ssize_t snd_pcm_aio_write(struct kiocb *iocb, const struct iovec *iov, ...@@ -2893,7 +2895,6 @@ static ssize_t snd_pcm_aio_write(struct kiocb *iocb, const struct iovec *iov,
if (result > 0) if (result > 0)
result = frames_to_bytes(runtime, result); result = frames_to_bytes(runtime, result);
kfree(bufs); kfree(bufs);
end:
return result; return result;
} }
...@@ -2908,7 +2909,8 @@ static unsigned int snd_pcm_playback_poll(struct file *file, poll_table * wait) ...@@ -2908,7 +2909,8 @@ static unsigned int snd_pcm_playback_poll(struct file *file, poll_table * wait)
pcm_file = file->private_data; pcm_file = file->private_data;
substream = pcm_file->substream; substream = pcm_file->substream;
snd_assert(substream != NULL, return -ENXIO); if (PCM_RUNTIME_CHECK(substream))
return -ENXIO;
runtime = substream->runtime; runtime = substream->runtime;
poll_wait(file, &runtime->sleep, wait); poll_wait(file, &runtime->sleep, wait);
...@@ -2946,7 +2948,8 @@ static unsigned int snd_pcm_capture_poll(struct file *file, poll_table * wait) ...@@ -2946,7 +2948,8 @@ static unsigned int snd_pcm_capture_poll(struct file *file, poll_table * wait)
pcm_file = file->private_data; pcm_file = file->private_data;
substream = pcm_file->substream; substream = pcm_file->substream;
snd_assert(substream != NULL, return -ENXIO); if (PCM_RUNTIME_CHECK(substream))
return -ENXIO;
runtime = substream->runtime; runtime = substream->runtime;
poll_wait(file, &runtime->sleep, wait); poll_wait(file, &runtime->sleep, wait);
...@@ -3016,7 +3019,6 @@ static int snd_pcm_mmap_status(struct snd_pcm_substream *substream, struct file ...@@ -3016,7 +3019,6 @@ static int snd_pcm_mmap_status(struct snd_pcm_substream *substream, struct file
if (!(area->vm_flags & VM_READ)) if (!(area->vm_flags & VM_READ))
return -EINVAL; return -EINVAL;
runtime = substream->runtime; runtime = substream->runtime;
snd_assert(runtime != NULL, return -EAGAIN);
size = area->vm_end - area->vm_start; size = area->vm_end - area->vm_start;
if (size != PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status))) if (size != PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status)))
return -EINVAL; return -EINVAL;
...@@ -3056,7 +3058,6 @@ static int snd_pcm_mmap_control(struct snd_pcm_substream *substream, struct file ...@@ -3056,7 +3058,6 @@ static int snd_pcm_mmap_control(struct snd_pcm_substream *substream, struct file
if (!(area->vm_flags & VM_READ)) if (!(area->vm_flags & VM_READ))
return -EINVAL; return -EINVAL;
runtime = substream->runtime; runtime = substream->runtime;
snd_assert(runtime != NULL, return -EAGAIN);
size = area->vm_end - area->vm_start; size = area->vm_end - area->vm_start;
if (size != PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control))) if (size != PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control)))
return -EINVAL; return -EINVAL;
...@@ -3188,7 +3189,6 @@ int snd_pcm_mmap_data(struct snd_pcm_substream *substream, struct file *file, ...@@ -3188,7 +3189,6 @@ int snd_pcm_mmap_data(struct snd_pcm_substream *substream, struct file *file,
return -EINVAL; return -EINVAL;
} }
runtime = substream->runtime; runtime = substream->runtime;
snd_assert(runtime != NULL, return -EAGAIN);
if (runtime->status->state == SNDRV_PCM_STATE_OPEN) if (runtime->status->state == SNDRV_PCM_STATE_OPEN)
return -EBADFD; return -EBADFD;
if (!(runtime->info & SNDRV_PCM_INFO_MMAP)) if (!(runtime->info & SNDRV_PCM_INFO_MMAP))
...@@ -3220,7 +3220,8 @@ static int snd_pcm_mmap(struct file *file, struct vm_area_struct *area) ...@@ -3220,7 +3220,8 @@ static int snd_pcm_mmap(struct file *file, struct vm_area_struct *area)
pcm_file = file->private_data; pcm_file = file->private_data;
substream = pcm_file->substream; substream = pcm_file->substream;
snd_assert(substream != NULL, return -ENXIO); if (PCM_RUNTIME_CHECK(substream))
return -ENXIO;
offset = area->vm_pgoff << PAGE_SHIFT; offset = area->vm_pgoff << PAGE_SHIFT;
switch (offset) { switch (offset) {
...@@ -3248,9 +3249,9 @@ static int snd_pcm_fasync(int fd, struct file * file, int on) ...@@ -3248,9 +3249,9 @@ static int snd_pcm_fasync(int fd, struct file * file, int on)
lock_kernel(); lock_kernel();
pcm_file = file->private_data; pcm_file = file->private_data;
substream = pcm_file->substream; substream = pcm_file->substream;
snd_assert(substream != NULL, goto out); if (PCM_RUNTIME_CHECK(substream))
goto out;
runtime = substream->runtime; runtime = substream->runtime;
err = fasync_helper(fd, file, on, &runtime->fasync); err = fasync_helper(fd, file, on, &runtime->fasync);
out: out:
unlock_kernel(); unlock_kernel();
......
...@@ -51,12 +51,14 @@ void snd_pcm_timer_resolution_change(struct snd_pcm_substream *substream) ...@@ -51,12 +51,14 @@ void snd_pcm_timer_resolution_change(struct snd_pcm_substream *substream)
mult = 1000000000; mult = 1000000000;
rate = runtime->rate; rate = runtime->rate;
snd_assert(rate != 0, return); if (snd_BUG_ON(!rate))
return;
l = gcd(mult, rate); l = gcd(mult, rate);
mult /= l; mult /= l;
rate /= l; rate /= l;
fsize = runtime->period_size; fsize = runtime->period_size;
snd_assert(fsize != 0, return); if (snd_BUG_ON(!fsize))
return;
l = gcd(rate, fsize); l = gcd(rate, fsize);
rate /= l; rate /= l;
fsize /= l; fsize /= l;
......
...@@ -470,8 +470,8 @@ int snd_rawmidi_kernel_release(struct snd_rawmidi_file * rfile) ...@@ -470,8 +470,8 @@ int snd_rawmidi_kernel_release(struct snd_rawmidi_file * rfile)
struct snd_rawmidi_substream *substream; struct snd_rawmidi_substream *substream;
struct snd_rawmidi_runtime *runtime; struct snd_rawmidi_runtime *runtime;
snd_assert(rfile != NULL, return -ENXIO); if (snd_BUG_ON(!rfile))
snd_assert(rfile->input != NULL || rfile->output != NULL, return -ENXIO); return -ENXIO;
rmidi = rfile->rmidi; rmidi = rfile->rmidi;
mutex_lock(&rmidi->open_mutex); mutex_lock(&rmidi->open_mutex);
if (rfile->input != NULL) { if (rfile->input != NULL) {
...@@ -1100,7 +1100,7 @@ int snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream, int count) ...@@ -1100,7 +1100,7 @@ int snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream, int count)
return -EINVAL; return -EINVAL;
} }
spin_lock_irqsave(&runtime->lock, flags); spin_lock_irqsave(&runtime->lock, flags);
snd_assert(runtime->avail + count <= runtime->buffer_size, ); snd_BUG_ON(runtime->avail + count > runtime->buffer_size);
runtime->hw_ptr += count; runtime->hw_ptr += count;
runtime->hw_ptr %= runtime->buffer_size; runtime->hw_ptr %= runtime->buffer_size;
runtime->avail += count; runtime->avail += count;
...@@ -1141,8 +1141,10 @@ static long snd_rawmidi_kernel_write1(struct snd_rawmidi_substream *substream, ...@@ -1141,8 +1141,10 @@ static long snd_rawmidi_kernel_write1(struct snd_rawmidi_substream *substream,
long count1, result; long count1, result;
struct snd_rawmidi_runtime *runtime = substream->runtime; struct snd_rawmidi_runtime *runtime = substream->runtime;
snd_assert(kernelbuf != NULL || userbuf != NULL, return -EINVAL); if (snd_BUG_ON(!kernelbuf && !userbuf))
snd_assert(runtime->buffer != NULL, return -EINVAL); return -EINVAL;
if (snd_BUG_ON(!runtime->buffer))
return -EINVAL;
result = 0; result = 0;
spin_lock_irqsave(&runtime->lock, flags); spin_lock_irqsave(&runtime->lock, flags);
...@@ -1420,9 +1422,10 @@ int snd_rawmidi_new(struct snd_card *card, char *id, int device, ...@@ -1420,9 +1422,10 @@ int snd_rawmidi_new(struct snd_card *card, char *id, int device,
.dev_disconnect = snd_rawmidi_dev_disconnect, .dev_disconnect = snd_rawmidi_dev_disconnect,
}; };
snd_assert(rrawmidi != NULL, return -EINVAL); if (snd_BUG_ON(!card))
return -ENXIO;
if (rrawmidi)
*rrawmidi = NULL; *rrawmidi = NULL;
snd_assert(card != NULL, return -ENXIO);
rmidi = kzalloc(sizeof(*rmidi), GFP_KERNEL); rmidi = kzalloc(sizeof(*rmidi), GFP_KERNEL);
if (rmidi == NULL) { if (rmidi == NULL) {
snd_printk(KERN_ERR "rawmidi: cannot allocate\n"); snd_printk(KERN_ERR "rawmidi: cannot allocate\n");
...@@ -1455,6 +1458,7 @@ int snd_rawmidi_new(struct snd_card *card, char *id, int device, ...@@ -1455,6 +1458,7 @@ int snd_rawmidi_new(struct snd_card *card, char *id, int device,
snd_rawmidi_free(rmidi); snd_rawmidi_free(rmidi);
return err; return err;
} }
if (rrawmidi)
*rrawmidi = rmidi; *rrawmidi = rmidi;
return 0; return 0;
} }
...@@ -1472,7 +1476,8 @@ static void snd_rawmidi_free_substreams(struct snd_rawmidi_str *stream) ...@@ -1472,7 +1476,8 @@ static void snd_rawmidi_free_substreams(struct snd_rawmidi_str *stream)
static int snd_rawmidi_free(struct snd_rawmidi *rmidi) static int snd_rawmidi_free(struct snd_rawmidi *rmidi)
{ {
snd_assert(rmidi != NULL, return -ENXIO); if (!rmidi)
return 0;
snd_info_free_entry(rmidi->proc_entry); snd_info_free_entry(rmidi->proc_entry);
rmidi->proc_entry = NULL; rmidi->proc_entry = NULL;
......
...@@ -91,7 +91,8 @@ static int ...@@ -91,7 +91,8 @@ static int
rtctimer_start(struct snd_timer *timer) rtctimer_start(struct snd_timer *timer)
{ {
rtc_task_t *rtc = timer->private_data; rtc_task_t *rtc = timer->private_data;
snd_assert(rtc != NULL, return -EINVAL); if (snd_BUG_ON(!rtc))
return -EINVAL;
rtc_control(rtc, RTC_IRQP_SET, rtctimer_freq); rtc_control(rtc, RTC_IRQP_SET, rtctimer_freq);
rtc_control(rtc, RTC_PIE_ON, 0); rtc_control(rtc, RTC_PIE_ON, 0);
return 0; return 0;
...@@ -101,7 +102,8 @@ static int ...@@ -101,7 +102,8 @@ static int
rtctimer_stop(struct snd_timer *timer) rtctimer_stop(struct snd_timer *timer)
{ {
rtc_task_t *rtc = timer->private_data; rtc_task_t *rtc = timer->private_data;
snd_assert(rtc != NULL, return -EINVAL); if (snd_BUG_ON(!rtc))
return -EINVAL;
rtc_control(rtc, RTC_PIE_OFF, 0); rtc_control(rtc, RTC_PIE_OFF, 0);
return 0; return 0;
} }
......
...@@ -164,7 +164,8 @@ odev_read(struct file *file, char __user *buf, size_t count, loff_t *offset) ...@@ -164,7 +164,8 @@ odev_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
{ {
struct seq_oss_devinfo *dp; struct seq_oss_devinfo *dp;
dp = file->private_data; dp = file->private_data;
snd_assert(dp != NULL, return -EIO); if (snd_BUG_ON(!dp))
return -ENXIO;
return snd_seq_oss_read(dp, buf, count); return snd_seq_oss_read(dp, buf, count);
} }
...@@ -174,7 +175,8 @@ odev_write(struct file *file, const char __user *buf, size_t count, loff_t *offs ...@@ -174,7 +175,8 @@ odev_write(struct file *file, const char __user *buf, size_t count, loff_t *offs
{ {
struct seq_oss_devinfo *dp; struct seq_oss_devinfo *dp;
dp = file->private_data; dp = file->private_data;
snd_assert(dp != NULL, return -EIO); if (snd_BUG_ON(!dp))
return -ENXIO;
return snd_seq_oss_write(dp, buf, count, file); return snd_seq_oss_write(dp, buf, count, file);
} }
...@@ -183,7 +185,8 @@ odev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) ...@@ -183,7 +185,8 @@ odev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{ {
struct seq_oss_devinfo *dp; struct seq_oss_devinfo *dp;
dp = file->private_data; dp = file->private_data;
snd_assert(dp != NULL, return -EIO); if (snd_BUG_ON(!dp))
return -ENXIO;
return snd_seq_oss_ioctl(dp, cmd, arg); return snd_seq_oss_ioctl(dp, cmd, arg);
} }
...@@ -198,7 +201,8 @@ odev_poll(struct file *file, poll_table * wait) ...@@ -198,7 +201,8 @@ odev_poll(struct file *file, poll_table * wait)
{ {
struct seq_oss_devinfo *dp; struct seq_oss_devinfo *dp;
dp = file->private_data; dp = file->private_data;
snd_assert(dp != NULL, return 0); if (snd_BUG_ON(!dp))
return -ENXIO;
return snd_seq_oss_poll(dp, file, wait); return snd_seq_oss_poll(dp, file, wait);
} }
......
...@@ -308,7 +308,8 @@ snd_seq_oss_synth_cleanup(struct seq_oss_devinfo *dp) ...@@ -308,7 +308,8 @@ snd_seq_oss_synth_cleanup(struct seq_oss_devinfo *dp)
struct seq_oss_synth *rec; struct seq_oss_synth *rec;
struct seq_oss_synthinfo *info; struct seq_oss_synthinfo *info;
snd_assert(dp->max_synthdev <= SNDRV_SEQ_OSS_MAX_SYNTH_DEVS, return); if (snd_BUG_ON(dp->max_synthdev >= SNDRV_SEQ_OSS_MAX_SYNTH_DEVS))
return;
for (i = 0; i < dp->max_synthdev; i++) { for (i = 0; i < dp->max_synthdev; i++) {
info = &dp->synths[i]; info = &dp->synths[i];
if (! info->opened) if (! info->opened)
...@@ -402,7 +403,8 @@ snd_seq_oss_synth_reset(struct seq_oss_devinfo *dp, int dev) ...@@ -402,7 +403,8 @@ snd_seq_oss_synth_reset(struct seq_oss_devinfo *dp, int dev)
struct seq_oss_synth *rec; struct seq_oss_synth *rec;
struct seq_oss_synthinfo *info; struct seq_oss_synthinfo *info;
snd_assert(dev >= 0 && dev < dp->max_synthdev, return); if (snd_BUG_ON(dev < 0 || dev >= dp->max_synthdev))
return;
info = &dp->synths[dev]; info = &dp->synths[dev];
if (! info->opened) if (! info->opened)
return; return;
......
...@@ -266,7 +266,8 @@ static int seq_free_client1(struct snd_seq_client *client) ...@@ -266,7 +266,8 @@ static int seq_free_client1(struct snd_seq_client *client)
{ {
unsigned long flags; unsigned long flags;
snd_assert(client != NULL, return -EINVAL); if (!client)
return 0;
snd_seq_delete_all_ports(client); snd_seq_delete_all_ports(client);
snd_seq_queue_client_leave(client->number); snd_seq_queue_client_leave(client->number);
spin_lock_irqsave(&clients_lock, flags); spin_lock_irqsave(&clients_lock, flags);
...@@ -403,7 +404,8 @@ static ssize_t snd_seq_read(struct file *file, char __user *buf, size_t count, ...@@ -403,7 +404,8 @@ static ssize_t snd_seq_read(struct file *file, char __user *buf, size_t count,
return -EFAULT; return -EFAULT;
/* check client structures are in place */ /* check client structures are in place */
snd_assert(client != NULL, return -ENXIO); if (snd_BUG_ON(!client))
return -ENXIO;
if (!client->accept_input || (fifo = client->data.user.fifo) == NULL) if (!client->accept_input || (fifo = client->data.user.fifo) == NULL)
return -ENXIO; return -ENXIO;
...@@ -825,7 +827,8 @@ int snd_seq_dispatch_event(struct snd_seq_event_cell *cell, int atomic, int hop) ...@@ -825,7 +827,8 @@ int snd_seq_dispatch_event(struct snd_seq_event_cell *cell, int atomic, int hop)
struct snd_seq_client *client; struct snd_seq_client *client;
int result; int result;
snd_assert(cell != NULL, return -EINVAL); if (snd_BUG_ON(!cell))
return -EINVAL;
client = snd_seq_client_use_ptr(cell->event.source.client); client = snd_seq_client_use_ptr(cell->event.source.client);
if (client == NULL) { if (client == NULL) {
...@@ -994,7 +997,8 @@ static ssize_t snd_seq_write(struct file *file, const char __user *buf, ...@@ -994,7 +997,8 @@ static ssize_t snd_seq_write(struct file *file, const char __user *buf,
return -ENXIO; return -ENXIO;
/* check client structures are in place */ /* check client structures are in place */
snd_assert(client != NULL, return -ENXIO); if (snd_BUG_ON(!client))
return -ENXIO;
if (!client->accept_output || client->pool == NULL) if (!client->accept_output || client->pool == NULL)
return -ENXIO; return -ENXIO;
...@@ -1076,7 +1080,8 @@ static unsigned int snd_seq_poll(struct file *file, poll_table * wait) ...@@ -1076,7 +1080,8 @@ static unsigned int snd_seq_poll(struct file *file, poll_table * wait)
unsigned int mask = 0; unsigned int mask = 0;
/* check client structures are in place */ /* check client structures are in place */
snd_assert(client != NULL, return -ENXIO); if (snd_BUG_ON(!client))
return -ENXIO;
if ((snd_seq_file_flags(file) & SNDRV_SEQ_LFLG_INPUT) && if ((snd_seq_file_flags(file) & SNDRV_SEQ_LFLG_INPUT) &&
client->data.user.fifo) { client->data.user.fifo) {
...@@ -2195,7 +2200,8 @@ static long snd_seq_ioctl(struct file *file, unsigned int cmd, unsigned long arg ...@@ -2195,7 +2200,8 @@ static long snd_seq_ioctl(struct file *file, unsigned int cmd, unsigned long arg
{ {
struct snd_seq_client *client = file->private_data; struct snd_seq_client *client = file->private_data;
snd_assert(client != NULL, return -ENXIO); if (snd_BUG_ON(!client))
return -ENXIO;
return snd_seq_do_ioctl(client, cmd, (void __user *) arg); return snd_seq_do_ioctl(client, cmd, (void __user *) arg);
} }
...@@ -2216,7 +2222,8 @@ int snd_seq_create_kernel_client(struct snd_card *card, int client_index, ...@@ -2216,7 +2222,8 @@ int snd_seq_create_kernel_client(struct snd_card *card, int client_index,
struct snd_seq_client *client; struct snd_seq_client *client;
va_list args; va_list args;
snd_assert(! in_interrupt(), return -EBUSY); if (snd_BUG_ON(in_interrupt()))
return -EBUSY;
if (card && client_index >= SNDRV_SEQ_CLIENTS_PER_CARD) if (card && client_index >= SNDRV_SEQ_CLIENTS_PER_CARD)
return -EINVAL; return -EINVAL;
...@@ -2265,7 +2272,8 @@ int snd_seq_delete_kernel_client(int client) ...@@ -2265,7 +2272,8 @@ int snd_seq_delete_kernel_client(int client)
{ {
struct snd_seq_client *ptr; struct snd_seq_client *ptr;
snd_assert(! in_interrupt(), return -EBUSY); if (snd_BUG_ON(in_interrupt()))
return -EBUSY;
ptr = clientptr(client); ptr = clientptr(client);
if (ptr == NULL) if (ptr == NULL)
...@@ -2288,7 +2296,8 @@ static int kernel_client_enqueue(int client, struct snd_seq_event *ev, ...@@ -2288,7 +2296,8 @@ static int kernel_client_enqueue(int client, struct snd_seq_event *ev,
struct snd_seq_client *cptr; struct snd_seq_client *cptr;
int result; int result;
snd_assert(ev != NULL, return -EINVAL); if (snd_BUG_ON(!ev))
return -EINVAL;
if (ev->type == SNDRV_SEQ_EVENT_NONE) if (ev->type == SNDRV_SEQ_EVENT_NONE)
return 0; /* ignore this */ return 0; /* ignore this */
...@@ -2354,7 +2363,8 @@ int snd_seq_kernel_client_dispatch(int client, struct snd_seq_event * ev, ...@@ -2354,7 +2363,8 @@ int snd_seq_kernel_client_dispatch(int client, struct snd_seq_event * ev,
struct snd_seq_client *cptr; struct snd_seq_client *cptr;
int result; int result;
snd_assert(ev != NULL, return -EINVAL); if (snd_BUG_ON(!ev))
return -EINVAL;
/* fill in client number */ /* fill in client number */
ev->queue = SNDRV_SEQ_QUEUE_DIRECT; ev->queue = SNDRV_SEQ_QUEUE_DIRECT;
......
...@@ -92,7 +92,8 @@ static long snd_seq_ioctl_compat(struct file *file, unsigned int cmd, unsigned l ...@@ -92,7 +92,8 @@ static long snd_seq_ioctl_compat(struct file *file, unsigned int cmd, unsigned l
struct snd_seq_client *client = file->private_data; struct snd_seq_client *client = file->private_data;
void __user *argp = compat_ptr(arg); void __user *argp = compat_ptr(arg);
snd_assert(client != NULL, return -ENXIO); if (snd_BUG_ON(!client))
return -ENXIO;
switch (cmd) { switch (cmd) {
case SNDRV_SEQ_IOCTL_PVERSION: case SNDRV_SEQ_IOCTL_PVERSION:
......
...@@ -187,7 +187,8 @@ int snd_seq_device_new(struct snd_card *card, int device, char *id, int argsize, ...@@ -187,7 +187,8 @@ int snd_seq_device_new(struct snd_card *card, int device, char *id, int argsize,
if (result) if (result)
*result = NULL; *result = NULL;
snd_assert(id != NULL, return -EINVAL); if (snd_BUG_ON(!id))
return -EINVAL;
ops = find_driver(id, 1); ops = find_driver(id, 1);
if (ops == NULL) if (ops == NULL)
...@@ -232,7 +233,8 @@ static int snd_seq_device_free(struct snd_seq_device *dev) ...@@ -232,7 +233,8 @@ static int snd_seq_device_free(struct snd_seq_device *dev)
{ {
struct ops_list *ops; struct ops_list *ops;
snd_assert(dev != NULL, return -EINVAL); if (snd_BUG_ON(!dev))
return -EINVAL;
ops = find_driver(dev->id, 0); ops = find_driver(dev->id, 0);
if (ops == NULL) if (ops == NULL)
......
...@@ -65,9 +65,11 @@ void snd_seq_fifo_delete(struct snd_seq_fifo **fifo) ...@@ -65,9 +65,11 @@ void snd_seq_fifo_delete(struct snd_seq_fifo **fifo)
{ {
struct snd_seq_fifo *f; struct snd_seq_fifo *f;
snd_assert(fifo != NULL, return); if (snd_BUG_ON(!fifo))
return;
f = *fifo; f = *fifo;
snd_assert(f != NULL, return); if (snd_BUG_ON(!f))
return;
*fifo = NULL; *fifo = NULL;
snd_seq_fifo_clear(f); snd_seq_fifo_clear(f);
...@@ -116,7 +118,8 @@ int snd_seq_fifo_event_in(struct snd_seq_fifo *f, ...@@ -116,7 +118,8 @@ int snd_seq_fifo_event_in(struct snd_seq_fifo *f,
unsigned long flags; unsigned long flags;
int err; int err;
snd_assert(f != NULL, return -EINVAL); if (snd_BUG_ON(!f))
return -EINVAL;
snd_use_lock_use(&f->use_lock); snd_use_lock_use(&f->use_lock);
err = snd_seq_event_dup(f->pool, event, &cell, 1, NULL); /* always non-blocking */ err = snd_seq_event_dup(f->pool, event, &cell, 1, NULL); /* always non-blocking */
...@@ -174,7 +177,8 @@ int snd_seq_fifo_cell_out(struct snd_seq_fifo *f, ...@@ -174,7 +177,8 @@ int snd_seq_fifo_cell_out(struct snd_seq_fifo *f,
unsigned long flags; unsigned long flags;
wait_queue_t wait; wait_queue_t wait;
snd_assert(f != NULL, return -EINVAL); if (snd_BUG_ON(!f))
return -EINVAL;
*cellp = NULL; *cellp = NULL;
init_waitqueue_entry(&wait, current); init_waitqueue_entry(&wait, current);
...@@ -233,7 +237,8 @@ int snd_seq_fifo_resize(struct snd_seq_fifo *f, int poolsize) ...@@ -233,7 +237,8 @@ int snd_seq_fifo_resize(struct snd_seq_fifo *f, int poolsize)
struct snd_seq_pool *newpool, *oldpool; struct snd_seq_pool *newpool, *oldpool;
struct snd_seq_event_cell *cell, *next, *oldhead; struct snd_seq_event_cell *cell, *next, *oldhead;
snd_assert(f != NULL && f->pool != NULL, return -EINVAL); if (snd_BUG_ON(!f || !f->pool))
return -EINVAL;
/* allocate new pool */ /* allocate new pool */
newpool = snd_seq_pool_new(poolsize); newpool = snd_seq_pool_new(poolsize);
......
...@@ -187,9 +187,11 @@ void snd_seq_cell_free(struct snd_seq_event_cell * cell) ...@@ -187,9 +187,11 @@ void snd_seq_cell_free(struct snd_seq_event_cell * cell)
unsigned long flags; unsigned long flags;
struct snd_seq_pool *pool; struct snd_seq_pool *pool;
snd_assert(cell != NULL, return); if (snd_BUG_ON(!cell))
return;
pool = cell->pool; pool = cell->pool;
snd_assert(pool != NULL, return); if (snd_BUG_ON(!pool))
return;
spin_lock_irqsave(&pool->lock, flags); spin_lock_irqsave(&pool->lock, flags);
free_cell(pool, cell); free_cell(pool, cell);
...@@ -378,7 +380,8 @@ int snd_seq_pool_init(struct snd_seq_pool *pool) ...@@ -378,7 +380,8 @@ int snd_seq_pool_init(struct snd_seq_pool *pool)
struct snd_seq_event_cell *cellptr; struct snd_seq_event_cell *cellptr;
unsigned long flags; unsigned long flags;
snd_assert(pool != NULL, return -EINVAL); if (snd_BUG_ON(!pool))
return -EINVAL;
if (pool->ptr) /* should be atomic? */ if (pool->ptr) /* should be atomic? */
return 0; return 0;
...@@ -414,7 +417,8 @@ int snd_seq_pool_done(struct snd_seq_pool *pool) ...@@ -414,7 +417,8 @@ int snd_seq_pool_done(struct snd_seq_pool *pool)
struct snd_seq_event_cell *ptr; struct snd_seq_event_cell *ptr;
int max_count = 5 * HZ; int max_count = 5 * HZ;
snd_assert(pool != NULL, return -EINVAL); if (snd_BUG_ON(!pool))
return -EINVAL;
/* wait for closing all threads */ /* wait for closing all threads */
spin_lock_irqsave(&pool->lock, flags); spin_lock_irqsave(&pool->lock, flags);
......
...@@ -116,7 +116,8 @@ static int dump_midi(struct snd_rawmidi_substream *substream, const char *buf, i ...@@ -116,7 +116,8 @@ static int dump_midi(struct snd_rawmidi_substream *substream, const char *buf, i
struct snd_rawmidi_runtime *runtime; struct snd_rawmidi_runtime *runtime;
int tmp; int tmp;
snd_assert(substream != NULL || buf != NULL, return -EINVAL); if (snd_BUG_ON(!substream || !buf))
return -EINVAL;
runtime = substream->runtime; runtime = substream->runtime;
if ((tmp = runtime->avail) < count) { if ((tmp = runtime->avail) < count) {
snd_printd("warning, output event was lost (count = %i, available = %i)\n", count, tmp); snd_printd("warning, output event was lost (count = %i, available = %i)\n", count, tmp);
...@@ -135,7 +136,8 @@ static int event_process_midi(struct snd_seq_event *ev, int direct, ...@@ -135,7 +136,8 @@ static int event_process_midi(struct snd_seq_event *ev, int direct,
struct snd_rawmidi_substream *substream; struct snd_rawmidi_substream *substream;
int len; int len;
snd_assert(msynth != NULL, return -EINVAL); if (snd_BUG_ON(!msynth))
return -EINVAL;
substream = msynth->output_rfile.output; substream = msynth->output_rfile.output;
if (substream == NULL) if (substream == NULL)
return -ENODEV; return -ENODEV;
...@@ -210,7 +212,8 @@ static int midisynth_unsubscribe(void *private_data, struct snd_seq_port_subscri ...@@ -210,7 +212,8 @@ static int midisynth_unsubscribe(void *private_data, struct snd_seq_port_subscri
int err; int err;
struct seq_midisynth *msynth = private_data; struct seq_midisynth *msynth = private_data;
snd_assert(msynth->input_rfile.input != NULL, return -EINVAL); if (snd_BUG_ON(!msynth->input_rfile.input))
return -EINVAL;
err = snd_rawmidi_kernel_release(&msynth->input_rfile); err = snd_rawmidi_kernel_release(&msynth->input_rfile);
return err; return err;
} }
...@@ -247,7 +250,8 @@ static int midisynth_unuse(void *private_data, struct snd_seq_port_subscribe *in ...@@ -247,7 +250,8 @@ static int midisynth_unuse(void *private_data, struct snd_seq_port_subscribe *in
struct seq_midisynth *msynth = private_data; struct seq_midisynth *msynth = private_data;
unsigned char buf = 0xff; /* MIDI reset */ unsigned char buf = 0xff; /* MIDI reset */
snd_assert(msynth->output_rfile.output != NULL, return -EINVAL); if (snd_BUG_ON(!msynth->output_rfile.output))
return -EINVAL;
/* sending single MIDI reset message to shut the device up */ /* sending single MIDI reset message to shut the device up */
snd_rawmidi_kernel_write(msynth->output_rfile.output, &buf, 1); snd_rawmidi_kernel_write(msynth->output_rfile.output, &buf, 1);
snd_rawmidi_drain_output(msynth->output_rfile.output); snd_rawmidi_drain_output(msynth->output_rfile.output);
...@@ -285,7 +289,8 @@ snd_seq_midisynth_register_port(struct snd_seq_device *dev) ...@@ -285,7 +289,8 @@ snd_seq_midisynth_register_port(struct snd_seq_device *dev)
int device = dev->device; int device = dev->device;
unsigned int input_count = 0, output_count = 0; unsigned int input_count = 0, output_count = 0;
snd_assert(card != NULL && device >= 0 && device < SNDRV_RAWMIDI_DEVICES, return -EINVAL); if (snd_BUG_ON(!card || device < 0 || device >= SNDRV_RAWMIDI_DEVICES))
return -EINVAL;
info = kmalloc(sizeof(*info), GFP_KERNEL); info = kmalloc(sizeof(*info), GFP_KERNEL);
if (! info) if (! info)
return -ENOMEM; return -ENOMEM;
......
...@@ -130,7 +130,8 @@ struct snd_seq_client_port *snd_seq_create_port(struct snd_seq_client *client, ...@@ -130,7 +130,8 @@ struct snd_seq_client_port *snd_seq_create_port(struct snd_seq_client *client,
int num = -1; int num = -1;
/* sanity check */ /* sanity check */
snd_assert(client, return NULL); if (snd_BUG_ON(!client))
return NULL;
if (client->num_ports >= SNDRV_SEQ_MAX_PORTS - 1) { if (client->num_ports >= SNDRV_SEQ_MAX_PORTS - 1) {
snd_printk(KERN_WARNING "too many ports for client %d\n", client->number); snd_printk(KERN_WARNING "too many ports for client %d\n", client->number);
...@@ -268,8 +269,8 @@ static int port_delete(struct snd_seq_client *client, ...@@ -268,8 +269,8 @@ static int port_delete(struct snd_seq_client *client,
if (port->private_free) if (port->private_free)
port->private_free(port->private_data); port->private_free(port->private_data);
snd_assert(port->c_src.count == 0,); snd_BUG_ON(port->c_src.count != 0);
snd_assert(port->c_dest.count == 0,); snd_BUG_ON(port->c_dest.count != 0);
kfree(port); kfree(port);
return 0; return 0;
...@@ -336,7 +337,8 @@ int snd_seq_delete_all_ports(struct snd_seq_client *client) ...@@ -336,7 +337,8 @@ int snd_seq_delete_all_ports(struct snd_seq_client *client)
int snd_seq_set_port_info(struct snd_seq_client_port * port, int snd_seq_set_port_info(struct snd_seq_client_port * port,
struct snd_seq_port_info * info) struct snd_seq_port_info * info)
{ {
snd_assert(port && info, return -EINVAL); if (snd_BUG_ON(!port || !info))
return -EINVAL;
/* set port name */ /* set port name */
if (info->name[0]) if (info->name[0])
...@@ -365,7 +367,8 @@ int snd_seq_set_port_info(struct snd_seq_client_port * port, ...@@ -365,7 +367,8 @@ int snd_seq_set_port_info(struct snd_seq_client_port * port,
int snd_seq_get_port_info(struct snd_seq_client_port * port, int snd_seq_get_port_info(struct snd_seq_client_port * port,
struct snd_seq_port_info * info) struct snd_seq_port_info * info)
{ {
snd_assert(port && info, return -EINVAL); if (snd_BUG_ON(!port || !info))
return -EINVAL;
/* get port name */ /* get port name */
strlcpy(info->name, port->name, sizeof(info->name)); strlcpy(info->name, port->name, sizeof(info->name));
......
...@@ -153,8 +153,8 @@ int snd_seq_prioq_cell_in(struct snd_seq_prioq * f, ...@@ -153,8 +153,8 @@ int snd_seq_prioq_cell_in(struct snd_seq_prioq * f,
int count; int count;
int prior; int prior;
snd_assert(f, return -EINVAL); if (snd_BUG_ON(!f || !cell))
snd_assert(cell, return -EINVAL); return -EINVAL;
/* check flags */ /* check flags */
prior = (cell->event.flags & SNDRV_SEQ_PRIORITY_MASK); prior = (cell->event.flags & SNDRV_SEQ_PRIORITY_MASK);
......
...@@ -315,7 +315,8 @@ int snd_seq_enqueue_event(struct snd_seq_event_cell *cell, int atomic, int hop) ...@@ -315,7 +315,8 @@ int snd_seq_enqueue_event(struct snd_seq_event_cell *cell, int atomic, int hop)
int dest, err; int dest, err;
struct snd_seq_queue *q; struct snd_seq_queue *q;
snd_assert(cell != NULL, return -EINVAL); if (snd_BUG_ON(!cell))
return -EINVAL;
dest = cell->event.queue; /* destination queue */ dest = cell->event.queue; /* destination queue */
q = queueptr(dest); q = queueptr(dest);
if (q == NULL) if (q == NULL)
...@@ -734,7 +735,8 @@ int snd_seq_control_queue(struct snd_seq_event *ev, int atomic, int hop) ...@@ -734,7 +735,8 @@ int snd_seq_control_queue(struct snd_seq_event *ev, int atomic, int hop)
{ {
struct snd_seq_queue *q; struct snd_seq_queue *q;
snd_assert(ev != NULL, return -EINVAL); if (snd_BUG_ON(!ev))
return -EINVAL;
q = queueptr(ev->data.queue.queue); q = queueptr(ev->data.queue.queue);
if (q == NULL) if (q == NULL)
......
...@@ -173,7 +173,8 @@ int snd_seq_timer_set_tempo(struct snd_seq_timer * tmr, int tempo) ...@@ -173,7 +173,8 @@ int snd_seq_timer_set_tempo(struct snd_seq_timer * tmr, int tempo)
{ {
unsigned long flags; unsigned long flags;
snd_assert(tmr, return -EINVAL); if (snd_BUG_ON(!tmr))
return -EINVAL;
if (tempo <= 0) if (tempo <= 0)
return -EINVAL; return -EINVAL;
spin_lock_irqsave(&tmr->lock, flags); spin_lock_irqsave(&tmr->lock, flags);
...@@ -190,7 +191,8 @@ int snd_seq_timer_set_ppq(struct snd_seq_timer * tmr, int ppq) ...@@ -190,7 +191,8 @@ int snd_seq_timer_set_ppq(struct snd_seq_timer * tmr, int ppq)
{ {
unsigned long flags; unsigned long flags;
snd_assert(tmr, return -EINVAL); if (snd_BUG_ON(!tmr))
return -EINVAL;
if (ppq <= 0) if (ppq <= 0)
return -EINVAL; return -EINVAL;
spin_lock_irqsave(&tmr->lock, flags); spin_lock_irqsave(&tmr->lock, flags);
...@@ -214,7 +216,8 @@ int snd_seq_timer_set_position_tick(struct snd_seq_timer *tmr, ...@@ -214,7 +216,8 @@ int snd_seq_timer_set_position_tick(struct snd_seq_timer *tmr,
{ {
unsigned long flags; unsigned long flags;
snd_assert(tmr, return -EINVAL); if (snd_BUG_ON(!tmr))
return -EINVAL;
spin_lock_irqsave(&tmr->lock, flags); spin_lock_irqsave(&tmr->lock, flags);
tmr->tick.cur_tick = position; tmr->tick.cur_tick = position;
...@@ -229,7 +232,8 @@ int snd_seq_timer_set_position_time(struct snd_seq_timer *tmr, ...@@ -229,7 +232,8 @@ int snd_seq_timer_set_position_time(struct snd_seq_timer *tmr,
{ {
unsigned long flags; unsigned long flags;
snd_assert(tmr, return -EINVAL); if (snd_BUG_ON(!tmr))
return -EINVAL;
snd_seq_sanity_real_time(&position); snd_seq_sanity_real_time(&position);
spin_lock_irqsave(&tmr->lock, flags); spin_lock_irqsave(&tmr->lock, flags);
...@@ -244,7 +248,8 @@ int snd_seq_timer_set_skew(struct snd_seq_timer *tmr, unsigned int skew, ...@@ -244,7 +248,8 @@ int snd_seq_timer_set_skew(struct snd_seq_timer *tmr, unsigned int skew,
{ {
unsigned long flags; unsigned long flags;
snd_assert(tmr, return -EINVAL); if (snd_BUG_ON(!tmr))
return -EINVAL;
/* FIXME */ /* FIXME */
if (base != SKEW_BASE) { if (base != SKEW_BASE) {
...@@ -265,7 +270,8 @@ int snd_seq_timer_open(struct snd_seq_queue *q) ...@@ -265,7 +270,8 @@ int snd_seq_timer_open(struct snd_seq_queue *q)
int err; int err;
tmr = q->timer; tmr = q->timer;
snd_assert(tmr != NULL, return -EINVAL); if (snd_BUG_ON(!tmr))
return -EINVAL;
if (tmr->timeri) if (tmr->timeri)
return -EBUSY; return -EBUSY;
sprintf(str, "sequencer queue %i", q->queue); sprintf(str, "sequencer queue %i", q->queue);
...@@ -302,7 +308,8 @@ int snd_seq_timer_close(struct snd_seq_queue *q) ...@@ -302,7 +308,8 @@ int snd_seq_timer_close(struct snd_seq_queue *q)
struct snd_seq_timer *tmr; struct snd_seq_timer *tmr;
tmr = q->timer; tmr = q->timer;
snd_assert(tmr != NULL, return -EINVAL); if (snd_BUG_ON(!tmr))
return -EINVAL;
if (tmr->timeri) { if (tmr->timeri) {
snd_timer_stop(tmr->timeri); snd_timer_stop(tmr->timeri);
snd_timer_close(tmr->timeri); snd_timer_close(tmr->timeri);
...@@ -328,7 +335,8 @@ static int initialize_timer(struct snd_seq_timer *tmr) ...@@ -328,7 +335,8 @@ static int initialize_timer(struct snd_seq_timer *tmr)
unsigned long freq; unsigned long freq;
t = tmr->timeri->timer; t = tmr->timeri->timer;
snd_assert(t, return -EINVAL); if (snd_BUG_ON(!t))
return -EINVAL;
freq = tmr->preferred_resolution; freq = tmr->preferred_resolution;
if (!freq) if (!freq)
......
...@@ -206,20 +206,23 @@ static int snd_kernel_minor(int type, struct snd_card *card, int dev) ...@@ -206,20 +206,23 @@ static int snd_kernel_minor(int type, struct snd_card *card, int dev)
minor = type; minor = type;
break; break;
case SNDRV_DEVICE_TYPE_CONTROL: case SNDRV_DEVICE_TYPE_CONTROL:
snd_assert(card != NULL, return -EINVAL); if (snd_BUG_ON(!card))
return -EINVAL;
minor = SNDRV_MINOR(card->number, type); minor = SNDRV_MINOR(card->number, type);
break; break;
case SNDRV_DEVICE_TYPE_HWDEP: case SNDRV_DEVICE_TYPE_HWDEP:
case SNDRV_DEVICE_TYPE_RAWMIDI: case SNDRV_DEVICE_TYPE_RAWMIDI:
case SNDRV_DEVICE_TYPE_PCM_PLAYBACK: case SNDRV_DEVICE_TYPE_PCM_PLAYBACK:
case SNDRV_DEVICE_TYPE_PCM_CAPTURE: case SNDRV_DEVICE_TYPE_PCM_CAPTURE:
snd_assert(card != NULL, return -EINVAL); if (snd_BUG_ON(!card))
return -EINVAL;
minor = SNDRV_MINOR(card->number, type + dev); minor = SNDRV_MINOR(card->number, type + dev);
break; break;
default: default:
return -EINVAL; return -EINVAL;
} }
snd_assert(minor >= 0 && minor < SNDRV_OS_MINORS, return -EINVAL); if (snd_BUG_ON(minor < 0 || minor >= SNDRV_OS_MINORS))
return -EINVAL;
return minor; return minor;
} }
#endif #endif
...@@ -247,7 +250,8 @@ int snd_register_device_for_dev(int type, struct snd_card *card, int dev, ...@@ -247,7 +250,8 @@ int snd_register_device_for_dev(int type, struct snd_card *card, int dev,
int minor; int minor;
struct snd_minor *preg; struct snd_minor *preg;
snd_assert(name, return -EINVAL); if (snd_BUG_ON(!name))
return -EINVAL;
preg = kmalloc(sizeof *preg, GFP_KERNEL); preg = kmalloc(sizeof *preg, GFP_KERNEL);
if (preg == NULL) if (preg == NULL)
return -ENOMEM; return -ENOMEM;
......
...@@ -64,7 +64,8 @@ static int snd_oss_kernel_minor(int type, struct snd_card *card, int dev) ...@@ -64,7 +64,8 @@ static int snd_oss_kernel_minor(int type, struct snd_card *card, int dev)
switch (type) { switch (type) {
case SNDRV_OSS_DEVICE_TYPE_MIXER: case SNDRV_OSS_DEVICE_TYPE_MIXER:
snd_assert(card != NULL && dev <= 1, return -EINVAL); if (snd_BUG_ON(!card || dev < 0 || dev > 1))
return -EINVAL;
minor = SNDRV_MINOR_OSS(card->number, (dev ? SNDRV_MINOR_OSS_MIXER1 : SNDRV_MINOR_OSS_MIXER)); minor = SNDRV_MINOR_OSS(card->number, (dev ? SNDRV_MINOR_OSS_MIXER1 : SNDRV_MINOR_OSS_MIXER));
break; break;
case SNDRV_OSS_DEVICE_TYPE_SEQUENCER: case SNDRV_OSS_DEVICE_TYPE_SEQUENCER:
...@@ -74,11 +75,13 @@ static int snd_oss_kernel_minor(int type, struct snd_card *card, int dev) ...@@ -74,11 +75,13 @@ static int snd_oss_kernel_minor(int type, struct snd_card *card, int dev)
minor = SNDRV_MINOR_OSS_MUSIC; minor = SNDRV_MINOR_OSS_MUSIC;
break; break;
case SNDRV_OSS_DEVICE_TYPE_PCM: case SNDRV_OSS_DEVICE_TYPE_PCM:
snd_assert(card != NULL && dev <= 1, return -EINVAL); if (snd_BUG_ON(!card || dev < 0 || dev > 1))
return -EINVAL;
minor = SNDRV_MINOR_OSS(card->number, (dev ? SNDRV_MINOR_OSS_PCM1 : SNDRV_MINOR_OSS_PCM)); minor = SNDRV_MINOR_OSS(card->number, (dev ? SNDRV_MINOR_OSS_PCM1 : SNDRV_MINOR_OSS_PCM));
break; break;
case SNDRV_OSS_DEVICE_TYPE_MIDI: case SNDRV_OSS_DEVICE_TYPE_MIDI:
snd_assert(card != NULL && dev <= 1, return -EINVAL); if (snd_BUG_ON(!card || dev < 0 || dev > 1))
return -EINVAL;
minor = SNDRV_MINOR_OSS(card->number, (dev ? SNDRV_MINOR_OSS_MIDI1 : SNDRV_MINOR_OSS_MIDI)); minor = SNDRV_MINOR_OSS(card->number, (dev ? SNDRV_MINOR_OSS_MIDI1 : SNDRV_MINOR_OSS_MIDI));
break; break;
case SNDRV_OSS_DEVICE_TYPE_DMFM: case SNDRV_OSS_DEVICE_TYPE_DMFM:
...@@ -90,7 +93,8 @@ static int snd_oss_kernel_minor(int type, struct snd_card *card, int dev) ...@@ -90,7 +93,8 @@ static int snd_oss_kernel_minor(int type, struct snd_card *card, int dev)
default: default:
return -EINVAL; return -EINVAL;
} }
snd_assert(minor >= 0 && minor < SNDRV_OSS_MINORS, return -EINVAL); if (snd_BUG_ON(minor < 0 || minor >= SNDRV_OSS_MINORS))
return -EINVAL;
return minor; return minor;
} }
......
...@@ -306,7 +306,8 @@ int snd_timer_close(struct snd_timer_instance *timeri) ...@@ -306,7 +306,8 @@ int snd_timer_close(struct snd_timer_instance *timeri)
struct snd_timer *timer = NULL; struct snd_timer *timer = NULL;
struct snd_timer_instance *slave, *tmp; struct snd_timer_instance *slave, *tmp;
snd_assert(timeri != NULL, return -ENXIO); if (snd_BUG_ON(!timer))
return -ENXIO;
/* force to stop the timer */ /* force to stop the timer */
snd_timer_stop(timeri); snd_timer_stop(timeri);
...@@ -385,8 +386,9 @@ static void snd_timer_notify1(struct snd_timer_instance *ti, int event) ...@@ -385,8 +386,9 @@ static void snd_timer_notify1(struct snd_timer_instance *ti, int event)
do_posix_clock_monotonic_gettime(&tstamp); do_posix_clock_monotonic_gettime(&tstamp);
else else
getnstimeofday(&tstamp); getnstimeofday(&tstamp);
snd_assert(event >= SNDRV_TIMER_EVENT_START && if (snd_BUG_ON(event < SNDRV_TIMER_EVENT_START ||
event <= SNDRV_TIMER_EVENT_PAUSE, return); event > SNDRV_TIMER_EVENT_PAUSE))
return;
if (event == SNDRV_TIMER_EVENT_START || if (event == SNDRV_TIMER_EVENT_START ||
event == SNDRV_TIMER_EVENT_CONTINUE) event == SNDRV_TIMER_EVENT_CONTINUE)
resolution = snd_timer_resolution(ti); resolution = snd_timer_resolution(ti);
...@@ -474,7 +476,8 @@ static int _snd_timer_stop(struct snd_timer_instance * timeri, ...@@ -474,7 +476,8 @@ static int _snd_timer_stop(struct snd_timer_instance * timeri,
struct snd_timer *timer; struct snd_timer *timer;
unsigned long flags; unsigned long flags;
snd_assert(timeri != NULL, return -ENXIO); if (snd_BUG_ON(!timeri))
return -ENXIO;
if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE) { if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE) {
if (!keep_flag) { if (!keep_flag) {
...@@ -758,8 +761,9 @@ int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid, ...@@ -758,8 +761,9 @@ int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid,
.dev_disconnect = snd_timer_dev_disconnect, .dev_disconnect = snd_timer_dev_disconnect,
}; };
snd_assert(tid != NULL, return -EINVAL); if (snd_BUG_ON(!tid))
snd_assert(rtimer != NULL, return -EINVAL); return -EINVAL;
if (rtimer)
*rtimer = NULL; *rtimer = NULL;
timer = kzalloc(sizeof(*timer), GFP_KERNEL); timer = kzalloc(sizeof(*timer), GFP_KERNEL);
if (timer == NULL) { if (timer == NULL) {
...@@ -788,13 +792,15 @@ int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid, ...@@ -788,13 +792,15 @@ int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid,
return err; return err;
} }
} }
if (rtimer)
*rtimer = timer; *rtimer = timer;
return 0; return 0;
} }
static int snd_timer_free(struct snd_timer *timer) static int snd_timer_free(struct snd_timer *timer)
{ {
snd_assert(timer != NULL, return -ENXIO); if (!timer)
return 0;
mutex_lock(&register_mutex); mutex_lock(&register_mutex);
if (! list_empty(&timer->open_list_head)) { if (! list_empty(&timer->open_list_head)) {
...@@ -827,8 +833,8 @@ static int snd_timer_dev_register(struct snd_device *dev) ...@@ -827,8 +833,8 @@ static int snd_timer_dev_register(struct snd_device *dev)
struct snd_timer *timer = dev->device_data; struct snd_timer *timer = dev->device_data;
struct snd_timer *timer1; struct snd_timer *timer1;
snd_assert(timer != NULL && timer->hw.start != NULL && if (snd_BUG_ON(!timer || !timer->hw.start || !timer->hw.stop))
timer->hw.stop != NULL, return -ENXIO); return -ENXIO;
if (!(timer->hw.flags & SNDRV_TIMER_HW_SLAVE) && if (!(timer->hw.flags & SNDRV_TIMER_HW_SLAVE) &&
!timer->hw.resolution && timer->hw.c_resolution == NULL) !timer->hw.resolution && timer->hw.c_resolution == NULL)
return -EINVAL; return -EINVAL;
...@@ -879,8 +885,9 @@ void snd_timer_notify(struct snd_timer *timer, int event, struct timespec *tstam ...@@ -879,8 +885,9 @@ void snd_timer_notify(struct snd_timer *timer, int event, struct timespec *tstam
if (! (timer->hw.flags & SNDRV_TIMER_HW_SLAVE)) if (! (timer->hw.flags & SNDRV_TIMER_HW_SLAVE))
return; return;
snd_assert(event >= SNDRV_TIMER_EVENT_MSTART && if (snd_BUG_ON(event < SNDRV_TIMER_EVENT_MSTART ||
event <= SNDRV_TIMER_EVENT_MRESUME, return); 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 ||
event == SNDRV_TIMER_EVENT_MCONTINUE || event == SNDRV_TIMER_EVENT_MCONTINUE ||
......
...@@ -40,9 +40,11 @@ static int snd_timer_user_info_compat(struct file *file, ...@@ -40,9 +40,11 @@ static int snd_timer_user_info_compat(struct file *file,
struct snd_timer *t; struct snd_timer *t;
tu = file->private_data; tu = file->private_data;
snd_assert(tu->timeri != NULL, return -ENXIO); if (snd_BUG_ON(!tu->timeri))
return -ENXIO;
t = tu->timeri->timer; t = tu->timeri->timer;
snd_assert(t != NULL, return -ENXIO); if (snd_BUG_ON(!t))
return -ENXIO;
memset(&info, 0, sizeof(info)); memset(&info, 0, sizeof(info));
info.card = t->card ? t->card->number : -1; info.card = t->card ? t->card->number : -1;
if (t->hw.flags & SNDRV_TIMER_HW_SLAVE) if (t->hw.flags & SNDRV_TIMER_HW_SLAVE)
...@@ -71,7 +73,8 @@ static int snd_timer_user_status_compat(struct file *file, ...@@ -71,7 +73,8 @@ static int snd_timer_user_status_compat(struct file *file,
struct snd_timer_status status; struct snd_timer_status status;
tu = file->private_data; tu = file->private_data;
snd_assert(tu->timeri != NULL, return -ENXIO); if (snd_BUG_ON(!tu->timeri))
return -ENXIO;
memset(&status, 0, sizeof(status)); memset(&status, 0, sizeof(status));
status.tstamp = tu->tstamp; status.tstamp = tu->tstamp;
status.resolution = snd_timer_resolution(tu->timeri); status.resolution = snd_timer_resolution(tu->timeri);
......
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