History log of /linux-master/sound/core/vmaster.c
Revision Date Author Comments
# fb9e197f 21-Feb-2024 Takashi Iwai <tiwai@suse.de>

ALSA: vmaster: Use automatic cleanup of kfree()

There are common patterns where a temporary buffer is allocated and
freed at the exit, and those can be simplified with the recent cleanup
mechanism via __free(kfree).

No functional changes, only code refactoring.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/20240222111509.28390-6-tiwai@suse.de


# ae07eb9b 21-Jul-2023 Takashi Iwai <tiwai@suse.de>

ALSA: vmaster: Add snd_ctl_add_followers() helper

Add a new helper to add multiple vmaster followers in a shot. The
same function was open-coded in various places, and this helper
replaces them.

Link: https://lore.kernel.org/r/20230721071643.3631-2-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>


# 281dee67 12-Jul-2022 Takashi Iwai <tiwai@suse.de>

ALSA: core: Fix missing return value comments for kernel docs

Each kernel doc comment expects the definition of the return value in
a proper format. This patch adds or fixes the missing entries for the
remaining ALSA core API functions.

Link: https://lore.kernel.org/r/20220713104759.4365-8-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>


# 9ab0cb30 17-Jul-2020 Takashi Iwai <tiwai@suse.de>

ALSA: Replace the word "slave" in vmaster API

Follow the recent inclusive terminology guidelines and replace the
word "slave" in vmaster API. I chose the word "follower" at this time
since it seems fitting for the purpose.

Note that the word "master" is kept in API, since it refers rather to
audio master volume control.

Also, while we're at it, a typo in comments is corrected, too.

Link: https://lore.kernel.org/r/20200717154517.27599-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>


# a10e763b 31-May-2019 Thomas Gleixner <tglx@linutronix.de>

treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 372

Based on 1 normalized pattern(s):

this program is free software you can redistribute it and or modify
it under the terms of the gnu general public license as published by
the free software foundation version 2

extracted by the scancode license scanner the SPDX license identifier

GPL-2.0-only

has been chosen to replace the boilerplate/reference in 135 file(s).

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Allison Randal <allison@lohutok.net>
Cc: linux-spdx@vger.kernel.org
Link: https://lkml.kernel.org/r/20190531081036.435762997@linutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# acafe7e3 08-May-2018 Kees Cook <keescook@chromium.org>

treewide: Use struct_size() for kmalloc()-family

One of the more common cases of allocation size calculations is finding
the size of a structure that has a zero-sized array at the end, along
with memory for some number of elements for that array. For example:

struct foo {
int stuff;
void *entry[];
};

instance = kmalloc(sizeof(struct foo) + sizeof(void *) * count, GFP_KERNEL);

Instead of leaving these open-coded and prone to type mistakes, we can
now use the new struct_size() helper:

instance = kmalloc(struct_size(instance, entry, count), GFP_KERNEL);

This patch makes the changes for kmalloc()-family (and kvmalloc()-family)
uses. It was done via automatic conversion with manual review for the
"CHECKME" non-standard cases noted below, using the following Coccinelle
script:

// pkey_cache = kmalloc(sizeof *pkey_cache + tprops->pkey_tbl_len *
// sizeof *pkey_cache->table, GFP_KERNEL);
@@
identifier alloc =~ "kmalloc|kzalloc|kvmalloc|kvzalloc";
expression GFP;
identifier VAR, ELEMENT;
expression COUNT;
@@

- alloc(sizeof(*VAR) + COUNT * sizeof(*VAR->ELEMENT), GFP)
+ alloc(struct_size(VAR, ELEMENT, COUNT), GFP)

// mr = kzalloc(sizeof(*mr) + m * sizeof(mr->map[0]), GFP_KERNEL);
@@
identifier alloc =~ "kmalloc|kzalloc|kvmalloc|kvzalloc";
expression GFP;
identifier VAR, ELEMENT;
expression COUNT;
@@

- alloc(sizeof(*VAR) + COUNT * sizeof(VAR->ELEMENT[0]), GFP)
+ alloc(struct_size(VAR, ELEMENT, COUNT), GFP)

// Same pattern, but can't trivially locate the trailing element name,
// or variable name.
@@
identifier alloc =~ "kmalloc|kzalloc|kvmalloc|kvzalloc";
expression GFP;
expression SOMETHING, COUNT, ELEMENT;
@@

- alloc(sizeof(SOMETHING) + COUNT * sizeof(ELEMENT), GFP)
+ alloc(CHECKME_struct_size(&SOMETHING, ELEMENT, COUNT), GFP)

Signed-off-by: Kees Cook <keescook@chromium.org>


# 841bdb7c 13-May-2018 Takashi Sakamoto <o-takashi@sakamocchi.jp>

ALSA: vmaster: use position offset macro of TLV data

A series of SNDRV_CTL_TLVO_XXX macro was introduced for position offset
of TLV data. This commit applies a code optimization.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>


