X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sound%2Fcore%2Foss%2Fmixer_oss.c;h=9c68bc3f97aabc93c37f6420cccdc77ab01da34d;hb=43bc926fffd92024b46cafaf7350d669ba9ca884;hp=8e7efafee93a9ecfedf3f8504feb88cad29ab186;hpb=5273a3df6485dc2ad6aa7ddd441b9a21970f003b;p=linux-2.6.git diff --git a/sound/core/oss/mixer_oss.c b/sound/core/oss/mixer_oss.c index 8e7efafee..9c68bc3f9 100644 --- a/sound/core/oss/mixer_oss.c +++ b/sound/core/oss/mixer_oss.c @@ -21,8 +21,10 @@ #include #include +#include #include #include +#include #include #include #include @@ -39,19 +41,20 @@ MODULE_ALIAS_SNDRV_MINOR(SNDRV_MINOR_OSS_MIXER); static int snd_mixer_oss_open(struct inode *inode, struct file *file) { - int cardnum = SNDRV_MINOR_OSS_CARD(iminor(inode)); - snd_card_t *card; - snd_mixer_oss_file_t *fmixer; + struct snd_card *card; + struct snd_mixer_oss_file *fmixer; int err; - if ((card = snd_cards[cardnum]) == NULL) + card = snd_lookup_oss_minor_data(iminor(inode), + SNDRV_OSS_DEVICE_TYPE_MIXER); + if (card == NULL) return -ENODEV; if (card->mixer_oss == NULL) return -ENODEV; err = snd_card_file_add(card, file); if (err < 0) return err; - fmixer = (snd_mixer_oss_file_t *)snd_kcalloc(sizeof(*fmixer), GFP_KERNEL); + fmixer = kzalloc(sizeof(*fmixer), GFP_KERNEL); if (fmixer == NULL) { snd_card_file_remove(card, file); return -ENOMEM; @@ -69,10 +72,10 @@ static int snd_mixer_oss_open(struct inode *inode, struct file *file) static int snd_mixer_oss_release(struct inode *inode, struct file *file) { - snd_mixer_oss_file_t *fmixer; + struct snd_mixer_oss_file *fmixer; if (file->private_data) { - fmixer = (snd_mixer_oss_file_t *) file->private_data; + fmixer = (struct snd_mixer_oss_file *) file->private_data; module_put(fmixer->card->module); snd_card_file_remove(fmixer->card, file); kfree(fmixer); @@ -80,11 +83,11 @@ static int snd_mixer_oss_release(struct inode *inode, struct file *file) return 0; } -static int snd_mixer_oss_info(snd_mixer_oss_file_t *fmixer, - mixer_info *_info) +static int snd_mixer_oss_info(struct snd_mixer_oss_file *fmixer, + mixer_info __user *_info) { - snd_card_t *card = fmixer->card; - snd_mixer_oss_t *mixer = fmixer->mixer; + struct snd_card *card = fmixer->card; + struct snd_mixer_oss *mixer = fmixer->mixer; struct mixer_info info; memset(&info, 0, sizeof(info)); @@ -96,11 +99,11 @@ static int snd_mixer_oss_info(snd_mixer_oss_file_t *fmixer, return 0; } -static int snd_mixer_oss_info_obsolete(snd_mixer_oss_file_t *fmixer, - _old_mixer_info *_info) +static int snd_mixer_oss_info_obsolete(struct snd_mixer_oss_file *fmixer, + _old_mixer_info __user *_info) { - snd_card_t *card = fmixer->card; - snd_mixer_oss_t *mixer = fmixer->mixer; + struct snd_card *card = fmixer->card; + struct snd_mixer_oss *mixer = fmixer->mixer; _old_mixer_info info; memset(&info, 0, sizeof(info)); @@ -111,9 +114,9 @@ static int snd_mixer_oss_info_obsolete(snd_mixer_oss_file_t *fmixer, return 0; } -static int snd_mixer_oss_caps(snd_mixer_oss_file_t *fmixer) +static int snd_mixer_oss_caps(struct snd_mixer_oss_file *fmixer) { - snd_mixer_oss_t *mixer = fmixer->mixer; + struct snd_mixer_oss *mixer = fmixer->mixer; int result = 0; if (mixer == NULL) @@ -123,10 +126,10 @@ static int snd_mixer_oss_caps(snd_mixer_oss_file_t *fmixer) return result; } -static int snd_mixer_oss_devmask(snd_mixer_oss_file_t *fmixer) +static int snd_mixer_oss_devmask(struct snd_mixer_oss_file *fmixer) { - snd_mixer_oss_t *mixer = fmixer->mixer; - snd_mixer_oss_slot_t *pslot; + struct snd_mixer_oss *mixer = fmixer->mixer; + struct snd_mixer_oss_slot *pslot; int result = 0, chn; if (mixer == NULL) @@ -139,10 +142,10 @@ static int snd_mixer_oss_devmask(snd_mixer_oss_file_t *fmixer) return result; } -static int snd_mixer_oss_stereodevs(snd_mixer_oss_file_t *fmixer) +static int snd_mixer_oss_stereodevs(struct snd_mixer_oss_file *fmixer) { - snd_mixer_oss_t *mixer = fmixer->mixer; - snd_mixer_oss_slot_t *pslot; + struct snd_mixer_oss *mixer = fmixer->mixer; + struct snd_mixer_oss_slot *pslot; int result = 0, chn; if (mixer == NULL) @@ -155,9 +158,9 @@ static int snd_mixer_oss_stereodevs(snd_mixer_oss_file_t *fmixer) return result; } -static int snd_mixer_oss_recmask(snd_mixer_oss_file_t *fmixer) +static int snd_mixer_oss_recmask(struct snd_mixer_oss_file *fmixer) { - snd_mixer_oss_t *mixer = fmixer->mixer; + struct snd_mixer_oss *mixer = fmixer->mixer; int result = 0; if (mixer == NULL) @@ -165,7 +168,7 @@ static int snd_mixer_oss_recmask(snd_mixer_oss_file_t *fmixer) if (mixer->put_recsrc && mixer->get_recsrc) { /* exclusive */ result = mixer->mask_recsrc; } else { - snd_mixer_oss_slot_t *pslot; + struct snd_mixer_oss_slot *pslot; int chn; for (chn = 0; chn < 31; chn++) { pslot = &mixer->slots[chn]; @@ -176,9 +179,9 @@ static int snd_mixer_oss_recmask(snd_mixer_oss_file_t *fmixer) return result; } -static int snd_mixer_oss_get_recsrc(snd_mixer_oss_file_t *fmixer) +static int snd_mixer_oss_get_recsrc(struct snd_mixer_oss_file *fmixer) { - snd_mixer_oss_t *mixer = fmixer->mixer; + struct snd_mixer_oss *mixer = fmixer->mixer; int result = 0; if (mixer == NULL) @@ -189,7 +192,7 @@ static int snd_mixer_oss_get_recsrc(snd_mixer_oss_file_t *fmixer) return err; result = 1 << result; } else { - snd_mixer_oss_slot_t *pslot; + struct snd_mixer_oss_slot *pslot; int chn; for (chn = 0; chn < 31; chn++) { pslot = &mixer->slots[chn]; @@ -204,10 +207,10 @@ static int snd_mixer_oss_get_recsrc(snd_mixer_oss_file_t *fmixer) return mixer->oss_recsrc = result; } -static int snd_mixer_oss_set_recsrc(snd_mixer_oss_file_t *fmixer, int recsrc) +static int snd_mixer_oss_set_recsrc(struct snd_mixer_oss_file *fmixer, int recsrc) { - snd_mixer_oss_t *mixer = fmixer->mixer; - snd_mixer_oss_slot_t *pslot; + struct snd_mixer_oss *mixer = fmixer->mixer; + struct snd_mixer_oss_slot *pslot; int chn, active; int result = 0; @@ -241,10 +244,10 @@ static int snd_mixer_oss_set_recsrc(snd_mixer_oss_file_t *fmixer, int recsrc) return result; } -static int snd_mixer_oss_get_volume(snd_mixer_oss_file_t *fmixer, int slot) +static int snd_mixer_oss_get_volume(struct snd_mixer_oss_file *fmixer, int slot) { - snd_mixer_oss_t *mixer = fmixer->mixer; - snd_mixer_oss_slot_t *pslot; + struct snd_mixer_oss *mixer = fmixer->mixer; + struct snd_mixer_oss_slot *pslot; int result = 0, left, right; if (mixer == NULL || slot > 30) @@ -266,11 +269,11 @@ static int snd_mixer_oss_get_volume(snd_mixer_oss_file_t *fmixer, int slot) return result; } -static int snd_mixer_oss_set_volume(snd_mixer_oss_file_t *fmixer, +static int snd_mixer_oss_set_volume(struct snd_mixer_oss_file *fmixer, int slot, int volume) { - snd_mixer_oss_t *mixer = fmixer->mixer; - snd_mixer_oss_slot_t *pslot; + struct snd_mixer_oss *mixer = fmixer->mixer; + struct snd_mixer_oss_slot *pslot; int result = 0, left = volume & 0xff, right = (volume >> 8) & 0xff; if (mixer == NULL || slot > 30) @@ -291,80 +294,81 @@ static int snd_mixer_oss_set_volume(snd_mixer_oss_file_t *fmixer, return (left & 0xff) | ((right & 0xff) << 8); } -static int snd_mixer_oss_ioctl1(snd_mixer_oss_file_t *fmixer, unsigned int cmd, unsigned long arg) +static int snd_mixer_oss_ioctl1(struct snd_mixer_oss_file *fmixer, unsigned int cmd, unsigned long arg) { + void __user *argp = (void __user *)arg; + int __user *p = argp; int tmp; snd_assert(fmixer != NULL, return -ENXIO); if (((cmd >> 8) & 0xff) == 'M') { switch (cmd) { case SOUND_MIXER_INFO: - return snd_mixer_oss_info(fmixer, (mixer_info *)arg); + return snd_mixer_oss_info(fmixer, argp); case SOUND_OLD_MIXER_INFO: - return snd_mixer_oss_info_obsolete(fmixer, (_old_mixer_info *)arg); + return snd_mixer_oss_info_obsolete(fmixer, argp); case SOUND_MIXER_WRITE_RECSRC: - if (get_user(tmp, (int *)arg)) + if (get_user(tmp, p)) return -EFAULT; tmp = snd_mixer_oss_set_recsrc(fmixer, tmp); if (tmp < 0) return tmp; - return put_user(tmp, (int *)arg); + return put_user(tmp, p); case OSS_GETVERSION: - return put_user(SNDRV_OSS_VERSION, (int *) arg); + return put_user(SNDRV_OSS_VERSION, p); case OSS_ALSAEMULVER: - return put_user(1, (int *) arg); + return put_user(1, p); case SOUND_MIXER_READ_DEVMASK: tmp = snd_mixer_oss_devmask(fmixer); if (tmp < 0) return tmp; - return put_user(tmp, (int *)arg); + return put_user(tmp, p); case SOUND_MIXER_READ_STEREODEVS: tmp = snd_mixer_oss_stereodevs(fmixer); if (tmp < 0) return tmp; - return put_user(tmp, (int *)arg); + return put_user(tmp, p); case SOUND_MIXER_READ_RECMASK: tmp = snd_mixer_oss_recmask(fmixer); if (tmp < 0) return tmp; - return put_user(tmp, (int *)arg); + return put_user(tmp, p); case SOUND_MIXER_READ_CAPS: tmp = snd_mixer_oss_caps(fmixer); if (tmp < 0) return tmp; - return put_user(tmp, (int *)arg); + return put_user(tmp, p); case SOUND_MIXER_READ_RECSRC: tmp = snd_mixer_oss_get_recsrc(fmixer); if (tmp < 0) return tmp; - return put_user(tmp, (int *)arg); + return put_user(tmp, p); } } if (cmd & SIOC_IN) { - if (get_user(tmp, (int *)arg)) + if (get_user(tmp, p)) return -EFAULT; tmp = snd_mixer_oss_set_volume(fmixer, cmd & 0xff, tmp); if (tmp < 0) return tmp; - return put_user(tmp, (int *)arg); + return put_user(tmp, p); } else if (cmd & SIOC_OUT) { tmp = snd_mixer_oss_get_volume(fmixer, cmd & 0xff); if (tmp < 0) return tmp; - return put_user(tmp, (int *)arg); + return put_user(tmp, p); } return -ENXIO; } -int snd_mixer_oss_ioctl(struct inode *inode, struct file *file, - unsigned int cmd, unsigned long arg) +static long snd_mixer_oss_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { - return snd_mixer_oss_ioctl1((snd_mixer_oss_file_t *) file->private_data, cmd, arg); + return snd_mixer_oss_ioctl1((struct snd_mixer_oss_file *) file->private_data, cmd, arg); } -int snd_mixer_oss_ioctl_card(snd_card_t *card, unsigned int cmd, unsigned long arg) +int snd_mixer_oss_ioctl_card(struct snd_card *card, unsigned int cmd, unsigned long arg) { - snd_mixer_oss_file_t fmixer; + struct snd_mixer_oss_file fmixer; snd_assert(card != NULL, return -ENXIO); if (card->mixer_oss == NULL) @@ -375,6 +379,13 @@ int snd_mixer_oss_ioctl_card(snd_card_t *card, unsigned int cmd, unsigned long a return snd_mixer_oss_ioctl1(&fmixer, cmd, arg); } +#ifdef CONFIG_COMPAT +/* all compatible */ +#define snd_mixer_oss_ioctl_compat snd_mixer_oss_ioctl +#else +#define snd_mixer_oss_ioctl_compat NULL +#endif + /* * REGISTRATION PART */ @@ -384,13 +395,8 @@ static struct file_operations snd_mixer_oss_f_ops = .owner = THIS_MODULE, .open = snd_mixer_oss_open, .release = snd_mixer_oss_release, - .ioctl = snd_mixer_oss_ioctl, -}; - -static snd_minor_t snd_mixer_oss_reg = -{ - .comment = "mixer", - .f_ops = &snd_mixer_oss_f_ops, + .unlocked_ioctl = snd_mixer_oss_ioctl, + .compat_ioctl = snd_mixer_oss_ioctl_compat, }; /* @@ -421,16 +427,16 @@ static long snd_mixer_oss_conv2(long val, long min, long max) } #if 0 -static void snd_mixer_oss_recsrce_set(snd_card_t *card, int slot) +static void snd_mixer_oss_recsrce_set(struct snd_card *card, int slot) { - snd_mixer_oss_t *mixer = card->mixer_oss; + struct snd_mixer_oss *mixer = card->mixer_oss; if (mixer) mixer->mask_recsrc |= 1 << slot; } -static int snd_mixer_oss_recsrce_get(snd_card_t *card, int slot) +static int snd_mixer_oss_recsrce_get(struct snd_card *card, int slot) { - snd_mixer_oss_t *mixer = card->mixer_oss; + struct snd_mixer_oss *mixer = card->mixer_oss; if (mixer && (mixer->mask_recsrc & (1 << slot))) return 1; return 0; @@ -477,10 +483,10 @@ struct slot { #define ID_UNKNOWN ((unsigned int)-1) -static snd_kcontrol_t *snd_mixer_oss_test_id(snd_mixer_oss_t *mixer, const char *name, int index) +static struct snd_kcontrol *snd_mixer_oss_test_id(struct snd_mixer_oss *mixer, const char *name, int index) { - snd_card_t * card = mixer->card; - snd_ctl_elem_id_t id; + struct snd_card *card = mixer->card; + struct snd_ctl_elem_id id; memset(&id, 0, sizeof(id)); id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; @@ -489,15 +495,15 @@ static snd_kcontrol_t *snd_mixer_oss_test_id(snd_mixer_oss_t *mixer, const char return snd_ctl_find_id(card, &id); } -static void snd_mixer_oss_get_volume1_vol(snd_mixer_oss_file_t *fmixer, - snd_mixer_oss_slot_t *pslot, +static void snd_mixer_oss_get_volume1_vol(struct snd_mixer_oss_file *fmixer, + struct snd_mixer_oss_slot *pslot, unsigned int numid, int *left, int *right) { - snd_ctl_elem_info_t *uinfo; - snd_ctl_elem_value_t *uctl; - snd_kcontrol_t *kctl; - snd_card_t *card = fmixer->card; + struct snd_ctl_elem_info *uinfo; + struct snd_ctl_elem_value *uctl; + struct snd_kcontrol *kctl; + struct snd_card *card = fmixer->card; if (numid == ID_UNKNOWN) return; @@ -506,34 +512,36 @@ static void snd_mixer_oss_get_volume1_vol(snd_mixer_oss_file_t *fmixer, up_read(&card->controls_rwsem); return; } - uinfo = snd_kcalloc(sizeof(*uinfo), GFP_KERNEL); - uctl = snd_kcalloc(sizeof(*uctl), GFP_KERNEL); + uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL); + uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); if (uinfo == NULL || uctl == NULL) goto __unalloc; - snd_runtime_check(!kctl->info(kctl, uinfo), goto __unalloc); - snd_runtime_check(!kctl->get(kctl, uctl), goto __unalloc); - snd_runtime_check(uinfo->type != SNDRV_CTL_ELEM_TYPE_BOOLEAN || uinfo->value.integer.min != 0 || uinfo->value.integer.max != 1, return); + if (kctl->info(kctl, uinfo)) + goto __unalloc; + if (kctl->get(kctl, uctl)) + goto __unalloc; + if (uinfo->type == SNDRV_CTL_ELEM_TYPE_BOOLEAN && + uinfo->value.integer.min == 0 && uinfo->value.integer.max == 1) + goto __unalloc; *left = snd_mixer_oss_conv1(uctl->value.integer.value[0], uinfo->value.integer.min, uinfo->value.integer.max, &pslot->volume[0]); if (uinfo->count > 1) *right = snd_mixer_oss_conv1(uctl->value.integer.value[1], uinfo->value.integer.min, uinfo->value.integer.max, &pslot->volume[1]); __unalloc: up_read(&card->controls_rwsem); - if (uctl) - kfree(uctl); - if (uinfo) - kfree(uinfo); + kfree(uctl); + kfree(uinfo); } -static void snd_mixer_oss_get_volume1_sw(snd_mixer_oss_file_t *fmixer, - snd_mixer_oss_slot_t *pslot, +static void snd_mixer_oss_get_volume1_sw(struct snd_mixer_oss_file *fmixer, + struct snd_mixer_oss_slot *pslot, unsigned int numid, int *left, int *right, int route) { - snd_ctl_elem_info_t *uinfo; - snd_ctl_elem_value_t *uctl; - snd_kcontrol_t *kctl; - snd_card_t *card = fmixer->card; + struct snd_ctl_elem_info *uinfo; + struct snd_ctl_elem_value *uctl; + struct snd_kcontrol *kctl; + struct snd_card *card = fmixer->card; if (numid == ID_UNKNOWN) return; @@ -542,12 +550,14 @@ static void snd_mixer_oss_get_volume1_sw(snd_mixer_oss_file_t *fmixer, up_read(&card->controls_rwsem); return; } - uinfo = snd_kcalloc(sizeof(*uinfo), GFP_KERNEL); - uctl = snd_kcalloc(sizeof(*uctl), GFP_KERNEL); + uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL); + uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); if (uinfo == NULL || uctl == NULL) goto __unalloc; - snd_runtime_check(!kctl->info(kctl, uinfo), goto __unalloc); - snd_runtime_check(!kctl->get(kctl, uctl), goto __unalloc); + if (kctl->info(kctl, uinfo)) + goto __unalloc; + if (kctl->get(kctl, uctl)) + goto __unalloc; if (!uctl->value.integer.value[0]) { *left = 0; if (uinfo->count == 1) @@ -557,14 +567,12 @@ static void snd_mixer_oss_get_volume1_sw(snd_mixer_oss_file_t *fmixer, *right = 0; __unalloc: up_read(&card->controls_rwsem); - if (uctl) - kfree(uctl); - if (uinfo) - kfree(uinfo); + kfree(uctl); + kfree(uinfo); } -static int snd_mixer_oss_get_volume1(snd_mixer_oss_file_t *fmixer, - snd_mixer_oss_slot_t *pslot, +static int snd_mixer_oss_get_volume1(struct snd_mixer_oss_file *fmixer, + struct snd_mixer_oss_slot *pslot, int *left, int *right) { struct slot *slot = (struct slot *)pslot->private_data; @@ -589,15 +597,15 @@ static int snd_mixer_oss_get_volume1(snd_mixer_oss_file_t *fmixer, return 0; } -static void snd_mixer_oss_put_volume1_vol(snd_mixer_oss_file_t *fmixer, - snd_mixer_oss_slot_t *pslot, +static void snd_mixer_oss_put_volume1_vol(struct snd_mixer_oss_file *fmixer, + struct snd_mixer_oss_slot *pslot, unsigned int numid, int left, int right) { - snd_ctl_elem_info_t *uinfo; - snd_ctl_elem_value_t *uctl; - snd_kcontrol_t *kctl; - snd_card_t *card = fmixer->card; + struct snd_ctl_elem_info *uinfo; + struct snd_ctl_elem_value *uctl; + struct snd_kcontrol *kctl; + struct snd_card *card = fmixer->card; int res; if (numid == ID_UNKNOWN) @@ -605,36 +613,38 @@ static void snd_mixer_oss_put_volume1_vol(snd_mixer_oss_file_t *fmixer, down_read(&card->controls_rwsem); if ((kctl = snd_ctl_find_numid(card, numid)) == NULL) return; - uinfo = snd_kcalloc(sizeof(*uinfo), GFP_KERNEL); - uctl = snd_kcalloc(sizeof(*uctl), GFP_KERNEL); + uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL); + uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); if (uinfo == NULL || uctl == NULL) goto __unalloc; - snd_runtime_check(!kctl->info(kctl, uinfo), goto __unalloc); - snd_runtime_check(uinfo->type != SNDRV_CTL_ELEM_TYPE_BOOLEAN || uinfo->value.integer.min != 0 || uinfo->value.integer.max != 1, return); + if (kctl->info(kctl, uinfo)) + goto __unalloc; + if (uinfo->type == SNDRV_CTL_ELEM_TYPE_BOOLEAN && + uinfo->value.integer.min == 0 && uinfo->value.integer.max == 1) + goto __unalloc; uctl->value.integer.value[0] = snd_mixer_oss_conv2(left, uinfo->value.integer.min, uinfo->value.integer.max); if (uinfo->count > 1) uctl->value.integer.value[1] = snd_mixer_oss_conv2(right, uinfo->value.integer.min, uinfo->value.integer.max); - snd_runtime_check((res = kctl->put(kctl, uctl)) >= 0, goto __unalloc); + if ((res = kctl->put(kctl, uctl)) < 0) + goto __unalloc; if (res > 0) snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id); __unalloc: up_read(&card->controls_rwsem); - if (uctl) - kfree(uctl); - if (uinfo) - kfree(uinfo); + kfree(uctl); + kfree(uinfo); } -static void snd_mixer_oss_put_volume1_sw(snd_mixer_oss_file_t *fmixer, - snd_mixer_oss_slot_t *pslot, +static void snd_mixer_oss_put_volume1_sw(struct snd_mixer_oss_file *fmixer, + struct snd_mixer_oss_slot *pslot, unsigned int numid, int left, int right, int route) { - snd_ctl_elem_info_t *uinfo; - snd_ctl_elem_value_t *uctl; - snd_kcontrol_t *kctl; - snd_card_t *card = fmixer->card; + struct snd_ctl_elem_info *uinfo; + struct snd_ctl_elem_value *uctl; + struct snd_kcontrol *kctl; + struct snd_card *card = fmixer->card; int res; if (numid == ID_UNKNOWN) @@ -644,11 +654,12 @@ static void snd_mixer_oss_put_volume1_sw(snd_mixer_oss_file_t *fmixer, up_read(&fmixer->card->controls_rwsem); return; } - uinfo = snd_kcalloc(sizeof(*uinfo), GFP_KERNEL); - uctl = snd_kcalloc(sizeof(*uctl), GFP_KERNEL); + uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL); + uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); if (uinfo == NULL || uctl == NULL) goto __unalloc; - snd_runtime_check(!kctl->info(kctl, uinfo), goto __unalloc); + if (kctl->info(kctl, uinfo)) + goto __unalloc; if (uinfo->count > 1) { uctl->value.integer.value[0] = left > 0 ? 1 : 0; uctl->value.integer.value[route ? 3 : 1] = right > 0 ? 1 : 0; @@ -659,19 +670,18 @@ static void snd_mixer_oss_put_volume1_sw(snd_mixer_oss_file_t *fmixer, } else { uctl->value.integer.value[0] = (left > 0 || right > 0) ? 1 : 0; } - snd_runtime_check((res = kctl->put(kctl, uctl)) >= 0, goto __unalloc); + if ((res = kctl->put(kctl, uctl)) < 0) + goto __unalloc; if (res > 0) snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id); __unalloc: up_read(&card->controls_rwsem); - if (uctl) - kfree(uctl); - if (uinfo) - kfree(uinfo); + kfree(uctl); + kfree(uinfo); } -static int snd_mixer_oss_put_volume1(snd_mixer_oss_file_t *fmixer, - snd_mixer_oss_slot_t *pslot, +static int snd_mixer_oss_put_volume1(struct snd_mixer_oss_file *fmixer, + struct snd_mixer_oss_slot *pslot, int left, int right) { struct slot *slot = (struct slot *)pslot->private_data; @@ -708,8 +718,8 @@ static int snd_mixer_oss_put_volume1(snd_mixer_oss_file_t *fmixer, return 0; } -static int snd_mixer_oss_get_recsrc1_sw(snd_mixer_oss_file_t *fmixer, - snd_mixer_oss_slot_t *pslot, +static int snd_mixer_oss_get_recsrc1_sw(struct snd_mixer_oss_file *fmixer, + struct snd_mixer_oss_slot *pslot, int *active) { struct slot *slot = (struct slot *)pslot->private_data; @@ -721,8 +731,8 @@ static int snd_mixer_oss_get_recsrc1_sw(snd_mixer_oss_file_t *fmixer, return 0; } -static int snd_mixer_oss_get_recsrc1_route(snd_mixer_oss_file_t *fmixer, - snd_mixer_oss_slot_t *pslot, +static int snd_mixer_oss_get_recsrc1_route(struct snd_mixer_oss_file *fmixer, + struct snd_mixer_oss_slot *pslot, int *active) { struct slot *slot = (struct slot *)pslot->private_data; @@ -734,8 +744,8 @@ static int snd_mixer_oss_get_recsrc1_route(snd_mixer_oss_file_t *fmixer, return 0; } -static int snd_mixer_oss_put_recsrc1_sw(snd_mixer_oss_file_t *fmixer, - snd_mixer_oss_slot_t *pslot, +static int snd_mixer_oss_put_recsrc1_sw(struct snd_mixer_oss_file *fmixer, + struct snd_mixer_oss_slot *pslot, int active) { struct slot *slot = (struct slot *)pslot->private_data; @@ -744,8 +754,8 @@ static int snd_mixer_oss_put_recsrc1_sw(snd_mixer_oss_file_t *fmixer, return 0; } -static int snd_mixer_oss_put_recsrc1_route(snd_mixer_oss_file_t *fmixer, - snd_mixer_oss_slot_t *pslot, +static int snd_mixer_oss_put_recsrc1_route(struct snd_mixer_oss_file *fmixer, + struct snd_mixer_oss_slot *pslot, int active) { struct slot *slot = (struct slot *)pslot->private_data; @@ -754,28 +764,33 @@ static int snd_mixer_oss_put_recsrc1_route(snd_mixer_oss_file_t *fmixer, return 0; } -static int snd_mixer_oss_get_recsrc2(snd_mixer_oss_file_t *fmixer, unsigned int *active_index) +static int snd_mixer_oss_get_recsrc2(struct snd_mixer_oss_file *fmixer, unsigned int *active_index) { - snd_card_t *card = fmixer->card; - snd_mixer_oss_t *mixer = fmixer->mixer; - snd_kcontrol_t *kctl; - snd_mixer_oss_slot_t *pslot; + struct snd_card *card = fmixer->card; + struct snd_mixer_oss *mixer = fmixer->mixer; + struct snd_kcontrol *kctl; + struct snd_mixer_oss_slot *pslot; struct slot *slot; - snd_ctl_elem_info_t *uinfo; - snd_ctl_elem_value_t *uctl; + struct snd_ctl_elem_info *uinfo; + struct snd_ctl_elem_value *uctl; int err, idx; - uinfo = snd_kcalloc(sizeof(*uinfo), GFP_KERNEL); - uctl = snd_kcalloc(sizeof(*uctl), GFP_KERNEL); + uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL); + uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); if (uinfo == NULL || uctl == NULL) { err = -ENOMEM; goto __unlock; } down_read(&card->controls_rwsem); kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0); - snd_runtime_check(kctl != NULL, err = -ENOENT; goto __unlock); - snd_runtime_check(!(err = kctl->info(kctl, uinfo)), goto __unlock); - snd_runtime_check(!(err = kctl->get(kctl, uctl)), goto __unlock); + if (! kctl) { + err = -ENOENT; + goto __unlock; + } + if ((err = kctl->info(kctl, uinfo)) < 0) + goto __unlock; + if ((err = kctl->get(kctl, uctl)) < 0) + goto __unlock; for (idx = 0; idx < 32; idx++) { if (!(mixer->mask_recsrc & (1 << idx))) continue; @@ -793,35 +808,37 @@ static int snd_mixer_oss_get_recsrc2(snd_mixer_oss_file_t *fmixer, unsigned int err = 0; __unlock: up_read(&card->controls_rwsem); - if (uctl) - kfree(uctl); - if (uinfo) - kfree(uinfo); + kfree(uctl); + kfree(uinfo); return err; } -static int snd_mixer_oss_put_recsrc2(snd_mixer_oss_file_t *fmixer, unsigned int active_index) +static int snd_mixer_oss_put_recsrc2(struct snd_mixer_oss_file *fmixer, unsigned int active_index) { - snd_card_t *card = fmixer->card; - snd_mixer_oss_t *mixer = fmixer->mixer; - snd_kcontrol_t *kctl; - snd_mixer_oss_slot_t *pslot; + struct snd_card *card = fmixer->card; + struct snd_mixer_oss *mixer = fmixer->mixer; + struct snd_kcontrol *kctl; + struct snd_mixer_oss_slot *pslot; struct slot *slot = NULL; - snd_ctl_elem_info_t *uinfo; - snd_ctl_elem_value_t *uctl; + struct snd_ctl_elem_info *uinfo; + struct snd_ctl_elem_value *uctl; int err; unsigned int idx; - uinfo = snd_kcalloc(sizeof(*uinfo), GFP_KERNEL); - uctl = snd_kcalloc(sizeof(*uctl), GFP_KERNEL); + uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL); + uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); if (uinfo == NULL || uctl == NULL) { err = -ENOMEM; goto __unlock; } down_read(&card->controls_rwsem); kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0); - snd_runtime_check(kctl != NULL, err = -ENOENT; goto __unlock); - snd_runtime_check(!(err = kctl->info(kctl, uinfo)), goto __unlock); + if (! kctl) { + err = -ENOENT; + goto __unlock; + } + if ((err = kctl->info(kctl, uinfo)) < 0) + goto __unlock; for (idx = 0; idx < 32; idx++) { if (!(mixer->mask_recsrc & (1 << idx))) continue; @@ -835,19 +852,18 @@ static int snd_mixer_oss_put_recsrc2(snd_mixer_oss_file_t *fmixer, unsigned int break; slot = NULL; } - snd_runtime_check(slot != NULL, goto __unlock); + if (! slot) + goto __unlock; for (idx = 0; idx < uinfo->count; idx++) uctl->value.enumerated.item[idx] = slot->capture_item; - snd_runtime_check((err = kctl->put(kctl, uctl)) >= 0, ); + err = kctl->put(kctl, uctl); if (err > 0) snd_ctl_notify(fmixer->card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id); err = 0; __unlock: up_read(&card->controls_rwsem); - if (uctl) - kfree(uctl); - if (uinfo) - kfree(uinfo); + kfree(uctl); + kfree(uinfo); return err; } @@ -857,11 +873,11 @@ struct snd_mixer_oss_assign_table { int index; }; -static int snd_mixer_oss_build_test(snd_mixer_oss_t *mixer, struct slot *slot, const char *name, int index, int item) +static int snd_mixer_oss_build_test(struct snd_mixer_oss *mixer, struct slot *slot, const char *name, int index, int item) { - snd_ctl_elem_info_t info; - snd_kcontrol_t *kcontrol; - snd_card_t *card = mixer->card; + struct snd_ctl_elem_info *info; + struct snd_kcontrol *kcontrol; + struct snd_card *card = mixer->card; int err; down_read(&card->controls_rwsem); @@ -870,19 +886,26 @@ static int snd_mixer_oss_build_test(snd_mixer_oss_t *mixer, struct slot *slot, c up_read(&card->controls_rwsem); return 0; } - if ((err = kcontrol->info(kcontrol, &info)) < 0) { + info = kmalloc(sizeof(*info), GFP_KERNEL); + if (! info) { up_read(&card->controls_rwsem); + return -ENOMEM; + } + if ((err = kcontrol->info(kcontrol, info)) < 0) { + up_read(&card->controls_rwsem); + kfree(info); return err; } slot->numid[item] = kcontrol->id.numid; up_read(&card->controls_rwsem); - if (info.count > slot->channels) - slot->channels = info.count; + if (info->count > slot->channels) + slot->channels = info->count; slot->present |= 1 << item; + kfree(info); return 0; } -static void snd_mixer_oss_slot_free(snd_mixer_oss_slot_t *chn) +static void snd_mixer_oss_slot_free(struct snd_mixer_oss_slot *chn) { struct slot *p = (struct slot *)chn->private_data; if (p) { @@ -894,7 +917,7 @@ static void snd_mixer_oss_slot_free(snd_mixer_oss_slot_t *chn) } } -static void mixer_slot_clear(snd_mixer_oss_slot_t *rslot) +static void mixer_slot_clear(struct snd_mixer_oss_slot *rslot) { int idx = rslot->number; /* remember this */ if (rslot->private_free) @@ -908,12 +931,12 @@ static void mixer_slot_clear(snd_mixer_oss_slot_t *rslot) * ptr_allocated means the entry is dynamically allocated (change via proc file). * when replace_old = 1, the old entry is replaced with the new one. */ -static int snd_mixer_oss_build_input(snd_mixer_oss_t *mixer, struct snd_mixer_oss_assign_table *ptr, int ptr_allocated, int replace_old) +static int snd_mixer_oss_build_input(struct snd_mixer_oss *mixer, struct snd_mixer_oss_assign_table *ptr, int ptr_allocated, int replace_old) { struct slot slot; struct slot *pslot; - snd_kcontrol_t *kctl; - snd_mixer_oss_slot_t *rslot; + struct snd_kcontrol *kctl; + struct snd_mixer_oss_slot *rslot; char str[64]; /* check if already assigned */ @@ -963,37 +986,47 @@ static int snd_mixer_oss_build_input(snd_mixer_oss_t *mixer, struct snd_mixer_os return 0; down_read(&mixer->card->controls_rwsem); if (ptr->index == 0 && (kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0)) != NULL) { - snd_ctl_elem_info_t uinfo; + struct snd_ctl_elem_info *uinfo; - memset(&uinfo, 0, sizeof(uinfo)); - if (kctl->info(kctl, &uinfo)) + uinfo = kmalloc(sizeof(*uinfo), GFP_KERNEL); + if (! uinfo) { + up_read(&mixer->card->controls_rwsem); + return -ENOMEM; + } + + memset(uinfo, 0, sizeof(*uinfo)); + if (kctl->info(kctl, uinfo)) { + up_read(&mixer->card->controls_rwsem); return 0; + } strcpy(str, ptr->name); if (!strcmp(str, "Master")) strcpy(str, "Mix"); if (!strcmp(str, "Master Mono")) strcpy(str, "Mix Mono"); slot.capture_item = 0; - if (!strcmp(uinfo.value.enumerated.name, str)) { + if (!strcmp(uinfo->value.enumerated.name, str)) { slot.present |= SNDRV_MIXER_OSS_PRESENT_CAPTURE; } else { - for (slot.capture_item = 1; slot.capture_item < uinfo.value.enumerated.items; slot.capture_item++) { - uinfo.value.enumerated.item = slot.capture_item; - if (kctl->info(kctl, &uinfo)) { + for (slot.capture_item = 1; slot.capture_item < uinfo->value.enumerated.items; slot.capture_item++) { + uinfo->value.enumerated.item = slot.capture_item; + if (kctl->info(kctl, uinfo)) { up_read(&mixer->card->controls_rwsem); return 0; } - if (!strcmp(uinfo.value.enumerated.name, str)) { + if (!strcmp(uinfo->value.enumerated.name, str)) { slot.present |= SNDRV_MIXER_OSS_PRESENT_CAPTURE; break; } } } + kfree(uinfo); } up_read(&mixer->card->controls_rwsem); if (slot.present != 0) { pslot = (struct slot *)kmalloc(sizeof(slot), GFP_KERNEL); - snd_runtime_check(pslot != NULL, return -ENOMEM); + if (! pslot) + return -ENOMEM; *pslot = slot; pslot->signature = SNDRV_MIXER_OSS_SIGNATURE; pslot->assigned = ptr; @@ -1020,6 +1053,7 @@ static int snd_mixer_oss_build_input(snd_mixer_oss_t *mixer, struct snd_mixer_os return 0; } +#ifdef CONFIG_PROC_FS /* */ #define MIXER_VOL(name) [SOUND_MIXER_##name] = #name @@ -1055,13 +1089,13 @@ static char *oss_mixer_names[SNDRV_OSS_MAX_MIXERS] = { * /proc interface */ -static void snd_mixer_oss_proc_read(snd_info_entry_t *entry, - snd_info_buffer_t * buffer) +static void snd_mixer_oss_proc_read(struct snd_info_entry *entry, + struct snd_info_buffer *buffer) { - snd_mixer_oss_t *mixer = snd_magic_cast(snd_mixer_oss_t, entry->private_data, return); + struct snd_mixer_oss *mixer = entry->private_data; int i; - down(&mixer->reg_mutex); + mutex_lock(&mixer->reg_mutex); for (i = 0; i < SNDRV_OSS_MAX_MIXERS; i++) { struct slot *p; @@ -1076,13 +1110,13 @@ static void snd_mixer_oss_proc_read(snd_info_entry_t *entry, else snd_iprintf(buffer, "\"\" 0\n"); } - up(&mixer->reg_mutex); + mutex_unlock(&mixer->reg_mutex); } -static void snd_mixer_oss_proc_write(snd_info_entry_t *entry, - snd_info_buffer_t * buffer) +static void snd_mixer_oss_proc_write(struct snd_info_entry *entry, + struct snd_info_buffer *buffer) { - snd_mixer_oss_t *mixer = snd_magic_cast(snd_mixer_oss_t, entry->private_data, return); + struct snd_mixer_oss *mixer = entry->private_data; char line[128], str[32], idxstr[16], *cptr; int ch, idx; struct snd_mixer_oss_assign_table *tbl; @@ -1100,9 +1134,9 @@ static void snd_mixer_oss_proc_write(snd_info_entry_t *entry, cptr = snd_info_get_str(str, cptr, sizeof(str)); if (! *str) { /* remove the entry */ - down(&mixer->reg_mutex); + mutex_lock(&mixer->reg_mutex); mixer_slot_clear(&mixer->slots[ch]); - up(&mixer->reg_mutex); + mutex_unlock(&mixer->reg_mutex); continue; } snd_info_get_str(idxstr, cptr, sizeof(idxstr)); @@ -1111,7 +1145,7 @@ static void snd_mixer_oss_proc_write(snd_info_entry_t *entry, snd_printk(KERN_ERR "mixer_oss: invalid index %d\n", idx); continue; } - down(&mixer->reg_mutex); + mutex_lock(&mixer->reg_mutex); slot = (struct slot *)mixer->slots[ch].private_data; if (slot && slot->assigned && slot->assigned->index == idx && ! strcmp(slot->assigned->name, str)) @@ -1123,7 +1157,7 @@ static void snd_mixer_oss_proc_write(snd_info_entry_t *entry, goto __unlock; } tbl->oss_id = ch; - tbl->name = snd_kmalloc_strdup(str, GFP_KERNEL); + tbl->name = kstrdup(str, GFP_KERNEL); if (! tbl->name) { kfree(tbl); goto __unlock; @@ -1134,13 +1168,13 @@ static void snd_mixer_oss_proc_write(snd_info_entry_t *entry, kfree(tbl); } __unlock: - up(&mixer->reg_mutex); + mutex_unlock(&mixer->reg_mutex); } } -static void snd_mixer_oss_proc_init(snd_mixer_oss_t *mixer) +static void snd_mixer_oss_proc_init(struct snd_mixer_oss *mixer) { - snd_info_entry_t *entry; + struct snd_info_entry *entry; entry = snd_info_create_card_entry(mixer->card, "oss_mixer", mixer->card->proc_root); @@ -1160,15 +1194,19 @@ static void snd_mixer_oss_proc_init(snd_mixer_oss_t *mixer) mixer->proc_entry = entry; } -static void snd_mixer_oss_proc_done(snd_mixer_oss_t *mixer) +static void snd_mixer_oss_proc_done(struct snd_mixer_oss *mixer) { if (mixer->proc_entry) { snd_info_unregister(mixer->proc_entry); mixer->proc_entry = NULL; } } +#else /* !CONFIG_PROC_FS */ +#define snd_mixer_oss_proc_init(mix) +#define snd_mixer_oss_proc_done(mix) +#endif /* CONFIG_PROC_FS */ -static void snd_mixer_oss_build(snd_mixer_oss_t *mixer) +static void snd_mixer_oss_build(struct snd_mixer_oss *mixer) { static struct snd_mixer_oss_assign_table table[] = { { SOUND_MIXER_VOLUME, "Master", 0 }, @@ -1208,7 +1246,7 @@ static void snd_mixer_oss_build(snd_mixer_oss_t *mixer) }; unsigned int idx; - for (idx = 0; idx < sizeof(table) / sizeof(struct snd_mixer_oss_assign_table); idx++) + for (idx = 0; idx < ARRAY_SIZE(table); idx++) snd_mixer_oss_build_input(mixer, &table[idx], 0, 0); if (mixer->mask_recsrc) { mixer->get_recsrc = snd_mixer_oss_get_recsrc2; @@ -1222,8 +1260,8 @@ static void snd_mixer_oss_build(snd_mixer_oss_t *mixer) static int snd_mixer_oss_free1(void *private) { - snd_mixer_oss_t *mixer = snd_magic_cast(snd_mixer_oss_t, private, return -ENXIO); - snd_card_t * card; + struct snd_mixer_oss *mixer = private; + struct snd_card *card; int idx; snd_assert(mixer != NULL, return -ENXIO); @@ -1231,33 +1269,34 @@ static int snd_mixer_oss_free1(void *private) snd_assert(mixer == card->mixer_oss, return -ENXIO); card->mixer_oss = NULL; for (idx = 0; idx < SNDRV_OSS_MAX_MIXERS; idx++) { - snd_mixer_oss_slot_t *chn = &mixer->slots[idx]; + struct snd_mixer_oss_slot *chn = &mixer->slots[idx]; if (chn->private_free) chn->private_free(chn); } - snd_magic_kfree(mixer); + kfree(mixer); return 0; } -static int snd_mixer_oss_notify_handler(snd_card_t * card, int cmd) +static int snd_mixer_oss_notify_handler(struct snd_card *card, int cmd) { - snd_mixer_oss_t *mixer; + struct snd_mixer_oss *mixer; if (cmd == SND_MIXER_OSS_NOTIFY_REGISTER) { char name[128]; int idx, err; - mixer = snd_magic_kcalloc(snd_mixer_oss_t, sizeof(snd_mixer_oss_t), GFP_KERNEL); + mixer = kcalloc(2, sizeof(*mixer), GFP_KERNEL); if (mixer == NULL) return -ENOMEM; - init_MUTEX(&mixer->reg_mutex); + mutex_init(&mixer->reg_mutex); sprintf(name, "mixer%i%i", card->number, 0); if ((err = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MIXER, card, 0, - &snd_mixer_oss_reg, + &snd_mixer_oss_f_ops, card, name)) < 0) { - snd_printk("unable to register OSS mixer device %i:%i\n", card->number, 0); - snd_magic_kfree(mixer); + snd_printk(KERN_ERR "unable to register OSS mixer device %i:%i\n", + card->number, 0); + kfree(mixer); return err; } mixer->oss_dev_alloc = 1;