From 8dea9d382a7aca9ebb48a80a34d7e1cf4ac8dcb2 Mon Sep 17 00:00:00 2001 From: Andi Kleen Date: Sat, 18 Aug 2012 19:56:22 -0700 Subject: ALSA: lto, sound: Fix export symbols for !CONFIG_MODULES The new LTO EXPORT_SYMBOL references symbols even without CONFIG_MODULES. Since these functions are macros in this case this doesn't work. Add a ifdef to fix the build. Signed-off-by: Andi Kleen Signed-off-by: Takashi Iwai --- sound/core/seq/seq_device.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sound/core') diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c index 5cf8d65..60e8fc1 100644 --- a/sound/core/seq/seq_device.c +++ b/sound/core/seq/seq_device.c @@ -569,5 +569,7 @@ EXPORT_SYMBOL(snd_seq_device_load_drivers); EXPORT_SYMBOL(snd_seq_device_new); EXPORT_SYMBOL(snd_seq_device_register_driver); EXPORT_SYMBOL(snd_seq_device_unregister_driver); +#ifdef CONFIG_MODULES EXPORT_SYMBOL(snd_seq_autoload_lock); EXPORT_SYMBOL(snd_seq_autoload_unlock); +#endif -- cgit v1.1 From 1f3b14072bacc80d62597ed7798e3daf7615dcc6 Mon Sep 17 00:00:00 2001 From: Wei Yongjun Date: Sun, 2 Sep 2012 22:10:27 +0800 Subject: ALSA: fix possible memory leak in snd_mixer_oss_build_input() uinfo has been allocated in this function and should be freed before leaving from the error handling cases. spatch with a semantic match is used to found this problem. (http://coccinelle.lip6.fr/) Signed-off-by: Wei Yongjun Signed-off-by: Takashi Iwai --- sound/core/oss/mixer_oss.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sound/core') diff --git a/sound/core/oss/mixer_oss.c b/sound/core/oss/mixer_oss.c index 18297f7..29f6ded 100644 --- a/sound/core/oss/mixer_oss.c +++ b/sound/core/oss/mixer_oss.c @@ -1046,6 +1046,7 @@ static int snd_mixer_oss_build_input(struct snd_mixer_oss *mixer, struct snd_mix if (kctl->info(kctl, uinfo)) { up_read(&mixer->card->controls_rwsem); + kfree(uinfo); return 0; } strcpy(str, ptr->name); @@ -1061,6 +1062,7 @@ static int snd_mixer_oss_build_input(struct snd_mixer_oss *mixer, struct snd_mix uinfo->value.enumerated.item = slot.capture_item; if (kctl->info(kctl, uinfo)) { up_read(&mixer->card->controls_rwsem); + kfree(uinfo); return 0; } if (!strcmp(uinfo->value.enumerated.name, str)) { -- cgit v1.1 From 4266274836e81575ee82498d84f4bd08ab7a7378 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Tue, 4 Sep 2012 11:21:45 +0200 Subject: ALSA: remove the main version information Remove the main ALSA version number from the kernel ALSA driver. The ALSA driver package release diverges from the upstream. This may confuse users to see the same ALSA version for many kernel releases and this version lost it's original purpose and connection. The "ioctl" APIs have own version numbers, so the user space may check for specific API changes only. Signed-off-by: Jaroslav Kysela --- sound/core/info.c | 7 +++---- sound/core/info_oss.c | 3 +-- sound/core/sound.c | 3 +-- 3 files changed, 5 insertions(+), 8 deletions(-) (limited to 'sound/core') diff --git a/sound/core/info.c b/sound/core/info.c index c1e611c..6b368d2 100644 --- a/sound/core/info.c +++ b/sound/core/info.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include #include @@ -986,9 +986,8 @@ static struct snd_info_entry *snd_info_version_entry; static void snd_info_version_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { snd_iprintf(buffer, - "Advanced Linux Sound Architecture Driver Version " - CONFIG_SND_VERSION CONFIG_SND_DATE ".\n" - ); + "Advanced Linux Sound Architecture Driver Version k%s.\n", + init_utsname()->release); } static int __init snd_info_version_init(void) diff --git a/sound/core/info_oss.c b/sound/core/info_oss.c index cf42ab5..83c29db 100644 --- a/sound/core/info_oss.c +++ b/sound/core/info_oss.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include @@ -94,7 +93,7 @@ static int snd_sndstat_show_strings(struct snd_info_buffer *buf, char *id, int d static void snd_sndstat_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { - snd_iprintf(buffer, "Sound Driver:3.8.1a-980706 (ALSA v" CONFIG_SND_VERSION " emulation code)\n"); + snd_iprintf(buffer, "Sound Driver:3.8.1a-980706 (ALSA emulation code)\n"); snd_iprintf(buffer, "Kernel: %s %s %s %s %s\n", init_utsname()->sysname, init_utsname()->nodename, diff --git a/sound/core/sound.c b/sound/core/sound.c index 28f3559..6439760 100644 --- a/sound/core/sound.c +++ b/sound/core/sound.c @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -468,7 +467,7 @@ static int __init alsa_sound_init(void) } snd_info_minor_register(); #ifndef MODULE - printk(KERN_INFO "Advanced Linux Sound Architecture Driver Version " CONFIG_SND_VERSION CONFIG_SND_DATE ".\n"); + printk(KERN_INFO "Advanced Linux Sound Architecture Driver Initialized.\n"); #endif return 0; } -- cgit v1.1 From 2d3391ec0ecca37efb6bc995906292f47522b471 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 27 Jul 2012 18:27:00 +0200 Subject: ALSA: PCM: channel mapping API implementation This patch implements the basic data types for the standard channel mapping API handling. - The definitions of the channel positions and the new TLV types are added in sound/asound.h and sound/tlv.h, so that they can be referred from user-space. - Introduced a new helper function snd_pcm_add_chmap_ctls() to create control elements representing the channel maps for each PCM (sub)stream. - Some standard pre-defined channel maps are provided for convenience. Signed-off-by: Takashi Iwai --- sound/core/pcm.c | 4 + sound/core/pcm_lib.c | 215 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 219 insertions(+) (limited to 'sound/core') diff --git a/sound/core/pcm.c b/sound/core/pcm.c index 1a3070b..f299194 100644 --- a/sound/core/pcm.c +++ b/sound/core/pcm.c @@ -1105,6 +1105,10 @@ static int snd_pcm_dev_disconnect(struct snd_device *device) break; } snd_unregister_device(devtype, pcm->card, pcm->device); + if (pcm->streams[cidx].chmap_kctl) { + snd_ctl_remove(pcm->card, pcm->streams[cidx].chmap_kctl); + pcm->streams[cidx].chmap_kctl = NULL; + } } unlock: mutex_unlock(®ister_mutex); diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c index 7ae6719..5651027 100644 --- a/sound/core/pcm_lib.c +++ b/sound/core/pcm_lib.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -2302,3 +2303,217 @@ snd_pcm_sframes_t snd_pcm_lib_readv(struct snd_pcm_substream *substream, } EXPORT_SYMBOL(snd_pcm_lib_readv); + +/* + * standard channel mapping helpers + */ + +/* default channel maps for multi-channel playbacks, up to 8 channels */ +const struct snd_pcm_chmap_elem snd_pcm_std_chmaps[] = { + { .channels = 1, + .map = { SNDRV_CHMAP_FC } }, + { .channels = 2, + .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR } }, + { .channels = 4, + .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, + SNDRV_CHMAP_RL, SNDRV_CHMAP_RR } }, + { .channels = 6, + .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, + SNDRV_CHMAP_RL, SNDRV_CHMAP_RR, + SNDRV_CHMAP_FC, SNDRV_CHMAP_LFE } }, + { .channels = 8, + .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, + SNDRV_CHMAP_RL, SNDRV_CHMAP_RR, + SNDRV_CHMAP_FC, SNDRV_CHMAP_LFE, + SNDRV_CHMAP_SL, SNDRV_CHMAP_SR } }, + { } +}; +EXPORT_SYMBOL_GPL(snd_pcm_std_chmaps); + +/* alternative channel maps with CLFE <-> surround swapped for 6/8 channels */ +const struct snd_pcm_chmap_elem snd_pcm_alt_chmaps[] = { + { .channels = 1, + .map = { SNDRV_CHMAP_FC } }, + { .channels = 2, + .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR } }, + { .channels = 4, + .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, + SNDRV_CHMAP_RL, SNDRV_CHMAP_RR } }, + { .channels = 6, + .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, + SNDRV_CHMAP_FC, SNDRV_CHMAP_LFE, + SNDRV_CHMAP_RL, SNDRV_CHMAP_RR } }, + { .channels = 8, + .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, + SNDRV_CHMAP_FC, SNDRV_CHMAP_LFE, + SNDRV_CHMAP_RL, SNDRV_CHMAP_RR, + SNDRV_CHMAP_SL, SNDRV_CHMAP_SR } }, + { } +}; +EXPORT_SYMBOL_GPL(snd_pcm_alt_chmaps); + +static bool valid_chmap_channels(const struct snd_pcm_chmap *info, int ch) +{ + if (ch > info->max_channels) + return false; + return !info->channel_mask || (info->channel_mask & (1U << ch)); +} + +static int pcm_chmap_ctl_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) +{ + struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol); + + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; + uinfo->count = 0; + uinfo->count = info->max_channels; + uinfo->value.integer.min = 0; + uinfo->value.integer.max = SNDRV_CHMAP_LAST; + return 0; +} + +/* get callback for channel map ctl element + * stores the channel position firstly matching with the current channels + */ +static int pcm_chmap_ctl_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol); + unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); + struct snd_pcm_substream *substream; + const struct snd_pcm_chmap_elem *map; + + if (snd_BUG_ON(!info->chmap)) + return -EINVAL; + substream = snd_pcm_chmap_substream(info, idx); + if (!substream) + return -ENODEV; + memset(ucontrol->value.integer.value, 0, + sizeof(ucontrol->value.integer.value)); + if (!substream->runtime) + return 0; /* no channels set */ + for (map = info->chmap; map->channels; map++) { + int i; + if (map->channels == substream->runtime->channels && + valid_chmap_channels(info, map->channels)) { + for (i = 0; i < map->channels; i++) + ucontrol->value.integer.value[i] = map->map[i]; + return 0; + } + } + return -EINVAL; +} + +/* tlv callback for channel map ctl element + * expands the pre-defined channel maps in a form of TLV + */ +static int pcm_chmap_ctl_tlv(struct snd_kcontrol *kcontrol, int op_flag, + unsigned int size, unsigned int __user *tlv) +{ + struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol); + const struct snd_pcm_chmap_elem *map; + unsigned int __user *dst; + int c, count = 0; + + if (snd_BUG_ON(!info->chmap)) + return -EINVAL; + if (size < 8) + return -ENOMEM; + if (put_user(SNDRV_CTL_TLVT_CONTAINER, tlv)) + return -EFAULT; + size -= 8; + dst = tlv + 2; + for (map = info->chmap; map->channels; map++) { + int chs_bytes = map->channels * 4; + if (!valid_chmap_channels(info, map->channels)) + continue; + if (size < 8) + return -ENOMEM; + if (put_user(SNDRV_CTL_TLVT_CHMAP_FIXED, dst) || + put_user(chs_bytes, dst + 1)) + return -EFAULT; + dst += 2; + size -= 8; + count += 8; + if (size < chs_bytes) + return -ENOMEM; + size -= chs_bytes; + count += chs_bytes; + for (c = 0; c < map->channels; c++) { + if (put_user(map->map[c], dst)) + return -EFAULT; + dst++; + } + } + if (put_user(count, tlv + 1)) + return -EFAULT; + return 0; +} + +static void pcm_chmap_ctl_private_free(struct snd_kcontrol *kcontrol) +{ + struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol); + info->pcm->streams[info->stream].chmap_kctl = NULL; + kfree(info); +} + +/** + * snd_pcm_add_chmap_ctls - create channel-mapping control elements + * @pcm: the assigned PCM instance + * @stream: stream direction + * @chmap: channel map elements (for query) + * @max_channels: the max number of channels for the stream + * @private_value: the value passed to each kcontrol's private_value field + * @info_ret: store struct snd_pcm_chmap instance if non-NULL + * + * Create channel-mapping control elements assigned to the given PCM stream(s). + * Returns zero if succeed, or a negative error value. + */ +int snd_pcm_add_chmap_ctls(struct snd_pcm *pcm, int stream, + const struct snd_pcm_chmap_elem *chmap, + int max_channels, + unsigned long private_value, + struct snd_pcm_chmap **info_ret) +{ + struct snd_pcm_chmap *info; + struct snd_kcontrol_new knew = { + .iface = SNDRV_CTL_ELEM_IFACE_PCM, + .access = SNDRV_CTL_ELEM_ACCESS_READ | + SNDRV_CTL_ELEM_ACCESS_VOLATILE | /* no notification */ + SNDRV_CTL_ELEM_ACCESS_TLV_READ | + SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, + .info = pcm_chmap_ctl_info, + .get = pcm_chmap_ctl_get, + .tlv.c = pcm_chmap_ctl_tlv, + }; + int err; + + info = kzalloc(sizeof(*info), GFP_KERNEL); + if (!info) + return -ENOMEM; + info->pcm = pcm; + info->stream = stream; + info->chmap = chmap; + info->max_channels = max_channels; + if (stream == SNDRV_PCM_STREAM_PLAYBACK) + knew.name = "Playback Channel Map"; + else + knew.name = "Capture Channel Map"; + knew.device = pcm->device; + knew.count = pcm->streams[stream].substream_count; + knew.private_value = private_value; + info->kctl = snd_ctl_new1(&knew, info); + if (!info->kctl) { + kfree(info); + return -ENOMEM; + } + info->kctl->private_free = pcm_chmap_ctl_private_free; + err = snd_ctl_add(pcm->card, info->kctl); + if (err < 0) + return err; + pcm->streams[stream].chmap_kctl = info->kctl; + if (info_ret) + *info_ret = info; + return 0; +} +EXPORT_SYMBOL_GPL(snd_pcm_add_chmap_ctls); -- cgit v1.1 From a8d372f171db9b90a64778fbcd9237c9bc256e06 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Mon, 30 Jul 2012 13:47:07 +0200 Subject: ALSA: control: Fix missing VOLATILE flag at creating controls The SNDRV_CTL_ELEM_ACCESS_VOLATILE bit flag wasn't properly inherited at creating control elements via snd_ctl_new1(). Signed-off-by: Takashi Iwai --- sound/core/control.c | 1 + 1 file changed, 1 insertion(+) (limited to 'sound/core') diff --git a/sound/core/control.c b/sound/core/control.c index 2487a6b..7e86a5b 100644 --- a/sound/core/control.c +++ b/sound/core/control.c @@ -246,6 +246,7 @@ struct snd_kcontrol *snd_ctl_new1(const struct snd_kcontrol_new *ncontrol, kctl.count = ncontrol->count ? ncontrol->count : 1; access = ncontrol->access == 0 ? SNDRV_CTL_ELEM_ACCESS_READWRITE : (ncontrol->access & (SNDRV_CTL_ELEM_ACCESS_READWRITE| + SNDRV_CTL_ELEM_ACCESS_VOLATILE| SNDRV_CTL_ELEM_ACCESS_INACTIVE| SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE| SNDRV_CTL_ELEM_ACCESS_TLV_COMMAND| -- cgit v1.1 From 6e67683d718c627aa585a82ae0eb44a7058eae5a Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 21 Aug 2012 14:49:47 +0200 Subject: ALSA: Remove VOLATILE flag from chmap ctls The VOLATILE flag was added to control elements by snd_pcm_add_chmap_ctls() just because I didn't want to have a side-effect of "alsactl restore". But now the set operation doesn't allow to change the value unless the PCM stream is in PREAPRED state, there is no reason to keep this flag. Let's rip it off. Signed-off-by: Takashi Iwai --- sound/core/pcm_lib.c | 1 - 1 file changed, 1 deletion(-) (limited to 'sound/core') diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c index 5651027..0a750ec 100644 --- a/sound/core/pcm_lib.c +++ b/sound/core/pcm_lib.c @@ -2479,7 +2479,6 @@ int snd_pcm_add_chmap_ctls(struct snd_pcm *pcm, int stream, struct snd_kcontrol_new knew = { .iface = SNDRV_CTL_ELEM_IFACE_PCM, .access = SNDRV_CTL_ELEM_ACCESS_READ | - SNDRV_CTL_ELEM_ACCESS_VOLATILE | /* no notification */ SNDRV_CTL_ELEM_ACCESS_TLV_READ | SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, .info = pcm_chmap_ctl_info, -- cgit v1.1 From 2dc6fbf0078e8148b571f1bbec704ca5c8e2ec2c Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 11 Sep 2012 14:24:43 +0200 Subject: ALSA: pcm - Use UNKNOWN chmap for mono streams In general, mono streams have no dedicated speaker assignment, thus they should be rather marked as UNKNOWN position. Signed-off-by: Takashi Iwai --- sound/core/pcm_lib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sound/core') diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c index 0a750ec..9647a22 100644 --- a/sound/core/pcm_lib.c +++ b/sound/core/pcm_lib.c @@ -2311,7 +2311,7 @@ EXPORT_SYMBOL(snd_pcm_lib_readv); /* default channel maps for multi-channel playbacks, up to 8 channels */ const struct snd_pcm_chmap_elem snd_pcm_std_chmaps[] = { { .channels = 1, - .map = { SNDRV_CHMAP_FC } }, + .map = { SNDRV_CHMAP_UNKNOWN } }, { .channels = 2, .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR } }, { .channels = 4, @@ -2333,7 +2333,7 @@ EXPORT_SYMBOL_GPL(snd_pcm_std_chmaps); /* alternative channel maps with CLFE <-> surround swapped for 6/8 channels */ const struct snd_pcm_chmap_elem snd_pcm_alt_chmaps[] = { { .channels = 1, - .map = { SNDRV_CHMAP_FC } }, + .map = { SNDRV_CHMAP_UNKNOWN } }, { .channels = 2, .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR } }, { .channels = 4, -- cgit v1.1 From 5efbc2610a7b2aac6c51f8fc943c019106568939 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 13 Sep 2012 14:48:46 +0200 Subject: ALSA: Fix leftover chmap UNKNOWN -> MONO conversions A few files have been slipped from the previous commit to add MONO channel type. Signed-off-by: Takashi Iwai --- sound/core/pcm_lib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sound/core') diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c index 9647a22..f42c10a 100644 --- a/sound/core/pcm_lib.c +++ b/sound/core/pcm_lib.c @@ -2311,7 +2311,7 @@ EXPORT_SYMBOL(snd_pcm_lib_readv); /* default channel maps for multi-channel playbacks, up to 8 channels */ const struct snd_pcm_chmap_elem snd_pcm_std_chmaps[] = { { .channels = 1, - .map = { SNDRV_CHMAP_UNKNOWN } }, + .map = { SNDRV_CHMAP_MONO } }, { .channels = 2, .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR } }, { .channels = 4, @@ -2333,7 +2333,7 @@ EXPORT_SYMBOL_GPL(snd_pcm_std_chmaps); /* alternative channel maps with CLFE <-> surround swapped for 6/8 channels */ const struct snd_pcm_chmap_elem snd_pcm_alt_chmaps[] = { { .channels = 1, - .map = { SNDRV_CHMAP_UNKNOWN } }, + .map = { SNDRV_CHMAP_MONO } }, { .channels = 2, .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR } }, { .channels = 4, -- cgit v1.1 From b35cc8225845112a616e3a2266d2fde5ab13d3ab Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Wed, 5 Sep 2012 15:32:18 +0300 Subject: ALSA: compress_core: integer overflow in snd_compr_allocate_buffer() These are 32 bit values that come from the user, we need to check for integer overflows or we could end up allocating a smaller buffer than expected. Signed-off-by: Dan Carpenter Signed-off-by: Takashi Iwai --- sound/core/compress_offload.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'sound/core') diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c index eb60cb8..68fe02c 100644 --- a/sound/core/compress_offload.c +++ b/sound/core/compress_offload.c @@ -407,6 +407,10 @@ static int snd_compr_allocate_buffer(struct snd_compr_stream *stream, unsigned int buffer_size; void *buffer; + if (params->buffer.fragment_size == 0 || + params->buffer.fragments > SIZE_MAX / params->buffer.fragment_size) + return -EINVAL; + buffer_size = params->buffer.fragment_size * params->buffer.fragments; if (stream->ops->copy) { buffer = NULL; -- cgit v1.1 From 4dc040a0b34890d2adc0d63da6e9bfb4eb791b19 Mon Sep 17 00:00:00 2001 From: Vinod Koul Date: Mon, 17 Sep 2012 11:51:25 +0530 Subject: ALSA: compress - move the buffer check Commit ALSA: compress_core: integer overflow in snd_compr_allocate_buffer() added a new error check for input params. this add new routine for input checks and moves buffer overflow check to this new routine. This allows the error value to be propogated to user space Signed-off-by: Vinod Koul Signed-off-by: Takashi Iwai --- sound/core/compress_offload.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'sound/core') diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c index 68fe02c..bd7f28e 100644 --- a/sound/core/compress_offload.c +++ b/sound/core/compress_offload.c @@ -407,10 +407,6 @@ static int snd_compr_allocate_buffer(struct snd_compr_stream *stream, unsigned int buffer_size; void *buffer; - if (params->buffer.fragment_size == 0 || - params->buffer.fragments > SIZE_MAX / params->buffer.fragment_size) - return -EINVAL; - buffer_size = params->buffer.fragment_size * params->buffer.fragments; if (stream->ops->copy) { buffer = NULL; @@ -429,6 +425,16 @@ static int snd_compr_allocate_buffer(struct snd_compr_stream *stream, return 0; } +static int snd_compress_check_input(struct snd_compr_params *params) +{ + /* first let's check the buffer parameter's */ + if (params->buffer.fragment_size == 0 || + params->buffer.fragments > SIZE_MAX / params->buffer.fragment_size) + return -EINVAL; + + return 0; +} + static int snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg) { @@ -447,11 +453,17 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg) retval = -EFAULT; goto out; } + + retval = snd_compress_check_input(params); + if (retval) + goto out; + retval = snd_compr_allocate_buffer(stream, params); if (retval) { retval = -ENOMEM; goto out; } + retval = stream->ops->set_params(stream, params); if (retval) goto out; -- cgit v1.1 From fb4a9779f1267539292268d7363e17180eb4ee5c Mon Sep 17 00:00:00 2001 From: Vinod Koul Date: Mon, 17 Sep 2012 11:51:26 +0530 Subject: ALSA: Compress - add codec parameter checks Signed-off-by: Vinod Koul Signed-off-by: Takashi Iwai --- sound/core/compress_offload.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'sound/core') diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c index bd7f28e..c40ae57 100644 --- a/sound/core/compress_offload.c +++ b/sound/core/compress_offload.c @@ -432,6 +432,16 @@ static int snd_compress_check_input(struct snd_compr_params *params) params->buffer.fragments > SIZE_MAX / params->buffer.fragment_size) return -EINVAL; + /* now codec parameters */ + if (params->codec.id == 0 || params->codec.id > SND_AUDIOCODEC_MAX) + return -EINVAL; + + if (params->codec.ch_in == 0 || params->codec.ch_out == 0) + return -EINVAL; + + if (!(params->codec.sample_rate & SNDRV_PCM_RATE_8000_192000)) + return -EINVAL; + return 0; } -- cgit v1.1 From 9d069dc00b02b886abe3cab5e369140f7cd78965 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 20 Sep 2012 20:29:12 -0700 Subject: ALSA: Make snd_sgbuf_get_{ptr|addr}() available for non-SG cases Passing struct snd_dma_buffer pointer instead, so that they work no matter whether real SG buffer is used or not. This is a preliminary work for the HD-audio DSP loader code. Signed-off-by: Ian Minett Signed-off-by: Takashi Iwai --- sound/core/pcm_memory.c | 26 -------------------------- sound/core/sgbuf.c | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 26 deletions(-) (limited to 'sound/core') diff --git a/sound/core/pcm_memory.c b/sound/core/pcm_memory.c index 9571313..69e01c4 100644 --- a/sound/core/pcm_memory.c +++ b/sound/core/pcm_memory.c @@ -327,32 +327,6 @@ struct page *snd_pcm_sgbuf_ops_page(struct snd_pcm_substream *substream, unsigne } EXPORT_SYMBOL(snd_pcm_sgbuf_ops_page); - -/* - * compute the max chunk size with continuous pages on sg-buffer - */ -unsigned int snd_pcm_sgbuf_get_chunk_size(struct snd_pcm_substream *substream, - unsigned int ofs, unsigned int size) -{ - struct snd_sg_buf *sg = snd_pcm_substream_sgbuf(substream); - unsigned int start, end, pg; - - start = ofs >> PAGE_SHIFT; - end = (ofs + size - 1) >> PAGE_SHIFT; - /* check page continuity */ - pg = sg->table[start].addr >> PAGE_SHIFT; - for (;;) { - start++; - if (start > end) - break; - pg++; - if ((sg->table[start].addr >> PAGE_SHIFT) != pg) - return (start << PAGE_SHIFT) - ofs; - } - /* ok, all on continuous pages */ - return size; -} -EXPORT_SYMBOL(snd_pcm_sgbuf_get_chunk_size); #endif /* CONFIG_SND_DMA_SGBUF */ /** diff --git a/sound/core/sgbuf.c b/sound/core/sgbuf.c index d0f0035..0a41850 100644 --- a/sound/core/sgbuf.c +++ b/sound/core/sgbuf.c @@ -22,6 +22,7 @@ #include #include #include +#include #include @@ -136,3 +137,29 @@ void *snd_malloc_sgbuf_pages(struct device *device, snd_free_sgbuf_pages(dmab); /* free the table */ return NULL; } + +/* + * compute the max chunk size with continuous pages on sg-buffer + */ +unsigned int snd_sgbuf_get_chunk_size(struct snd_dma_buffer *dmab, + unsigned int ofs, unsigned int size) +{ + struct snd_sg_buf *sg = dmab->private_data; + unsigned int start, end, pg; + + start = ofs >> PAGE_SHIFT; + end = (ofs + size - 1) >> PAGE_SHIFT; + /* check page continuity */ + pg = sg->table[start].addr >> PAGE_SHIFT; + for (;;) { + start++; + if (start > end) + break; + pg++; + if ((sg->table[start].addr >> PAGE_SHIFT) != pg) + return (start << PAGE_SHIFT) - ofs; + } + /* ok, all on continuous pages */ + return size; +} +EXPORT_SYMBOL(snd_sgbuf_get_chunk_size); -- cgit v1.1