Skip to content

Commit

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

Signed-off-by: Takashi Iwai <[email protected]>
Signed-off-by: Jaroslav Kysela <[email protected]>
  • Loading branch information
tiwai authored and perexg committed Aug 13, 2008
1 parent 5ef0346 commit 7eaa943
Show file tree
Hide file tree
Showing 42 changed files with 583 additions and 388 deletions.
2 changes: 2 additions & 0 deletions include/sound/pcm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_AES3_CON_FS_48000<<24))

#define PCM_RUNTIME_CHECK(sub) snd_BUG_ON(!(sub) || !(sub)->runtime)

#endif /* __SOUND_PCM_H */
50 changes: 31 additions & 19 deletions sound/core/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ void snd_ctl_notify(struct snd_card *card, unsigned int mask,
struct snd_ctl_file *ctl;
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);
#if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
card->mixer_oss_change_count++;
Expand Down Expand Up @@ -188,8 +189,8 @@ static struct snd_kcontrol *snd_ctl_new(struct snd_kcontrol *control,
struct snd_kcontrol *kctl;
unsigned int idx;

snd_assert(control != NULL, return NULL);
snd_assert(control->count > 0, return NULL);
if (snd_BUG_ON(!control || !control->count))
return NULL;
kctl = kzalloc(sizeof(*kctl) + sizeof(struct snd_kcontrol_volatile) * control->count, GFP_KERNEL);
if (kctl == NULL) {
snd_printk(KERN_ERR "Cannot allocate control instance\n");
Expand Down Expand Up @@ -218,8 +219,8 @@ struct snd_kcontrol *snd_ctl_new1(const struct snd_kcontrol_new *ncontrol,
struct snd_kcontrol kctl;
unsigned int access;

snd_assert(ncontrol != NULL, return NULL);
snd_assert(ncontrol->info != NULL, return NULL);
if (snd_BUG_ON(!ncontrol || !ncontrol->info))
return NULL;
memset(&kctl, 0, sizeof(kctl));
kctl.id.iface = ncontrol->iface;
kctl.id.device = ncontrol->device;
Expand Down Expand Up @@ -315,8 +316,8 @@ int snd_ctl_add(struct snd_card *card, struct snd_kcontrol *kcontrol)

if (! kcontrol)
return err;
snd_assert(card != NULL, goto error);
snd_assert(kcontrol->info != NULL, goto error);
if (snd_BUG_ON(!card || !kcontrol->info))
goto error;
id = kcontrol->id;
down_write(&card->controls_rwsem);
if (snd_ctl_find_id(card, &id)) {
Expand Down Expand Up @@ -367,7 +368,8 @@ int snd_ctl_remove(struct snd_card *card, struct snd_kcontrol *kcontrol)
struct snd_ctl_elem_id id;
unsigned int idx;

snd_assert(card != NULL && kcontrol != NULL, return -EINVAL);
if (snd_BUG_ON(!card || !kcontrol))
return -EINVAL;
list_del(&kcontrol->list);
card->controls_count -= kcontrol->count;
id = kcontrol->id;
Expand Down Expand Up @@ -487,7 +489,8 @@ struct snd_kcontrol *snd_ctl_find_numid(struct snd_card *card, unsigned int numi
{
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) {
if (kctl->id.numid <= numid && kctl->id.numid + kctl->count > numid)
return kctl;
Expand All @@ -514,7 +517,8 @@ struct snd_kcontrol *snd_ctl_find_id(struct snd_card *card,
{
struct snd_kcontrol *kctl;

snd_assert(card != NULL && id != NULL, return NULL);
if (snd_BUG_ON(!card || !id))
return NULL;
if (id->numid != 0)
return snd_ctl_find_numid(card, id->numid);
list_for_each_entry(kctl, &card->controls, list) {
Expand Down Expand Up @@ -647,7 +651,7 @@ static int snd_ctl_elem_info(struct snd_ctl_file *ctl,
#endif
result = kctl->info(kctl, info);
if (result >= 0) {
snd_assert(info->access == 0, );
snd_BUG_ON(info->access);
index_offset = snd_ctl_get_ioff(kctl, &info->id);
vd = &kctl->vd[index_offset];
snd_ctl_build_ioff(&info->id, kctl, index_offset);
Expand Down Expand Up @@ -1160,7 +1164,8 @@ static long snd_ctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg

ctl = file->private_data;
card = ctl->card;
snd_assert(card != NULL, return -ENXIO);
if (snd_BUG_ON(!card))
return -ENXIO;
switch (cmd) {
case SNDRV_CTL_IOCTL_PVERSION:
return put_user(SNDRV_CTL_VERSION, ip) ? -EFAULT : 0;
Expand Down Expand Up @@ -1222,7 +1227,8 @@ static ssize_t snd_ctl_read(struct file *file, char __user *buffer,
ssize_t result = 0;

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)
return -EBADFD;
if (count < sizeof(struct snd_ctl_event))
Expand Down Expand Up @@ -1328,7 +1334,8 @@ static int _snd_ctl_unregister_ioctl(snd_kctl_ioctl_func_t fcn,
{
struct snd_kctl_ioctl *p;

snd_assert(fcn != NULL, return -EINVAL);
if (snd_BUG_ON(!fcn))
return -EINVAL;
down_write(&snd_ioctl_rwsem);
list_for_each_entry(p, lists, list) {
if (p->fioctl == fcn) {
Expand Down Expand Up @@ -1404,9 +1411,11 @@ static int snd_ctl_dev_register(struct snd_device *device)
int err, cardnum;
char name[16];

snd_assert(card != NULL, return -ENXIO);
if (snd_BUG_ON(!card))
return -ENXIO;
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);
if ((err = snd_register_device(SNDRV_DEVICE_TYPE_CONTROL, card, -1,
&snd_ctl_f_ops, card, name)) < 0)
Expand All @@ -1423,9 +1432,11 @@ static int snd_ctl_dev_disconnect(struct snd_device *device)
struct snd_ctl_file *ctl;
int err, cardnum;

snd_assert(card != NULL, return -ENXIO);
if (snd_BUG_ON(!card))
return -ENXIO;
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);
list_for_each_entry(ctl, &card->ctl_files, list) {
Expand Down Expand Up @@ -1469,7 +1480,8 @@ int snd_ctl_create(struct snd_card *card)
.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);
}

Expand Down
3 changes: 2 additions & 1 deletion sound/core/control_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,8 @@ static inline long snd_ctl_ioctl_compat(struct file *file, unsigned int cmd, uns
int err;

ctl = file->private_data;
snd_assert(ctl && ctl->card, return -ENXIO);
if (snd_BUG_ON(!ctl || !ctl->card))
return -ENXIO;

switch (cmd) {
case SNDRV_CTL_IOCTL_PVERSION:
Expand Down
26 changes: 14 additions & 12 deletions sound/core/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ int snd_device_new(struct snd_card *card, snd_device_type_t type,
{
struct snd_device *dev;

snd_assert(card != NULL, return -ENXIO);
snd_assert(device_data != NULL, return -ENXIO);
snd_assert(ops != NULL, return -ENXIO);
if (snd_BUG_ON(!card || !device_data || !ops))
return -ENXIO;
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (dev == NULL) {
snd_printk(KERN_ERR "Cannot allocate device\n");
Expand Down Expand Up @@ -80,8 +79,8 @@ int snd_device_free(struct snd_card *card, void *device_data)
{
struct snd_device *dev;

snd_assert(card != NULL, return -ENXIO);
snd_assert(device_data != NULL, return -ENXIO);
if (snd_BUG_ON(!card || !device_data))
return -ENXIO;
list_for_each_entry(dev, &card->devices, list) {
if (dev->device_data != device_data)
continue;
Expand Down Expand Up @@ -123,8 +122,8 @@ int snd_device_disconnect(struct snd_card *card, void *device_data)
{
struct snd_device *dev;

snd_assert(card != NULL, return -ENXIO);
snd_assert(device_data != NULL, return -ENXIO);
if (snd_BUG_ON(!card || !device_data))
return -ENXIO;
list_for_each_entry(dev, &card->devices, list) {
if (dev->device_data != device_data)
continue;
Expand Down Expand Up @@ -159,8 +158,8 @@ int snd_device_register(struct snd_card *card, void *device_data)
struct snd_device *dev;
int err;

snd_assert(card != NULL, return -ENXIO);
snd_assert(device_data != NULL, return -ENXIO);
if (snd_BUG_ON(!card || !device_data))
return -ENXIO;
list_for_each_entry(dev, &card->devices, list) {
if (dev->device_data != device_data)
continue;
Expand Down Expand Up @@ -188,7 +187,8 @@ int snd_device_register_all(struct snd_card *card)
struct snd_device *dev;
int err;

snd_assert(card != NULL, return -ENXIO);
if (snd_BUG_ON(!card))
return -ENXIO;
list_for_each_entry(dev, &card->devices, list) {
if (dev->state == SNDRV_DEV_BUILD && dev->ops->dev_register) {
if ((err = dev->ops->dev_register(dev)) < 0)
Expand All @@ -208,7 +208,8 @@ int snd_device_disconnect_all(struct snd_card *card)
struct snd_device *dev;
int err = 0;

snd_assert(card != NULL, return -ENXIO);
if (snd_BUG_ON(!card))
return -ENXIO;
list_for_each_entry(dev, &card->devices, list) {
if (snd_device_disconnect(card, dev->device_data) < 0)
err = -ENXIO;
Expand All @@ -226,7 +227,8 @@ int snd_device_free_all(struct snd_card *card, snd_device_cmd_t cmd)
int err;
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_high = range_low + SNDRV_DEV_TYPE_RANGE_SIZE - 1;
__again:
Expand Down
16 changes: 10 additions & 6 deletions sound/core/hwdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,10 @@ int snd_hwdep_new(struct snd_card *card, char *id, int device,
.dev_disconnect = snd_hwdep_dev_disconnect,
};

snd_assert(rhwdep != NULL, return -EINVAL);
*rhwdep = NULL;
snd_assert(card != NULL, return -ENXIO);
if (snd_BUG_ON(!card))
return -ENXIO;
if (rhwdep)
*rhwdep = NULL;
hwdep = kzalloc(sizeof(*hwdep), GFP_KERNEL);
if (hwdep == NULL) {
snd_printk(KERN_ERR "hwdep: cannot allocate\n");
Expand All @@ -374,13 +375,15 @@ int snd_hwdep_new(struct snd_card *card, char *id, int device,
}
init_waitqueue_head(&hwdep->open_wait);
mutex_init(&hwdep->open_mutex);
*rhwdep = hwdep;
if (rhwdep)
*rhwdep = hwdep;
return 0;
}

static int snd_hwdep_free(struct snd_hwdep *hwdep)
{
snd_assert(hwdep != NULL, return -ENXIO);
if (!hwdep)
return 0;
if (hwdep->private_free)
hwdep->private_free(hwdep);
kfree(hwdep);
Expand Down Expand Up @@ -440,7 +443,8 @@ static int snd_hwdep_dev_disconnect(struct snd_device *device)
{
struct snd_hwdep *hwdep = device->device_data;

snd_assert(hwdep != NULL, return -ENXIO);
if (snd_BUG_ON(!hwdep))
return -ENXIO;
mutex_lock(&register_mutex);
if (snd_hwdep_search(hwdep->card, hwdep->device) != hwdep) {
mutex_unlock(&register_mutex);
Expand Down
23 changes: 15 additions & 8 deletions sound/core/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ static ssize_t snd_info_entry_read(struct file *file, char __user *buffer,
loff_t pos;

data = file->private_data;
snd_assert(data != NULL, return -ENXIO);
if (snd_BUG_ON(!data))
return -ENXIO;
pos = *offset;
if (pos < 0 || (long) pos != pos || (ssize_t) count < 0)
return -EIO;
Expand Down Expand Up @@ -258,7 +259,8 @@ static ssize_t snd_info_entry_write(struct file *file, const char __user *buffer
loff_t pos;

data = file->private_data;
snd_assert(data != NULL, return -ENXIO);
if (snd_BUG_ON(!data))
return -ENXIO;
entry = data->entry;
pos = *offset;
if (pos < 0 || (long) pos != pos || (ssize_t) count < 0)
Expand Down Expand Up @@ -614,7 +616,8 @@ int snd_info_card_create(struct snd_card *card)
char str[8];
struct snd_info_entry *entry;

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

sprintf(str, "card%i", card->number);
if ((entry = snd_info_create_module_entry(card->module, str, NULL)) == NULL)
Expand All @@ -636,7 +639,8 @@ int snd_info_card_register(struct snd_card *card)
{
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))
return 0;
Expand All @@ -654,7 +658,8 @@ int snd_info_card_register(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);
if (card->proc_root_link) {
snd_remove_proc_entry(snd_proc_root, card->proc_root_link);
Expand All @@ -671,7 +676,8 @@ void snd_info_card_disconnect(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);
card->proc_root = NULL;
return 0;
Expand Down Expand Up @@ -849,7 +855,7 @@ static void snd_info_disconnect(struct snd_info_entry *entry)
return;
list_del_init(&entry->list);
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);
entry->p = NULL;
}
Expand Down Expand Up @@ -947,7 +953,8 @@ int snd_info_register(struct snd_info_entry * entry)
{
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;
mutex_lock(&info_mutex);
p = snd_create_proc_entry(entry->name, entry->mode, root);
Expand Down
6 changes: 4 additions & 2 deletions sound/core/info_oss.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ int snd_oss_info_register(int dev, int num, char *string)
{
char *x;

snd_assert(dev >= 0 && dev < SNDRV_OSS_INFO_DEV_COUNT, return -ENXIO);
snd_assert(num >= 0 && num < SNDRV_CARDS, return -ENXIO);
if (snd_BUG_ON(dev < 0 || dev >= SNDRV_OSS_INFO_DEV_COUNT))
return -ENXIO;
if (snd_BUG_ON(num < 0 || num >= SNDRV_CARDS))
return -ENXIO;
mutex_lock(&strings);
if (string == NULL) {
if ((x = snd_sndstat_strings[num][dev]) != NULL) {
Expand Down
3 changes: 2 additions & 1 deletion sound/core/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,8 @@ int snd_card_register(struct snd_card *card)
{
int err;

snd_assert(card != NULL, return -EINVAL);
if (snd_BUG_ON(!card))
return -EINVAL;
#ifndef CONFIG_SYSFS_DEPRECATED
if (!card->card_dev) {
card->card_dev = device_create_drvdata(sound_class, card->dev,
Expand Down
Loading

0 comments on commit 7eaa943

Please sign in to comment.