summaryrefslogtreecommitdiffstats
path: root/sound/core/control.c
Commit message (Collapse)AuthorAgeFilesLines
* ALSA: snd_ctl_activate_id(): Fix index look-upLars-Peter Clausen2014-11-071-1/+1
| | | | | | | | We want to know the offset for the id that was passed to the function, not the offset of the first id of the control (which is always 0). Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
* ALSA: control: Add missing kerneldoc comments to exported functionsTakashi Iwai2014-10-301-15/+49
| | | | | | | | A few functions have no proper documentation yet, so let's add them. Along with it, remove superfluous blank line between the closing brace and EXPORT_SYMBOL() line. Signed-off-by: Takashi Iwai <tiwai@suse.de>
* ALSA: control: Allow to pass items zero to snd_ctl_enum_info()Takashi Iwai2014-10-201-0/+2
| | | | | | | | | Although this is weird, some drivers want to allow empty control elements intentionally, e.g. the number of items may change depending on the firmware status. Let the function simply returning in such a case. Signed-off-by: Takashi Iwai <tiwai@suse.de>
* ALSA: control: Warn if too long string is passed to snd_ctl_enum_info()Takashi Iwai2014-10-201-0/+3
| | | | | | This allows us to catch the bugs in drivers easily. Signed-off-by: Takashi Iwai <tiwai@suse.de>
* ALSA: control: Define SNDRV_CTL_TLV_OP_* constantsTakashi Iwai2014-07-151-3/+3
| | | | | | | Instead of hard-coded magic numbers, define constants for op_flag to tlv callbacks. Signed-off-by: Takashi Iwai <tiwai@suse.de>
* ALSA: control: Make sure that id->index does not overflowLars-Peter Clausen2014-06-181-0/+3
| | | | | | | | | | | | | | The ALSA control code expects that the range of assigned indices to a control is continuous and does not overflow. Currently there are no checks to enforce this. If a control with a overflowing index range is created that control becomes effectively inaccessible and unremovable since snd_ctl_find_id() will not be able to find it. This patch adds a check that makes sure that controls with a overflowing index range can not be created. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Acked-by: Jaroslav Kysela <perex@perex.cz> Cc: <stable@vger.kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
* ALSA: control: Handle numid overflowLars-Peter Clausen2014-06-181-0/+4
| | | | | | | | | | | | | | | | Each control gets automatically assigned its numids when the control is created. The allocation is done by incrementing the numid by the amount of allocated numids per allocation. This means that excessive creation and destruction of controls (e.g. via SNDRV_CTL_IOCTL_ELEM_ADD/REMOVE) can cause the id to eventually overflow. Currently when this happens for the control that caused the overflow kctl->id.numid + kctl->count will also over flow causing it to be smaller than kctl->id.numid. Most of the code assumes that this is something that can not happen, so we need to make sure that it won't happen Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Acked-by: Jaroslav Kysela <perex@perex.cz> Cc: <stable@vger.kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
* ALSA: control: Don't access controls outside of protected regionsLars-Peter Clausen2014-06-181-5/+10
| | | | | | | | | | | A control that is visible on the card->controls list can be freed at any time. This means we must not access any of its memory while not holding the controls_rw_lock. Otherwise we risk a use after free access. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Acked-by: Jaroslav Kysela <perex@perex.cz> Cc: <stable@vger.kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
* ALSA: control: Fix replacing user controlsLars-Peter Clausen2014-06-181-16/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are two issues with the current implementation for replacing user controls. The first is that the code does not check if the control is actually a user control and neither does it check if the control is owned by the process that tries to remove it. That allows userspace applications to remove arbitrary controls, which can cause a user after free if a for example a driver does not expect a control to be removed from under its feed. The second issue is that on one hand when a control is replaced the user_ctl_count limit is not checked and on the other hand the user_ctl_count is increased (even though the number of user controls does not change). This allows userspace, once the user_ctl_count limit as been reached, to repeatedly replace a control until user_ctl_count overflows. Once that happens new controls can be added effectively bypassing the user_ctl_count limit. Both issues can be fixed by instead of open-coding the removal of the control that is to be replaced to use snd_ctl_remove_user_ctl(). This function does proper permission checks as well as decrements user_ctl_count after the control has been removed. Note that by using snd_ctl_remove_user_ctl() the check which returns -EBUSY at beginning of the function if the control already exists is removed. This is not a problem though since the check is quite useless, because the lock that is protecting the control list is released between the check and before adding the new control to the list, which means that it is possible that a different control with the same settings is added to the list after the check. Luckily there is another check that is done while holding the lock in snd_ctl_add(), so we'll rely on that to make sure that the same control is not added twice. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Acked-by: Jaroslav Kysela <perex@perex.cz> Cc: <stable@vger.kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
* ALSA: control: Protect user controls against concurrent accessLars-Peter Clausen2014-06-181-6/+25
| | | | | | | | | | | | | | | The user-control put and get handlers as well as the tlv do not protect against concurrent access from multiple threads. Since the state of the control is not updated atomically it is possible that either two write operations or a write and a read operation race against each other. Both can lead to arbitrary memory disclosure. This patch introduces a new lock that protects user-controls from concurrent access. Since applications typically access controls sequentially than in parallel a single lock per card should be fine. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Acked-by: Jaroslav Kysela <perex@perex.cz> Cc: <stable@vger.kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
* ALSA: control: Use standard printk helpersTakashi Iwai2014-02-141-8/+7
| | | | | | | Use dev_err() & co as much as possible. If not available (no device assigned at the calling point), use pr_xxx() helpers instead. Signed-off-by: Takashi Iwai <tiwai@suse.de>
* ALSA: Replace with IS_ENABLED()Takashi Iwai2014-02-101-1/+1
| | | | | | | | | | | | Replace the lengthy #if defined(XXX) || defined(XXX_MODULE) with the new IS_ENABLED() macro. The patch still doesn't cover all ifdefs. For example, the dependency on CONFIG_GAMEPORT is still open-coded because this also has an extra dependency on MODULE. Similarly, an open-coded ifdef in pcm_oss.c and some sequencer-related stuff are left untouched. Signed-off-by: Takashi Iwai <tiwai@suse.de>
* ALSA: add/change some comments describing function return valuesYacine Belkadi2013-03-121-18/+23
| | | | | | | | | | | | | | | | | | | script/kernel-doc reports the following type of warnings (when run in verbose mode): Warning(sound/core/init.c:152): No description found for return value of 'snd_card_create' To fix that: - add missing descriptions of function return values - use "Return:" sections to describe those return values Along the way: - complete some descriptions - fix some typos Signed-off-by: Yacine Belkadi <yacine.belkadi.1@gmail.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
* ALSA: Avoid endless sleep after disconnectTakashi Iwai2012-10-301-0/+2
| | | | | | | | | When disconnect callback is called, each component should wake up sleepers and check card->shutdown flag for avoiding the endless sleep blocking the proper resource release. Cc: <stable@vger.kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
* ALSA: Add a reference counter to card instanceTakashi Iwai2012-10-301-0/+3
| | | | | | | | | | | | | For more strict protection for wild disconnections, a refcount is introduced to the card instance, and let it up/down when an object is referred via snd_lookup_*() in the open ops. The free-after-last-close check is also changed to check this refcount instead of the empty list, too. Reported-by: Matthieu CASTET <matthieu.castet@parrot.com> Cc: <stable@vger.kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
* ALSA: control: Fix missing VOLATILE flag at creating controlsTakashi Iwai2012-09-061-0/+1
| | | | | | | 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 <tiwai@suse.de>
* ALSA: control - Fixe a trailing white space errorJeffrin Jose2012-03-131-1/+1
| | | | | | | | Fixed a trailing white space error detected in sound/core/control.c by checkpatch.pl script. Signed-off-by: Jeffrin Jose <ahiliation@yahoo.co.in> Signed-off-by: Takashi Iwai <tiwai@suse.de>
* Merge branch 'modsplit-Oct31_2011' of ↵Linus Torvalds2011-11-061-0/+1
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | git://git.kernel.org/pub/scm/linux/kernel/git/paulg/linux * 'modsplit-Oct31_2011' of git://git.kernel.org/pub/scm/linux/kernel/git/paulg/linux: (230 commits) Revert "tracing: Include module.h in define_trace.h" irq: don't put module.h into irq.h for tracking irqgen modules. bluetooth: macroize two small inlines to avoid module.h ip_vs.h: fix implicit use of module_get/module_put from module.h nf_conntrack.h: fix up fallout from implicit moduleparam.h presence include: replace linux/module.h with "struct module" wherever possible include: convert various register fcns to macros to avoid include chaining crypto.h: remove unused crypto_tfm_alg_modname() inline uwb.h: fix implicit use of asm/page.h for PAGE_SIZE pm_runtime.h: explicitly requires notifier.h linux/dmaengine.h: fix implicit use of bitmap.h and asm/page.h miscdevice.h: fix up implicit use of lists and types stop_machine.h: fix implicit use of smp.h for smp_processor_id of: fix implicit use of errno.h in include/linux/of.h of_platform.h: delete needless include <linux/module.h> acpi: remove module.h include from platform/aclinux.h miscdevice.h: delete unnecessary inclusion of module.h device_cgroup.h: delete needless include <linux/module.h> net: sch_generic remove redundant use of <linux/module.h> net: inet_timewait_sock doesnt need <linux/module.h> ... Fix up trivial conflicts (other header files, and removal of the ab3550 mfd driver) in - drivers/media/dvb/frontends/dibx000_common.c - drivers/media/video/{mt9m111.c,ov6650.c} - drivers/mfd/ab3550-core.c - include/linux/dmaengine.h
| * sound: Add module.h to the previously silent sound usersPaul Gortmaker2011-10-311-0/+1
| | | | | | | | | | | | | | | | Lots of sound drivers were getting module.h via the implicit presence of it in <linux/device.h> but we are going to clean that up. So fix up those users now. Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
* | ALSA: control: remove compilation warning on 32-bitOlof Johansson2011-11-061-2/+2
|/ | | | | | | | | | | | | | | This was introduced by 'ALSA: control: add support for ENUMERATED user space controls' which adds a u64 variable that gets cast to a pointer: sound/core/control.c: In function 'snd_ctl_elem_init_enum_names': sound/core/control.c:1089: warning: cast to pointer from integer of different size Cast to uintptr_t before casting to pointer to avoid the warning. Signed-off-by: Olof Johansson <olof@lixom.net> [cl: replace long with uintptr_t] Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
* ALSA: control: add support for ENUMERATED user space controlsClemens Ladisch2011-10-091-4/+76
| | | | | | | | | Handling of user control elements was implemented for all types except ENUMERATED. This type will be needed for the device-specific mixers of upcoming FireWire drivers. Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
* ALSA: core: release the constraint check for replace opsLu Guanqun2011-08-241-1/+1
| | | | | | | | Suppose the ALSA card already has a number of MAX_USER_CONTROLS controls, and the user wants to replace one, it should not fail at this condition check. Signed-off-by: Lu Guanqun <guanqun.lu@intel.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
* ALSA: core: trivial code style fixLu Guanqun2011-08-241-1/+1
| | | | | | | remove trailing tab on the line. Signed-off-by: Lu Guanqun <guanqun.lu@intel.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
* ALSA: core: remove unused variables.Luca Tettamanti2011-05-261-2/+1
| | | | | | | Drop a few variables that are never read. Signed-off-by: Luca Tettamanti <kronos.it@gmail.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
* ALSA: Add snd_ctl_replace() to dynamically replace a controlDimitris Papastamos2011-03-221-0/+64
| | | | | | | | | | | | Add a function to dynamically replace a given control. If the control does not already exist, a third parameter is used to determine whether to actually add that control. This is useful in cases where downloadable firmware at runtime can add or replace existing controls. A separate patch needs to be made to allow ALSA Mixer to render the replaced controls on the fly. Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
* Merge branch 'topic/misc' into for-linusTakashi Iwai2011-03-181-12/+10
|\
| * ALSA: control: clean up snd_ctl_hole_check()Clemens Ladisch2011-03-081-9/+9
| | | | | | | | | | | | | | | | | | | | The return value of snd_ctl_hole_check() is used only to detect whether to continue the loop in snd_ctl_find_hole() or not, so we can simplify the code by changing this return type to a boolean. Also rename this function to better show what it actually does. Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
| * ALSA: control: fix numid conflict check for new controlsClemens Ladisch2011-03-081-4/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The purpose of the snd_ctl_hole_check() function is to find conflicts between the numerical IDs of the new control and those of any existing controls. However, it would fail to detect an existing control whose count is smaller than the new control's count and whose interval of IDs is entirely contained in the interval of the new control's IDs. To fix this, use the correct formula to detect overlapping intervals, which happens to simplify the condition. This problem was not encountered so far because ALSA does not yet allow drivers to allocate specific control IDs. Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
* | ALSA: Add snd_ctl_activate_id()Takashi Iwai2011-03-111-0/+46
|/ | | | | | | | Added a new API function snd_ctl_activate_id() for activate / inactivate the control element dynamically. Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
* ALSA: core, oxygen, virtuoso: add an enum control info helperClemens Ladisch2011-01-101-1/+27
| | | | | | | | Introduce the helper function snd_ctl_enum_info() to fill out the elem_info fields for an enumerated control. Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
* ALSA: prevent heap corruption in snd_ctl_new()Dan Rosenberg2010-09-281-0/+5
| | | | | | | | | | | | | | | | The snd_ctl_new() function in sound/core/control.c allocates space for a snd_kcontrol struct by performing arithmetic operations on a user-provided size without checking for integer overflow. If a user provides a large enough size, an overflow will occur, the allocated chunk will be too small, and a second user-influenced value will be written repeatedly past the bounds of this chunk. This code is reachable by unprivileged users who have permission to open a /dev/snd/controlC* device (on many distros, this is group "audio") via the SNDRV_CTL_IOCTL_ELEM_ADD and SNDRV_CTL_IOCTL_ELEM_REPLACE ioctls. Signed-off-by: Dan Rosenberg <drosenberg@vsecurity.com> Cc: <stable@kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
* ALSA: core - Define llseek fopsTakashi Iwai2010-04-131-0/+5
| | | | | | | | | | | Set no_llseek to llseek file ops of each sound component (but for hwdep). This avoids the implicit BKL invocation via generic_file_llseek() used as default when fops.llseek is NULL. Also call nonseekable_open() at each open ops to ensure the file flags have no seek bit. Signed-off-by: Takashi Iwai <tiwai@suse.de>
* sound: control: fix minimum TLV lengthClemens Ladisch2010-02-011-1/+1
| | | | | | | | Allow TLV blocks that do not have any values; the smallest possible TLV is an empty container or one where the information is only in the tag. Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
* sound: control: actually allow TLV command accessClemens Ladisch2010-02-011-2/+3
| | | | | | | | | Creating a control with TLV_COMMAND access was not possible because snd_ctl_new1() forgot to include it in the mask of allowable access bits. Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
* Merge branch 'topic/misc' into for-linusTakashi Iwai2009-12-041-1/+1
|\
| * ALSA: remove unnecessary null checkDan Carpenter2009-11-181-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | This function is only called from snd_ctl_ioctl() and the file parameter can never be null so there is no need to check it here. We dereference file at the start of the function: struct snd_card *card = file->card; and it confuses static checkers to dereference a pointer before checking it. Signed-off-by: Dan Carpenter <error27@gmail.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
* | control: use reference-counted pidClemens Ladisch2009-11-061-2/+3
| | | | | | | | | | | | | | | | | | | | Instead of storing the PID number, take a reference to the task's pid structure. This protects against duplicates due to PID overflows, and using pid_vnr() ensures that the PID returned by snd_ctl_elem_info() is correct as seen from the current namespace. Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
* | control: remove snd_konctrol_volatile::owner_pid fieldClemens Ladisch2009-11-061-3/+1
|/ | | | | | | | We do not need to save the ID of the process that locked a control because that information is already available in the owner's file data. Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
* sound: snd_ctl_remove_user_ctl: prevent removal of kernel controlsClemens Ladisch2009-08-171-0/+4
| | | | | | | | | Ensure that userspace can remove only user controls. Controls created by kernel drivers must not be removed because they might be referenced in calls to snd_ctl_notify(). Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
* sound: snd_ctl_remove_unlocked_id: simplify user control countingClemens Ladisch2009-08-171-12/+7
| | | | | | | | | | | | | | Move the decrementing of the user controls counter from snd_ctl_elem_remove to snd_ctl_remove_unlocked_id; this saves the separate locking of the controls semaphore, and therefore removes a harmless race. Since the purpose of the function is to operate on user controls (the control being unlocked is just a prerequisite), rename it to snd_ctl_remove_user_ctl. Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
* sound: snd_ctl_remove_unlocked_id: simplify error pathsClemens Ladisch2009-08-171-4/+5
| | | | | | | | Use a common exit path to release the mutex and to return a possible error. Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
* sound: snd_ctl_elem_add: fix value count checkClemens Ladisch2009-08-171-1/+1
| | | | | | | | | | Make sure that no user element that has no values can be added. The check for count>1024 is not needed because the count is checked later for the individual control types. Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
* ALSA: sound/core: use memdup_user()Li Zefan2009-04-141-22/+13
| | | | | | | Remove open-coded memdup_user(). Signed-off-by: Li Zefan <lizf@cn.fujitsu.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
* Rationalize fasync return valuesJonathan Corbet2009-03-161-5/+2
| | | | | | | | | | | | | | | | | | | | Most fasync implementations do something like: return fasync_helper(...); But fasync_helper() will return a positive value at times - a feature used in at least one place. Thus, a number of other drivers do: err = fasync_helper(...); if (err < 0) return err; return 0; In the interests of consistency and more concise code, it makes sense to map positive return values onto zero where ->fasync() is called. Cc: Al Viro <viro@ZenIV.linux.org.uk> Signed-off-by: Jonathan Corbet <corbet@lwn.net>
* saner FASYNC handling on file closeAl Viro2008-11-011-1/+0
| | | | | | | | | | | | | | As it is, all instances of ->release() for files that have ->fasync() need to remember to evict file from fasync lists; forgetting that creates a hole and we actually have a bunch that *does* forget. So let's keep our lives simple - let __fput() check FASYNC in file->f_flags and call ->fasync() there if it's been set. And lose that crap in ->release() instances - leaving it there is still valid, but we don't have to bother anymore. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
* ALSA: Warn when control names are truncatedMark Brown2008-10-291-1/+6
| | | | | | | | This is likely to confuse user interfaces since the end of the control name is interpreted (eg, "Volume", "Switch"). Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
* ALSA: use correct lock in snd_ctl_dev_disconnect()Takashi Iwai2008-09-091-2/+2
| | | | | | | | | The lock used in snd_ctl_dev_disconnect() should be card->ctl_files_rwlock for protection of card->ctl_files entries, instead of card->controls_rwsem. Reported-by: Vegard Nossum <vegard.nossum@gmail.com> Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
* ALSA: Kill snd_assert() in sound/core/*Takashi Iwai2008-08-131-19/+31
| | | | | | | | Kill snd_assert() in sound/core/*, either removed or replaced with if () with snd_BUG_ON(). Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
* ALSA: make snd_ctl_elem_read() and snd_ctl_elem_write() staticTakashi Iwai2008-06-131-3/+4
| | | | | | | | snd_ctl_elem_read() and snd_ctl_elem_write() are no longer used by any other drivers. Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
* [ALSA] Remove sound/driver.hTakashi Iwai2008-01-311-1/+0
| | | | | | | | | | | | This header file exists only for some hacks to adapt alsa-driver tree. It's useless for building in the kernel. Let's move a few lines in it to sound/core.h and remove it. With this patch, sound/driver.h isn't removed but has just a single compile warning to include it. This should be really killed in future. Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
OpenPOWER on IntegriCloud