diff options
Diffstat (limited to 'sound/core/control.c')
-rw-r--r-- | sound/core/control.c | 54 |
1 files changed, 33 insertions, 21 deletions
diff --git a/sound/core/control.c b/sound/core/control.c index 281b2e2ef0ea..6d71f9a7ccbb 100644 --- a/sound/core/control.c +++ b/sound/core/control.c | |||
@@ -139,7 +139,8 @@ void snd_ctl_notify(struct snd_card *card, unsigned int mask, | |||
139 | struct snd_ctl_file *ctl; | 139 | struct snd_ctl_file *ctl; |
140 | struct snd_kctl_event *ev; | 140 | struct snd_kctl_event *ev; |
141 | 141 | ||
142 | snd_assert(card != NULL && id != NULL, return); | 142 | if (snd_BUG_ON(!card || !id)) |
143 | return; | ||
143 | read_lock(&card->ctl_files_rwlock); | 144 | read_lock(&card->ctl_files_rwlock); |
144 | #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE) | 145 | #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE) |
145 | card->mixer_oss_change_count++; | 146 | card->mixer_oss_change_count++; |
@@ -188,8 +189,8 @@ static struct snd_kcontrol *snd_ctl_new(struct snd_kcontrol *control, | |||
188 | struct snd_kcontrol *kctl; | 189 | struct snd_kcontrol *kctl; |
189 | unsigned int idx; | 190 | unsigned int idx; |
190 | 191 | ||
191 | snd_assert(control != NULL, return NULL); | 192 | if (snd_BUG_ON(!control || !control->count)) |
192 | snd_assert(control->count > 0, return NULL); | 193 | return NULL; |
193 | kctl = kzalloc(sizeof(*kctl) + sizeof(struct snd_kcontrol_volatile) * control->count, GFP_KERNEL); | 194 | kctl = kzalloc(sizeof(*kctl) + sizeof(struct snd_kcontrol_volatile) * control->count, GFP_KERNEL); |
194 | if (kctl == NULL) { | 195 | if (kctl == NULL) { |
195 | snd_printk(KERN_ERR "Cannot allocate control instance\n"); | 196 | 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 | struct snd_kcontrol kctl; | 219 | struct snd_kcontrol kctl; |
219 | unsigned int access; | 220 | unsigned int access; |
220 | 221 | ||
221 | snd_assert(ncontrol != NULL, return NULL); | 222 | if (snd_BUG_ON(!ncontrol || !ncontrol->info)) |
222 | snd_assert(ncontrol->info != NULL, return NULL); | 223 | return NULL; |
223 | memset(&kctl, 0, sizeof(kctl)); | 224 | memset(&kctl, 0, sizeof(kctl)); |
224 | kctl.id.iface = ncontrol->iface; | 225 | kctl.id.iface = ncontrol->iface; |
225 | kctl.id.device = ncontrol->device; | 226 | kctl.id.device = ncontrol->device; |
@@ -315,8 +316,8 @@ int snd_ctl_add(struct snd_card *card, struct snd_kcontrol *kcontrol) | |||
315 | 316 | ||
316 | if (! kcontrol) | 317 | if (! kcontrol) |
317 | return err; | 318 | return err; |
318 | snd_assert(card != NULL, goto error); | 319 | if (snd_BUG_ON(!card || !kcontrol->info)) |
319 | snd_assert(kcontrol->info != NULL, goto error); | 320 | goto error; |
320 | id = kcontrol->id; | 321 | id = kcontrol->id; |
321 | down_write(&card->controls_rwsem); | 322 | down_write(&card->controls_rwsem); |
322 | if (snd_ctl_find_id(card, &id)) { | 323 | if (snd_ctl_find_id(card, &id)) { |
@@ -367,7 +368,8 @@ int snd_ctl_remove(struct snd_card *card, struct snd_kcontrol *kcontrol) | |||
367 | struct snd_ctl_elem_id id; | 368 | struct snd_ctl_elem_id id; |
368 | unsigned int idx; | 369 | unsigned int idx; |
369 | 370 | ||
370 | snd_assert(card != NULL && kcontrol != NULL, return -EINVAL); | 371 | if (snd_BUG_ON(!card || !kcontrol)) |
372 | return -EINVAL; | ||
371 | list_del(&kcontrol->list); | 373 | list_del(&kcontrol->list); |
372 | card->controls_count -= kcontrol->count; | 374 | card->controls_count -= kcontrol->count; |
373 | id = kcontrol->id; | 375 | id = kcontrol->id; |
@@ -487,7 +489,8 @@ struct snd_kcontrol *snd_ctl_find_numid(struct snd_card *card, unsigned int numi | |||
487 | { | 489 | { |
488 | struct snd_kcontrol *kctl; | 490 | struct snd_kcontrol *kctl; |
489 | 491 | ||
490 | snd_assert(card != NULL && numid != 0, return NULL); | 492 | if (snd_BUG_ON(!card || !numid)) |
493 | return NULL; | ||
491 | list_for_each_entry(kctl, &card->controls, list) { | 494 | list_for_each_entry(kctl, &card->controls, list) { |
492 | if (kctl->id.numid <= numid && kctl->id.numid + kctl->count > numid) | 495 | if (kctl->id.numid <= numid && kctl->id.numid + kctl->count > numid) |
493 | return kctl; | 496 | return kctl; |
@@ -514,7 +517,8 @@ struct snd_kcontrol *snd_ctl_find_id(struct snd_card *card, | |||
514 | { | 517 | { |
515 | struct snd_kcontrol *kctl; | 518 | struct snd_kcontrol *kctl; |
516 | 519 | ||
517 | snd_assert(card != NULL && id != NULL, return NULL); | 520 | if (snd_BUG_ON(!card || !id)) |
521 | return NULL; | ||
518 | if (id->numid != 0) | 522 | if (id->numid != 0) |
519 | return snd_ctl_find_numid(card, id->numid); | 523 | return snd_ctl_find_numid(card, id->numid); |
520 | list_for_each_entry(kctl, &card->controls, list) { | 524 | list_for_each_entry(kctl, &card->controls, list) { |
@@ -647,7 +651,7 @@ static int snd_ctl_elem_info(struct snd_ctl_file *ctl, | |||
647 | #endif | 651 | #endif |
648 | result = kctl->info(kctl, info); | 652 | result = kctl->info(kctl, info); |
649 | if (result >= 0) { | 653 | if (result >= 0) { |
650 | snd_assert(info->access == 0, ); | 654 | snd_BUG_ON(info->access); |
651 | index_offset = snd_ctl_get_ioff(kctl, &info->id); | 655 | index_offset = snd_ctl_get_ioff(kctl, &info->id); |
652 | vd = &kctl->vd[index_offset]; | 656 | vd = &kctl->vd[index_offset]; |
653 | snd_ctl_build_ioff(&info->id, kctl, index_offset); | 657 | 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 | 1164 | ||
1161 | ctl = file->private_data; | 1165 | ctl = file->private_data; |
1162 | card = ctl->card; | 1166 | card = ctl->card; |
1163 | snd_assert(card != NULL, return -ENXIO); | 1167 | if (snd_BUG_ON(!card)) |
1168 | return -ENXIO; | ||
1164 | switch (cmd) { | 1169 | switch (cmd) { |
1165 | case SNDRV_CTL_IOCTL_PVERSION: | 1170 | case SNDRV_CTL_IOCTL_PVERSION: |
1166 | return put_user(SNDRV_CTL_VERSION, ip) ? -EFAULT : 0; | 1171 | 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 | ssize_t result = 0; | 1227 | ssize_t result = 0; |
1223 | 1228 | ||
1224 | ctl = file->private_data; | 1229 | ctl = file->private_data; |
1225 | snd_assert(ctl != NULL && ctl->card != NULL, return -ENXIO); | 1230 | if (snd_BUG_ON(!ctl || !ctl->card)) |
1231 | return -ENXIO; | ||
1226 | if (!ctl->subscribed) | 1232 | if (!ctl->subscribed) |
1227 | return -EBADFD; | 1233 | return -EBADFD; |
1228 | if (count < sizeof(struct snd_ctl_event)) | 1234 | if (count < sizeof(struct snd_ctl_event)) |
@@ -1328,7 +1334,8 @@ static int _snd_ctl_unregister_ioctl(snd_kctl_ioctl_func_t fcn, | |||
1328 | { | 1334 | { |
1329 | struct snd_kctl_ioctl *p; | 1335 | struct snd_kctl_ioctl *p; |
1330 | 1336 | ||
1331 | snd_assert(fcn != NULL, return -EINVAL); | 1337 | if (snd_BUG_ON(!fcn)) |
1338 | return -EINVAL; | ||
1332 | down_write(&snd_ioctl_rwsem); | 1339 | down_write(&snd_ioctl_rwsem); |
1333 | list_for_each_entry(p, lists, list) { | 1340 | list_for_each_entry(p, lists, list) { |
1334 | if (p->fioctl == fcn) { | 1341 | if (p->fioctl == fcn) { |
@@ -1404,9 +1411,11 @@ static int snd_ctl_dev_register(struct snd_device *device) | |||
1404 | int err, cardnum; | 1411 | int err, cardnum; |
1405 | char name[16]; | 1412 | char name[16]; |
1406 | 1413 | ||
1407 | snd_assert(card != NULL, return -ENXIO); | 1414 | if (snd_BUG_ON(!card)) |
1415 | return -ENXIO; | ||
1408 | cardnum = card->number; | 1416 | cardnum = card->number; |
1409 | snd_assert(cardnum >= 0 && cardnum < SNDRV_CARDS, return -ENXIO); | 1417 | if (snd_BUG_ON(cardnum < 0 || cardnum >= SNDRV_CARDS)) |
1418 | return -ENXIO; | ||
1410 | sprintf(name, "controlC%i", cardnum); | 1419 | sprintf(name, "controlC%i", cardnum); |
1411 | if ((err = snd_register_device(SNDRV_DEVICE_TYPE_CONTROL, card, -1, | 1420 | if ((err = snd_register_device(SNDRV_DEVICE_TYPE_CONTROL, card, -1, |
1412 | &snd_ctl_f_ops, card, name)) < 0) | 1421 | &snd_ctl_f_ops, card, name)) < 0) |
@@ -1423,16 +1432,18 @@ static int snd_ctl_dev_disconnect(struct snd_device *device) | |||
1423 | struct snd_ctl_file *ctl; | 1432 | struct snd_ctl_file *ctl; |
1424 | int err, cardnum; | 1433 | int err, cardnum; |
1425 | 1434 | ||
1426 | snd_assert(card != NULL, return -ENXIO); | 1435 | if (snd_BUG_ON(!card)) |
1436 | return -ENXIO; | ||
1427 | cardnum = card->number; | 1437 | cardnum = card->number; |
1428 | snd_assert(cardnum >= 0 && cardnum < SNDRV_CARDS, return -ENXIO); | 1438 | if (snd_BUG_ON(cardnum < 0 || cardnum >= SNDRV_CARDS)) |
1439 | return -ENXIO; | ||
1429 | 1440 | ||
1430 | down_read(&card->controls_rwsem); | 1441 | read_lock(&card->ctl_files_rwlock); |
1431 | list_for_each_entry(ctl, &card->ctl_files, list) { | 1442 | list_for_each_entry(ctl, &card->ctl_files, list) { |
1432 | wake_up(&ctl->change_sleep); | 1443 | wake_up(&ctl->change_sleep); |
1433 | kill_fasync(&ctl->fasync, SIGIO, POLL_ERR); | 1444 | kill_fasync(&ctl->fasync, SIGIO, POLL_ERR); |
1434 | } | 1445 | } |
1435 | up_read(&card->controls_rwsem); | 1446 | read_unlock(&card->ctl_files_rwlock); |
1436 | 1447 | ||
1437 | if ((err = snd_unregister_device(SNDRV_DEVICE_TYPE_CONTROL, | 1448 | if ((err = snd_unregister_device(SNDRV_DEVICE_TYPE_CONTROL, |
1438 | card, -1)) < 0) | 1449 | card, -1)) < 0) |
@@ -1469,7 +1480,8 @@ int snd_ctl_create(struct snd_card *card) | |||
1469 | .dev_disconnect = snd_ctl_dev_disconnect, | 1480 | .dev_disconnect = snd_ctl_dev_disconnect, |
1470 | }; | 1481 | }; |
1471 | 1482 | ||
1472 | snd_assert(card != NULL, return -ENXIO); | 1483 | if (snd_BUG_ON(!card)) |
1484 | return -ENXIO; | ||
1473 | return snd_device_new(card, SNDRV_DEV_CONTROL, card, &ops); | 1485 | return snd_device_new(card, SNDRV_DEV_CONTROL, card, &ops); |
1474 | } | 1486 | } |
1475 | 1487 | ||