# 7a33a02f 08-Mar-2018 Takashi Iwai <tiwai@suse.de>

ALSA: vmaster: Zero-clear ctl before calling slave get

Use kzalloc() instead of kmalloc() so that we don't need to rely fully
on the slave get() callback to clear the control value that might be
copied to user-space.

Signed-off-by: Takashi Iwai <tiwai@suse.de>


# 2e2c177c 08-Mar-2018 Takashi Iwai <tiwai@suse.de>

ALSA: vmaster: Propagate slave error

In slave_update() of vmaster code ignores the error from the slave
get() callback and copies the values. It's not only about the missing
error code but also that this may potentially lead to a leak of
uninitialized variables when the slave get() don't clear them.

This patch fixes slave_update() not to copy the potentially
uninitialized values when an error is returned from the slave get()
callback, and to propagate the error value properly.

Signed-off-by: Takashi Iwai <tiwai@suse.de>


# d6c0615f 21-Nov-2017 Takashi Iwai <tiwai@suse.de>

ALSA: hda - Fix yet remaining issue with vmaster 0dB initialization

The previous fix for addressing the breakage in vmaster slave
initialization, commit a91d66129fb9 ("ALSA: hda - Fix incorrect TLV
callback check introduced during set_fs() removal"), introduced a new
helper to process over each slave kctl. However, this helper passes
only the original kctl, not the virtual slave kctl. As a result,
HD-audio driver (which is the only user so far) couldn't initialize
the slave correctly because it's trying to update the value directly
with the original kctl, not with the mapped kctl.

This patch fixes the situation again by passing both the mapped slaved
and original slave kctls to the function. Luckily there is a single
caller as of now, so changing the call signature is no big matter.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=197959
Fixes: a91d66129fb9 ("ALSA: hda - Fix incorrect TLV callback check introduced during set_fs() removal")
Cc: <stable@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>


# a91d6612 16-Oct-2017 Takashi Iwai <tiwai@suse.de>

ALSA: hda - Fix incorrect TLV callback check introduced during set_fs() removal

The commit 99b5c5bb9a54 ("ALSA: hda - Remove the use of set_fs()")
converted the get_kctl_0dB_offset() call for killing set_fs() usage in
HD-audio codec code. The conversion assumed that the TLV callback
used in HD-audio code is only snd_hda_mixer_amp() and applies the TLV
calculation locally.

Although this assumption is correct, and all slave kctls are actually
with that callback, the current code is still utterly buggy; it
doesn't hit this condition and falls back to the next check. It's
because the function gets called after adding slave kctls to vmaster.
By assigning a slave kctl, the slave kctl object is faked inside
vmaster code, and the whole kctl ops are overridden. Thus the
callback op points to a different value from what we've assumed.

More badly, as reported by the KERNEXEC and UDEREF features of PaX,
the code flow turns into the unexpected pitfall. The next fallback
check is SNDRV_CTL_ELEM_ACCESS_TLV_READ access bit, and this always
hits for each kctl with TLV. Then it evaluates the callback function
pointer wrongly as if it were a TLV array. Although currently its
side-effect is fairly limited, this incorrect reference may lead to an
unpleasant result.

For addressing the regression, this patch introduces a new helper to
vmaster code, snd_ctl_apply_vmaster_slaves(). This works similarly
like the existing map_slaves() in hda_codec.c: it loops over the slave
list of the given master, and applies the given function to each
slave. Then the initializer function receives the right kctl object
and we can compare the correct pointer instead of the faked one.

Also, for catching the similar breakage in future, give an error
message when the unexpected TLV callback is found and bail out
immediately.

Fixes: 99b5c5bb9a54 ("ALSA: hda - Remove the use of set_fs()")
Reported-by: PaX Team <pageexec@freemail.hu>
Cc: <stable@vger.kernel.org> # v4.13
Signed-off-by: Takashi Iwai <tiwai@suse.de>


# f2f9307a 04-Feb-2014 Takashi Iwai <tiwai@suse.de>

ALSA: core: Use standard printk helpers

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>


# 1ba65ae4 03-Jul-2013 Takashi Iwai <tiwai@suse.de>

ALSA: vmaster: Fix the regression of missing vmaster hook call

The commit [1ca2f2ec: ALSA: vmaster: Add snd_ctl_sync_vmaster() helper
function] changed master_put() function and the check for the required
vmaster hook call is wrongly performed now, which results in the
missing hook call upon "Master Playback Switch" value changes.
This patch corrects the check logic.

Signed-off-by: Takashi Iwai <tiwai@suse.de>


# 1ca2f2ec 24-Jun-2013 Takashi Iwai <tiwai@suse.de>

ALSA: vmaster: Add snd_ctl_sync_vmaster() helper function

Introduce a new helper function, snd_ctl_sync_vmaster(), which updates
the slave put callbacks forcibly as well as calling the hook. This
will be used in the upcoming patch in HD-audio codec driver for
toggling the mute in vmaster slaves.

Along with the new function, the old snd_ctl_sync_vmaster_hook() is
replaced as a macro calling with the argument hook_only=true.

Signed-off-by: Takashi Iwai <tiwai@suse.de>


# eb7c06e8 11-Mar-2013 Yacine Belkadi <yacine.belkadi.1@gmail.com>

ALSA: add/change some comments describing function return values

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>


# 2069d483 05-Mar-2013 Takashi Iwai <tiwai@suse.de>

ALSA: vmaster: Fix slave change notification

When a value of a vmaster slave control is changed, the ctl change
notification is sometimes ignored. This happens when the master
control overrides, e.g. when the corresponding master control is
muted. The reason is that slave_put() returns the value of the actual
slave put callback, and it doesn't reflect the virtual slave value
change.

This patch fixes the function just to return 1 whenever a slave value
is changed.

Cc: <stable@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>


# f2ec52d4 17-Apr-2012 Randy Dunlap <rdunlap@infradead.org>

ALSA: fix core/vmaster.c kernel-doc warning

Fix kernel-doc warning in sound/core/vmaster.c:

Warning(sound/core/vmaster.c:429): No description found for parameter 'private_data'

Signed-off-by: Randy Dunlap <rdunlap@xenotime.net>
Signed-off-by: Takashi Iwai <tiwai@suse.de>


# 2ad787e9 11-Mar-2012 Takashi Iwai <tiwai@suse.de>

ALSA: Add a hook capability to vmaster controls

This patch adds a hook to vmaster control to be called at each time
when the master value is changed. It'd be handy for an additional
mute LED control following the Master switch, for example.

Signed-off-by: Takashi Iwai <tiwai@suse.de>


# 9e226b4b 09-Nov-2011 Takashi Iwai <tiwai@suse.de>

ALSA: vmaster - Free slave-links when freeing the master element

When freeing the vmaster master element, we should release slave-links
properly, not only assumig that slaves will be freed soon later.

Signed-off-by: Takashi Iwai <tiwai@suse.de>


# d81a6d71 22-Sep-2011 Paul Gortmaker <paul.gortmaker@windriver.com>

sound: Add export.h for THIS_MODULE/EXPORT_SYMBOL where needed

These aren't modules, but they do make use of these macros, so
they will need export.h to get that definition. Previously,
they got it via the implicit module.h inclusion.

Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>


# 25985edc 30-Mar-2011 Lucas De Marchi <lucas.demarchi@profusion.mobi>

Fix common misspellings

Fixes generated by 'codespell' and manually reviewed.

Signed-off-by: Lucas De Marchi <lucas.demarchi@profusion.mobi>


# fea952e5 14-Feb-2011 Clemens Ladisch <clemens@ladisch.de>

ALSA: core: sparse cleanups

Change the core code where sparse complains. In most cases, this means
just adding annotations to confirm that we indeed want to do the dirty
things we're doing.

Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>


# 085f3065 16-Jun-2009 Takashi Iwai <tiwai@suse.de>

ALSA: Add new TLV types for dBwith min/max

Add new types for TLV dB scale specified with min/max values instead
of min/step since the resolution can't match always with the one
a device provides. For example, usb audio devices give 1/256 dB
resolution while ALSA TLV is based on 1/100 dB resolution.
The new min/max types have less problems because the possible
rounding error happens only at min/max.

Signed-off-by: Takashi Iwai <tiwai@suse.de>


# 79c7cdd5 09-Feb-2009 Takashi Iwai <tiwai@suse.de>

ALSA: Add kernel-doc comments to vmaster stuff

Signed-off-by: Takashi Iwai <tiwai@suse.de>


# f5b1db63 16-Jan-2009 Takashi Iwai <tiwai@suse.de>

ALSA: add snd_ctl_add_slave_uncached()

Added snd_ctl_add_slave_uncached() function to add a slave element
with volatile controls. The values of normal slave elements are
supposed to be cachable, i.e. they are changed only via the put
callbacks. OTOH, when a slave element is volatile and its values may
be changed by other reason (e.g. hardware status change), the values
will get inconsistent.

The new function allows the slave elements with volatile changes.
When the slave is tied with this call, the native get callback is
issued at each time so that the values are always updated.

Signed-off-by: Takashi Iwai <tiwai@suse.de>


# 1c82ed1b 18-Feb-2008 Takashi Iwai <tiwai@suse.de>

[ALSA] Keep private TLV entry in vmaster itself

Use a private array for TLV entries of virtual master controls instead
of (supposed) static array. This cleans up the existing codes.

Also, now vmaster assumes the simple dB-range TLV that is the only type
it can handle.

Signed-off-by: Takashi Iwai <tiwai@suse.de>


# e922b002 18-Feb-2008 Takashi Iwai <tiwai@suse.de>

[ALSA] Move vmaster code to sound core

Move the codes for virtual master controls to sound core part so that
not only hda-intel drivers can use it.

Signed-off-by: Takashi Iwai <tiwai@suse.de>