]> git.kernelconcepts.de Git - karo-tx-linux.git/log
karo-tx-linux.git
6 years agoALSA: pcm: remove SNDRV_PCM_IOCTL1_INFO internal command
Takashi Sakamoto [Wed, 14 Jun 2017 10:30:03 +0000 (19:30 +0900)]
ALSA: pcm: remove SNDRV_PCM_IOCTL1_INFO internal command

Drivers can implement 'struct snd_pcm_ops.ioctl' to handle some requests
from ALSA PCM core. These requests are internal purpose in kernel land.
Usually common set of operations are used for it.

SNDRV_PCM_IOCTL1_INFO is one of the requests. According to code comment,
it has been obsoleted in the old days.

We can see old releases in ftp.alsa-project.org. The command was firstly
introduced in v0.5.0 release as SND_PCM_IOCTL1_INFO, to allow drivers to
fill data of 'struct snd_pcm_channel_info' type. In v0.9.0 release,
this was obsoleted by the other commands for ioctl(2) such as
SNDRV_PCM_IOCTL_CHANNEL_INFO.

This commit removes the long-abandoned command, bye.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: Skip ack callback without actual appl_ptr update
Takashi Iwai [Tue, 13 Jun 2017 13:57:28 +0000 (15:57 +0200)]
ALSA: pcm: Skip ack callback without actual appl_ptr update

We call ack callback whenever appl_ptr gets updated via
pcm_lib_apply_appl_ptr().  There are various code paths to call this
function.  A part of them are for read/write/forward/rewind, where the
appl_ptr is always changed and thus the call of ack is mandatory.
OTOH, another part of code paths are from the explicit user call,
e.g. via SYNC_PTR ioctl.  There, we may receive the same appl_ptr
value, and in such a case, calling ack is obviously superfluous.

This patch adds the check of the given appl_ptr value, and returns
immediately if it's no real update.

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: Use common PCM_RUNTIME_CHECK() for sanity checks
Takashi Iwai [Tue, 24 May 2016 13:53:36 +0000 (15:53 +0200)]
ALSA: pcm: Use common PCM_RUNTIME_CHECK() for sanity checks

Just a code cleanup.

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: Preprocess PAUSED or SUSPENDED stream before PREPARE
Takashi Iwai [Tue, 24 May 2016 13:40:03 +0000 (15:40 +0200)]
ALSA: pcm: Preprocess PAUSED or SUSPENDED stream before PREPARE

Calling PREPARE ioctl to the stream in either PAUSED or SUSPENDED
state may confuse some drivers that don't handle the state properly.
Instead of fixing each driver, PCM core should take care of the proper
state change before actually trying to (re-)prepare the stream.
Namely, when the stream is in PAUSED state, it triggers PAUSE_RELEASE,
and when in SUSPENDED state, it triggers STOP, before calling prepare
callbacks.

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: Allow dropping stream directly after resume
Takashi Iwai [Tue, 24 May 2016 13:08:31 +0000 (15:08 +0200)]
ALSA: pcm: Allow dropping stream directly after resume

So far, the PCM core refuses DROP ioctl when the stream in the
suspended state.  This was basically to avoid the invalid state change
*during* the suspend.  But since we protect the power change globally
in the common PCM ioctl caller side, it's guaranteed that
snd_pcm_drop() is called at the right power state.  So we can assume
that the drop of stream is safe immediately after SUSPENDED state.

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: Apply power lock globally to common ioctls
Takashi Iwai [Tue, 24 May 2016 13:07:39 +0000 (15:07 +0200)]
ALSA: pcm: Apply power lock globally to common ioctls

All PCM common ioctls should run only in the powered up state, but
currently only a few ioctls do the proper snd_power_lock() and
snd_power_wait() invocations.  Instead of adding to each place, do it
commonly in the caller side, so that all these ioctls are assured to
be operated at the power up state.

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: Clean up SNDRV_PCM_IOCTL_PAUSE code
Takashi Iwai [Tue, 24 May 2016 12:58:04 +0000 (14:58 +0200)]
ALSA: pcm: Clean up SNDRV_PCM_IOCTL_PAUSE code

Use snd_pcm_action_lock_irq() helper instead of open coding.
No functional change.

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoMerge branch 'topic/seq-kconfig' into for-next
Takashi Iwai [Tue, 13 Jun 2017 05:50:09 +0000 (07:50 +0200)]
Merge branch 'topic/seq-kconfig' into for-next

6 years agoALSA: pcm: use %s instead of %c for format of PCM buffer tracepoints
Takashi Sakamoto [Mon, 12 Jun 2017 00:41:46 +0000 (09:41 +0900)]
ALSA: pcm: use %s instead of %c for format of PCM buffer tracepoints

As long as I know, in userspace, '%c' format on printing format for
tracepoint is replaced with '>c<' by existent tracing program; i.g.
'perf-trace' and 'trace-cmd'. This is inconvenient.

This commit replaces the format with '%s'. The length of letters in the
format string is not changed, thus this commit doesn't increase object
size.

In theory, I should work for improvements of these tracing programs, but
here I'd like to save my time to work for the other projects.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: add 'applptr' event of tracepoint
Takashi Sakamoto [Mon, 12 Jun 2017 00:41:45 +0000 (09:41 +0900)]
ALSA: pcm: add 'applptr' event of tracepoint

In design of ALSA PCM core, status and control data for runtime of ALSA
PCM substream are shared between kernel/user spaces by page frame
mapping with read-only attribute. Both of hardware-side and
application-side position on PCM buffer are maintained as a part of
the status data. In a view of ALSA PCM application, these two positions
can be updated by executing ioctl(2) with some commands.

There's an event of tracepoint for hardware-side position; 'hwptr'.
On the other hand, no events for application-side position. This commit
adds a new event for this purpose; 'applptr'. When the application-side
position is changed in kernel space, this event is probed with useful
information for developers.

I note that the event is not probed for all of ALSA PCM applications, When
applications are written by read/write programming scenario, the event is
surely probed. The applications execute ioctl(2) with
SNDRV_PCM_IOCTL_[READ|WRITE][N/I]_FRAMES to read/write any PCM frame, then
ALSA PCM core updates the application-side position in kernel land.
However, when applications are written by mmap programming scenario, if
maintaining the application side position in kernel space accurately,
applications should voluntarily execute ioctl(2) with
SNDRV_PCM_IOCTL_SYNC_PTR to commit the number of handled PCM frames. If
not voluntarily, the application-side position is not changed, thus the
added event is not probed.

There's a loophole, using architectures to which ALSA PCM core judges
non cache coherent. In this case, the status and control data is not mapped
into processe's VMA for any applications. Userland library, alsa-lib, is
programmed for this case. It executes ioctl(2) with
SNDRV_PCM_IOCTL_SYNC_PTR command every time to requiring the status and
control data.

ARM is such an architecture. Below is an example with serial sound interface
(ssi) on i.mx6 quad core SoC. I use v4.1 kernel released by fsl-community
with patches from VIA Tech. Inc. for VAB820, and my backport patches for
relevant features for this patchset. I use Ubuntu 17.04 from
ports.ubuntu.com as user land for armhf architecture.

$ aplay -v -M -D hw:imx6vab820sgtl5,0 /dev/urandom -f S16_LE -r 48000 --period-size=128 --buffer-size=256
Playing raw data '/dev/urandom' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono
Hardware PCM card 0 'imx6-vab820-sgtl5000' device 0 subdevice 0
Its setup is:
  stream       : PLAYBACK
  access       : MMAP_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 1
  rate         : 48000
  exact rate   : 48000 (48000/1)
  msbits       : 16
  buffer_size  : 256
  period_size  : 128
  period_time  : 2666
  tstamp_mode  : NONE
  tstamp_type  : MONOTONIC
  period_step  : 1
  avail_min    : 128
  period_event : 0
  start_threshold  : 256
  stop_threshold   : 256
  silence_threshold: 0
  silence_size : 0
  boundary     : 1073741824
  appl_ptr     : 0
  hw_ptr       : 0
mmap_area[0] = 0x76f98000,0,16 (16)

$ trace-cmd record -e snd_pcm:hwptr -e snd_pcm:applptr
$ trace-cmd report
...
60.208495: applptr: pcmC0D0p/sub0: prev=1792, curr=1792, avail=0, period=128, buf=256
60.208633: applptr: pcmC0D0p/sub0: prev=1792, curr=1792, avail=0, period=128, buf=256
60.210022: hwptr:   pcmC0D0p/sub0: IRQ: pos=128, old=1536, base=1536, period=128, buf=256
60.210202: applptr: pcmC0D0p/sub0: prev=1792, curr=1792, avail=128, period=128, buf=256
60.210344: hwptr:   pcmC0D0p/sub0: POS: pos=128, old=1664, base=1536, period=128, buf=256
60.210348: applptr: pcmC0D0p/sub0: prev=1792, curr=1792, avail=128, period=128, buf=256
60.210486: applptr: pcmC0D0p/sub0: prev=1792, curr=1792, avail=128, period=128, buf=256
60.210626: applptr: pcmC0D0p/sub0: prev=1792, curr=1920, avail=0, period=128, buf=256
60.211002: applptr: pcmC0D0p/sub0: prev=1920, curr=1920, avail=0, period=128, buf=256
60.211142: hwptr:   pcmC0D0p/sub0: POS: pos=128, old=1664, base=1536, period=128, buf=256
60.211146: applptr: pcmC0D0p/sub0: prev=1920, curr=1920, avail=0, period=128, buf=256
60.211287: applptr: pcmC0D0p/sub0: prev=1920, curr=1920, avail=0, period=128, buf=256
60.212690: hwptr:   pcmC0D0p/sub0: IRQ: pos=0, old=1664, base=1536, period=128, buf=256
60.212866: applptr: pcmC0D0p/sub0: prev=1920, curr=1920, avail=128, period=128, buf=256
60.212999: hwptr:   pcmC0D0p/sub0: POS: pos=0, old=1792, base=1792, period=128, buf=256
60.213003: applptr: pcmC0D0p/sub0: prev=1920, curr=1920, avail=128, period=128, buf=256
60.213135: applptr: pcmC0D0p/sub0: prev=1920, curr=1920, avail=128, period=128, buf=256
60.213276: applptr: pcmC0D0p/sub0: prev=1920, curr=2048, avail=0, period=128, buf=256
60.213654: applptr: pcmC0D0p/sub0: prev=2048, curr=2048, avail=0, period=128, buf=256
60.213796: hwptr:   pcmC0D0p/sub0: POS: pos=0, old=1792, base=1792, period=128, buf=256
60.213800: applptr: pcmC0D0p/sub0: prev=2048, curr=2048, avail=0, period=128, buf=256
60.213937: applptr: pcmC0D0p/sub0: prev=2048, curr=2048, avail=0, period=128, buf=256
60.215356: hwptr:   pcmC0D0p/sub0: IRQ: pos=128, old=1792, base=1792, period=128, buf=256
60.215542: applptr: pcmC0D0p/sub0: prev=2048, curr=2048, avail=128, period=128, buf=256
60.215679: hwptr:   pcmC0D0p/sub0: POS: pos=128, old=1920, base=1792, period=128, buf=256
60.215683: applptr: pcmC0D0p/sub0: prev=2048, curr=2048, avail=128, period=128, buf=256
60.215813: applptr: pcmC0D0p/sub0: prev=2048, curr=2048, avail=128, period=128, buf=256
60.215947: applptr: pcmC0D0p/sub0: prev=2048, curr=2176, avail=0, period=128, buf=256
...

We can surely see 'applptr' event is probed even if the application run
for mmap programming scenario ('-M' option and 'hw' plugin). Below is a
result of strace:

02:44:15.886382 ioctl(4, SNDRV_PCM_IOCTL_SYNC_PTR, 0x56a32b30) = 0
02:44:15.887203 poll([{fd=4, events=POLLOUT|POLLERR|POLLNVAL}], 1, -1) = 1 ([{fd=4, revents=POLLOUT}])
02:44:15.887471 ioctl(4, SNDRV_PCM_IOCTL_SYNC_PTR, 0x56a32b30) = 0
02:44:15.887637 ioctl(4, SNDRV_PCM_IOCTL_SYNC_PTR, 0x56a32b30) = 0
02:44:15.887805 ioctl(4, SNDRV_PCM_IOCTL_SYNC_PTR, 0x56a32b30) = 0
02:44:15.887969 ioctl(4, SNDRV_PCM_IOCTL_SYNC_PTR, 0x56a32b30) = 0
02:44:15.888132 read(3, "..."..., 256) = 256
02:44:15.889040 ioctl(4, SNDRV_PCM_IOCTL_SYNC_PTR, 0x56a32b30) = 0
02:44:15.889221 ioctl(4, SNDRV_PCM_IOCTL_SYNC_PTR, 0x56a32b30) = 0
02:44:15.889431 ioctl(4, SNDRV_PCM_IOCTL_SYNC_PTR, 0x56a32b30) = 0
02:44:15.889606 poll([{fd=4, events=POLLOUT|POLLERR|POLLNVAL}], 1, -1) = 1 ([{fd=4, revents=POLLOUT}])
02:44:15.889833 ioctl(4, SNDRV_PCM_IOCTL_SYNC_PTR, 0x56a32b30) = 0
02:44:15.889998 ioctl(4, SNDRV_PCM_IOCTL_SYNC_PTR, 0x56a32b30) = 0
02:44:15.890164 ioctl(4, SNDRV_PCM_IOCTL_SYNC_PTR, 0x56a32b30) = 0
02:44:15.891048 ioctl(4, SNDRV_PCM_IOCTL_SYNC_PTR, 0x56a32b30) = 0
02:44:15.891228 read(3, "..."..., 256) = 256
02:44:15.891497 ioctl(4, SNDRV_PCM_IOCTL_SYNC_PTR, 0x56a32b30) = 0
02:44:15.891661 ioctl(4, SNDRV_PCM_IOCTL_SYNC_PTR, 0x56a32b30) = 0
02:44:15.891829 ioctl(4, SNDRV_PCM_IOCTL_SYNC_PTR, 0x56a32b30) = 0
02:44:15.891991 poll([{fd=4, events=POLLOUT|POLLERR|POLLNVAL}], 1, -1) = 1 ([{fd=4, revents=POLLOUT}])
02:44:15.893007 ioctl(4, SNDRV_PCM_IOCTL_SYNC_PTR, 0x56a32b30) = 0

We can see 7 calls of ioctl(2) with SNDRV_PCM_IOCTL_SYNC_PTR per loop with
call of poll(2). 128 PCM frames are transferred per loop of one poll(2),
because the PCM substream is configured with S16_LE format and 1 channel
(2 byte * 1 * 128 = 256 bytes). This equals to the size of period of PCM
buffer. Comparing to the probed data, one of the 7 calls of ioctl(2) is
actually used to commit the number of copied PCM frames to kernel space.
The other calls are just used to check runtime status of PCM substream;
e.g. XRUN.

The tracepoint event is useful to investigate this case. I note that below
modules are related to the above sample.

 * snd-soc-dummy.ko
 * snd-soc-imx-sgtl5000.ko
 * snd-soc-fsl-ssi.ko
 * snd-soc-imx-pcm-dma.ko
 * snd-soc-sgtl5000.ko

My additional note is lock acquisition. The event is probed under acquiring
PCM stream lock. This means that calculation in the event is free from
any hardware events.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: unify codes to operate application-side position on PCM buffer
Takashi Sakamoto [Mon, 12 Jun 2017 00:41:44 +0000 (09:41 +0900)]
ALSA: pcm: unify codes to operate application-side position on PCM buffer

In a series of recent work, ALSA PCM core got some arrangements to handle
application-side position on PCM buffer. However, relevant codes still
disperse to two translation units

This commit unifies these codes into a helper function.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: seq: Allow the modular sequencer registration
Takashi Iwai [Fri, 9 Jun 2017 13:11:58 +0000 (15:11 +0200)]
ALSA: seq: Allow the modular sequencer registration

Many drivers bind the sequencer stuff in off-load by another driver
module, so that it's loaded only on demand.  In the current code, this
mechanism doesn't work when the driver is built-in while the sequencer
is module.  We check with IS_REACHABLE() and enable only when the
sequencer is in the same level of build.

However, this is basically a overshoot.  The binder code
(snd-seq-device) is an individual module from the sequencer core
(snd-seq), and we just have to make the former a built-in while
keeping the latter a module for allowing the scenario like the above.

This patch achieves that by rewriting Kconfig slightly.  Now, a driver
that provides the manual sequencer device binding should select
CONFIG_SND_SEQ_DEVICE in a way as
select SND_SEQ_DEVICE if SND_SEQUENCER != n

Note that the "!=n" is needed here to avoid the influence of the
sequencer core is module while the driver is built-in.

Also, since rawmidi.o may be linked with snd_seq_device.o when
built-in, we have to shuffle the code to make the linker happy.
(the kernel linker isn't smart enough yet to handle such a case.)
That is, snd_seq_device.c is moved to sound/core from sound/core/seq,
as well as Makefile.

Last but not least, the patch replaces the code using IS_REACHABLE()
with IS_ENABLED(), since now the condition meets always when enabled.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: probe events when parameters are changed actually
Takashi Sakamoto [Sun, 11 Jun 2017 14:56:13 +0000 (23:56 +0900)]
ALSA: pcm: probe events when parameters are changed actually

At present, trace events are probed even if corresponding parameter is
not actually changed. This is inconvenient.

This commit improves the behaviour.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: return error immediately for parameters handling
Takashi Sakamoto [Sun, 11 Jun 2017 14:56:12 +0000 (23:56 +0900)]
ALSA: pcm: return error immediately for parameters handling

When refining mask/interval parameters, helper functions can return error
code. This error is not handled immediately. This seems to return
parameters to userspace applications in its meddle of processing.

However, in general, when receiving error from system calls, the
application might not handle argument buffer. It's reasonable to
judge the above design as superfluity.

This commit handles the error immediately.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: synth: Select snd-emux-synth explicitly
Takashi Iwai [Fri, 9 Jun 2017 12:57:51 +0000 (14:57 +0200)]
ALSA: synth: Select snd-emux-synth explicitly

Instead of the non-standard way to enable the build of snd-emux-synth
module inside Makefile, rewrite Kconfig to select the item explicitly
from each driver (sbawe and emu10k1).  This is the standard way.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: seq: Reorganize kconfig and build
Takashi Iwai [Fri, 9 Jun 2017 12:40:18 +0000 (14:40 +0200)]
ALSA: seq: Reorganize kconfig and build

This is a slightly intensive rewrite of Kconfig and Makefile about
ALSA sequencer stuff.

The first major change is that the kconfig items for the sequencer are
moved to sound/core/seq/Kconfig.  OK, that's easy.

The substantial change is that, instead of hackish top-level module
selection in Makefile, we define a Kconfig item for each sequencer
module.  The driver that requires such sequencer components select
exclusively the kconfig items.  This is more straightforward and
standard way.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: seq: Allow the tristate build of OSS emulation
Takashi Iwai [Fri, 9 Jun 2017 12:06:46 +0000 (14:06 +0200)]
ALSA: seq: Allow the tristate build of OSS emulation

Currently OSS sequencer emulation is tied with ALSA sequencer core,
both are built in the same level; i.e. when CONFIG_SND_SEQUENCER=y,
the OSS sequencer emulation is also always built-in, even though the
functionality can be built as an individual module.

This patch changes the rule and allows users to build snd-seq-oss
module while others are built-in.  Essentially, it's just a few simple
changes in Kconfig and Makefile.  Some driver codes like opl3 need to
convert from the simple ifdef to IS_ENABLED().  But that's all.

You might wonder how about the dependency: right, it can be messy, but
it still works.  Since we rewrote the sequencer binding with the
standard bus, the driver can be bound at any time on demand.  So, the
synthesizer driver module can be loaded individually from the OSS
emulation core before/after it.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: Make CONFIG_SND_OSSEMUL user-selectable
Takashi Iwai [Fri, 9 Jun 2017 11:56:05 +0000 (13:56 +0200)]
ALSA: Make CONFIG_SND_OSSEMUL user-selectable

Currently CONFIG_SND_OSSEMUL is selected by each config like
CONFIG_SND_PCM_OSS.  But, as see in the raw MIDI code that is built
conditionally with CONFIG_SND_OSSEMUL, we should rather make
CONFIG_SND_OSSEMUL user-selectable as the top kconfig item, and leave
the rest depending on it.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: use friendly name for id of PCM substream in trace print
Takashi Sakamoto [Fri, 9 Jun 2017 12:46:50 +0000 (21:46 +0900)]
ALSA: pcm: use friendly name for id of PCM substream in trace print

Use the same print format of snd_pcm_debug_name() for userspace tracing
program.

Suggested-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: add tracepoints for final selection process of hardware parameters
Takashi Sakamoto [Fri, 9 Jun 2017 12:46:49 +0000 (21:46 +0900)]
ALSA: pcm: add tracepoints for final selection process of hardware parameters

Results of ioctl(2) with SNDRV_PCM_IOCTL_HW_REFINE and
SNDRV_PCM_IOCTL_HW_PARAMS are different, because the latter has single
value for several parameters; e.g. channels of PCM substream. Selection
of the single value is done independently of application of constraints.
It's helpful for developers to trace the selection process.

This commit adds tracepoints to snd_pcm_hw_params_choose() for the
purpose.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: localize snd_pcm_hw_params_choose()
Takashi Sakamoto [Fri, 9 Jun 2017 12:46:48 +0000 (21:46 +0900)]
ALSA: pcm: localize snd_pcm_hw_params_choose()

As of v4.12, snd_pcm_hw_params_choose() is just called in a process
context of ioctl(2) with SNDRV_PCM_IOCTL_HW_PARAMS. The function locates
in a different file, which has no tracepoints.

This commit moves the function to a file with the tracepoints for later
commit.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: sparc: Constify hw_constraints
Takashi Iwai [Wed, 7 Jun 2017 12:23:22 +0000 (14:23 +0200)]
ALSA: sparc: Constify hw_constraints

snd_pcm_hw_constraint_list(), *_ratnums() and *_ratdens() receive the
const pointers.  Constify the corresponding static objects for better
hardening.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: via82xx: Constify hw_constraints
Takashi Iwai [Wed, 7 Jun 2017 12:23:13 +0000 (14:23 +0200)]
ALSA: via82xx: Constify hw_constraints

snd_pcm_hw_constraint_list(), *_ratnums() and *_ratdens() receive the
const pointers.  Constify the corresponding static objects for better
hardening.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: sonicvibes: Constify hw_constraints
Takashi Iwai [Wed, 7 Jun 2017 12:22:55 +0000 (14:22 +0200)]
ALSA: sonicvibes: Constify hw_constraints

snd_pcm_hw_constraint_list(), *_ratnums() and *_ratdens() receive the
const pointers.  Constify the corresponding static objects for better
hardening.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: rme9652: Constify hw_constraints
Takashi Iwai [Wed, 7 Jun 2017 12:22:43 +0000 (14:22 +0200)]
ALSA: rme9652: Constify hw_constraints

snd_pcm_hw_constraint_list(), *_ratnums() and *_ratdens() receive the
const pointers.  Constify the corresponding static objects for better
hardening.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: hdspm: Constify hw_constraints
Takashi Iwai [Wed, 7 Jun 2017 12:22:35 +0000 (14:22 +0200)]
ALSA: hdspm: Constify hw_constraints

snd_pcm_hw_constraint_list(), *_ratnums() and *_ratdens() receive the
const pointers.  Constify the corresponding static objects for better
hardening.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: hdsp: Constify hw_constraints
Takashi Iwai [Wed, 7 Jun 2017 12:22:26 +0000 (14:22 +0200)]
ALSA: hdsp: Constify hw_constraints

snd_pcm_hw_constraint_list(), *_ratnums() and *_ratdens() receive the
const pointers.  Constify the corresponding static objects for better
hardening.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: rme96: Constify hw_constraints
Takashi Iwai [Wed, 7 Jun 2017 12:22:10 +0000 (14:22 +0200)]
ALSA: rme96: Constify hw_constraints

snd_pcm_hw_constraint_list(), *_ratnums() and *_ratdens() receive the
const pointers.  Constify the corresponding static objects for better
hardening.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: rme32: Constify hw_constraints
Takashi Iwai [Wed, 7 Jun 2017 12:22:02 +0000 (14:22 +0200)]
ALSA: rme32: Constify hw_constraints

snd_pcm_hw_constraint_list(), *_ratnums() and *_ratdens() receive the
const pointers.  Constify the corresponding static objects for better
hardening.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: nm256: Constify hw_constraints
Takashi Iwai [Wed, 7 Jun 2017 12:21:49 +0000 (14:21 +0200)]
ALSA: nm256: Constify hw_constraints

snd_pcm_hw_constraint_list(), *_ratnums() and *_ratdens() receive the
const pointers.  Constify the corresponding static objects for better
hardening.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: intel8x0: Constify hw_constraints
Takashi Iwai [Wed, 7 Jun 2017 12:21:31 +0000 (14:21 +0200)]
ALSA: intel8x0: Constify hw_constraints

snd_pcm_hw_constraint_list(), *_ratnums() and *_ratdens() receive the
const pointers.  Constify the corresponding static objects for better
hardening.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: ice1724: Constify hw_constraints
Takashi Iwai [Wed, 7 Jun 2017 12:20:52 +0000 (14:20 +0200)]
ALSA: ice1724: Constify hw_constraints

snd_pcm_hw_constraint_list(), *_ratnums() and *_ratdens() receive the
const pointers.  Constify the corresponding static objects for better
hardening.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: ice1712: Constify hw_constraints
Takashi Iwai [Wed, 7 Jun 2017 12:20:40 +0000 (14:20 +0200)]
ALSA: ice1712: Constify hw_constraints

snd_pcm_hw_constraint_list(), *_ratnums() and *_ratdens() receive the
const pointers.  Constify the corresponding static objects for better
hardening.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: hda: Constify hw_constraints
Takashi Iwai [Wed, 7 Jun 2017 12:20:07 +0000 (14:20 +0200)]
ALSA: hda: Constify hw_constraints

snd_pcm_hw_constraint_list(), *_ratnums() and *_ratdens() receive the
const pointers.  Constify the corresponding static objects for better
hardening.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: es1938: Constify hw_constraints
Takashi Iwai [Wed, 7 Jun 2017 12:19:56 +0000 (14:19 +0200)]
ALSA: es1938: Constify hw_constraints

snd_pcm_hw_constraint_list(), *_ratnums() and *_ratdens() receive the
const pointers.  Constify the corresponding static objects for better
hardening.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: ens137x: Constify hw_constraints
Takashi Iwai [Wed, 7 Jun 2017 12:19:39 +0000 (14:19 +0200)]
ALSA: ens137x: Constify hw_constraints

snd_pcm_hw_constraint_list(), *_ratnums() and *_ratdens() receive the
const pointers.  Constify the corresponding static objects for better
hardening.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: fm801: Constify hw_constraints
Takashi Iwai [Wed, 7 Jun 2017 12:19:28 +0000 (14:19 +0200)]
ALSA: fm801: Constify hw_constraints

snd_pcm_hw_constraint_list(), *_ratnums() and *_ratdens() receive the
const pointers.  Constify the corresponding static objects for better
hardening.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: emu10k1: Constify hw_constraints
Takashi Iwai [Wed, 7 Jun 2017 12:19:20 +0000 (14:19 +0200)]
ALSA: emu10k1: Constify hw_constraints

snd_pcm_hw_constraint_list(), *_ratnums() and *_ratdens() receive the
const pointers.  Constify the corresponding static objects for better
hardening.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: cs46xx: Constify hw_constraints
Takashi Iwai [Wed, 7 Jun 2017 12:19:05 +0000 (14:19 +0200)]
ALSA: cs46xx: Constify hw_constraints

snd_pcm_hw_constraint_list(), *_ratnums() and *_ratdens() receive the
const pointers.  Constify the corresponding static objects for better
hardening.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: cmipci: Constify hw_constraints
Takashi Iwai [Wed, 7 Jun 2017 12:18:47 +0000 (14:18 +0200)]
ALSA: cmipci: Constify hw_constraints

snd_pcm_hw_constraint_list(), *_ratnums() and *_ratdens() receive the
const pointers.  Constify the corresponding static objects for better
hardening.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: bt87x: Constify hw_constraints
Takashi Iwai [Wed, 7 Jun 2017 12:18:33 +0000 (14:18 +0200)]
ALSA: bt87x: Constify hw_constraints

snd_pcm_hw_constraint_list(), *_ratnums() and *_ratdens() receive the
const pointers.  Constify the corresponding static objects for better
hardening.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: azt3328: Constify hw_constraints
Takashi Iwai [Wed, 7 Jun 2017 12:18:16 +0000 (14:18 +0200)]
ALSA: azt3328: Constify hw_constraints

snd_pcm_hw_constraint_list(), *_ratnums() and *_ratdens() receive the
const pointers.  Constify the corresponding static objects for better
hardening.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: au88x0: Constify hw_constraints
Takashi Iwai [Wed, 7 Jun 2017 12:18:01 +0000 (14:18 +0200)]
ALSA: au88x0: Constify hw_constraints

snd_pcm_hw_constraint_list(), *_ratnums() and *_ratdens() receive the
const pointers.  Constify the corresponding static objects for better
hardening.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: atiixp: Constify hw_constraints
Takashi Iwai [Wed, 7 Jun 2017 12:17:39 +0000 (14:17 +0200)]
ALSA: atiixp: Constify hw_constraints

snd_pcm_hw_constraint_list(), *_ratnums() and *_ratdens() receive the
const pointers.  Constify the corresponding static objects for better
hardening.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: ali5451: Constify hw_constraints
Takashi Iwai [Wed, 7 Jun 2017 12:17:23 +0000 (14:17 +0200)]
ALSA: ali5451: Constify hw_constraints

snd_pcm_hw_constraint_list(), *_ratnums() and *_ratdens() receive the
const pointers.  Constify the corresponding static objects for better
hardening.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: parisc: Constify hw_constraints
Takashi Iwai [Wed, 7 Jun 2017 12:17:04 +0000 (14:17 +0200)]
ALSA: parisc: Constify hw_constraints

snd_pcm_hw_constraint_list(), *_ratnums() and *_ratdens() receive the
const pointers.  Constify the corresponding static objects for better
hardening.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: wss: Constify hw_constraints
Takashi Iwai [Wed, 7 Jun 2017 12:16:43 +0000 (14:16 +0200)]
ALSA: wss: Constify hw_constraints

snd_pcm_hw_constraint_list(), *_ratnums() and *_ratdens() receive the
const pointers.  Constify the corresponding static objects for better
hardening.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: sb: Constify hw_constraints
Takashi Iwai [Wed, 7 Jun 2017 12:16:34 +0000 (14:16 +0200)]
ALSA: sb: Constify hw_constraints

snd_pcm_hw_constraint_list(), *_ratnums() and *_ratdens() receive the
const pointers.  Constify the corresponding static objects for better
hardening.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: gus: Constify hw_constraints
Takashi Iwai [Wed, 7 Jun 2017 12:16:25 +0000 (14:16 +0200)]
ALSA: gus: Constify hw_constraints

snd_pcm_hw_constraint_list(), *_ratnums() and *_ratdens() receive the
const pointers.  Constify the corresponding static objects for better
hardening.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: es18xx: Constify hw_constraints
Takashi Iwai [Wed, 7 Jun 2017 12:16:10 +0000 (14:16 +0200)]
ALSA: es18xx: Constify hw_constraints

snd_pcm_hw_constraint_list(), *_ratnums() and *_ratdens() receive the
const pointers.  Constify the corresponding static objects for better
hardening.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: es1688: Constify hw_constraints
Takashi Iwai [Wed, 7 Jun 2017 12:15:49 +0000 (14:15 +0200)]
ALSA: es1688: Constify hw_constraints

snd_pcm_hw_constraint_list(), *_ratnums() and *_ratdens() receive the
const pointers.  Constify the corresponding static objects for better
hardening.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: cs423x: Constify hw_constraints
Takashi Iwai [Wed, 7 Jun 2017 12:12:16 +0000 (14:12 +0200)]
ALSA: cs423x: Constify hw_constraints

snd_pcm_hw_constraint_list(), *_ratnums() and *_ratdens() receive the
const pointers.  Constify the corresponding static objects for better
hardening.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: vx: vx_pcm: constify vx_pcm_playback_ops and vx_pcm_capture_ops.
Arvind Yadav [Fri, 9 Jun 2017 07:05:43 +0000 (12:35 +0530)]
ALSA: vx: vx_pcm: constify vx_pcm_playback_ops and vx_pcm_capture_ops.

File size before:
   text    data     bss     dec     hex filename
   7126     240       0    7366    1cc6 sound/drivers/vx/vx_pcm.o

File size After adding 'const':
   text    data     bss     dec     hex filename
   7382       0       0    7382    1cd6 sound/drivers/vx/vx_pcm.o

Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA : pcsp: pcsp_lib: constify snd_pcsp_playback_ops
Arvind Yadav [Fri, 9 Jun 2017 06:09:56 +0000 (11:39 +0530)]
ALSA : pcsp: pcsp_lib: constify snd_pcsp_playback_ops

File size before:
   text    data     bss     dec     hex filename
   2027     168       1    2196     894 sound/drivers/pcsp/pcsp_lib.o

File size After:
   text    data     bss     dec     hex filename
   2155      40       1    2196     894 sound/drivers/pcsp/pcsp_lib.o

Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: move fixup of info flag after selecting single parameters
Takashi Sakamoto [Fri, 9 Jun 2017 00:34:40 +0000 (09:34 +0900)]
ALSA: pcm: move fixup of info flag after selecting single parameters

When drivers register no flags about information of PCM hardware, ALSA
PCM core fixups it roughly. Currently, this operation places in a
function snd_pcm_hw_refine(). It can be moved to a function
fixup_unreferenced_params() because it doesn't affects operations
between these two functions.

This idea is better to bundle codes with similar purposes and this commit
achieves it.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: calculate non-mask/non-interval parameters always when possible
Takashi Sakamoto [Fri, 9 Jun 2017 00:34:39 +0000 (09:34 +0900)]
ALSA: pcm: calculate non-mask/non-interval parameters always when possible

A structure for parameters of PCM runtime has parameters which are
not classified as mask/interval type. They are decided only when
corresponding normal parameters have unique values.
 * struct snd_pcm_hw_params.msbits
 * struct snd_pcm_hw_params.rate_num
 * struct snd_pcm_hw_params.rate_den
 * struct snd_pcm_hw_params.fifo_size

Current implementation of hw_params ioctl sometimes doesn't decide these
parameters even if corresponding parameters are fixed, because these
parameters are evaluated before a call of snd_pcm_hw_params_choose().

This commit adds a helper function to process the parameters and call it
in proper positions.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: use helper functions to refer parameters as constants
Takashi Sakamoto [Fri, 9 Jun 2017 00:34:38 +0000 (09:34 +0900)]
ALSA: pcm: use helper functions to refer parameters as constants

To fixup some parameters, ALSA PCM core refers the other parameters as
constants. There're some macros for this purpose.

This commit replaces codes with them.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: add comment about application of rule to PCM parameters
Takashi Sakamoto [Thu, 8 Jun 2017 21:37:06 +0000 (06:37 +0900)]
ALSA: pcm: add comment about application of rule to PCM parameters

Drivers add rules of parameters to runtime of PCM substream, when
applications open ALSA PCM character device. When applications call
ioctl(2) with SNDRV_PCM_IOCTL_HW_REFINE or SNDRV_PCM_IOCTL_HW_PARAMS, the
rules are applied to the parameters and return the result to user space.

The rule can have dependency between parameters. Additionally, it can have
condition flags about application of rules. Userspace applications can
indicate the flags to suppress change of parameters.

This commit attempts to describe the mechanism.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: use helper functions to check whether parameters are determined
Takashi Sakamoto [Thu, 8 Jun 2017 21:37:05 +0000 (06:37 +0900)]
ALSA: pcm: use helper functions to check whether parameters are determined

A commit 8bea869c5e56 ("ALSA: PCM midlevel: improve fifo_size handling")
allows drivers to implement calculation of fifo size in parameter
structure. This calculation runs only when two of the other parameters
have single value.

In ALSA PCM core, there're some helper functions for the case. This commit
applies the functions instead of value comparison.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: adaption of code formatting
Takashi Sakamoto [Thu, 8 Jun 2017 21:37:04 +0000 (06:37 +0900)]
ALSA: pcm: adaption of code formatting

This commit modifies current for readability in below aspects:
 - use bool type variable instead of int type variable assigned to 0/1
 - move variable definition from loop to top of the function definition

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: remove function local variable with alternative evaluation
Takashi Sakamoto [Thu, 8 Jun 2017 21:37:03 +0000 (06:37 +0900)]
ALSA: pcm: remove function local variable with alternative evaluation

A local variable is used to judge whether a parameter should be handled
due to reverse dependency of the other rules. However, this can be
obsoleted by check of a sentinel in dependency array.

This commit removes the local variable and check the sentinel to reduce
stack usage.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: use goto statement instead of while statement to reduce indentation
Takashi Sakamoto [Thu, 8 Jun 2017 21:37:02 +0000 (06:37 +0900)]
ALSA: pcm: use goto statement instead of while statement to reduce indentation

In a process to calculate parameters of PCM substream, application of all
rules is iterated several times till parameter dependencies are satisfied.
In current implementation, two loops are used for the design, however this
brings two-level indentation and decline readability.

This commit attempts to reduce the indentation by using goto statement,
instead of outer while loop.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: add a helper function to apply parameter rules
Takashi Sakamoto [Thu, 8 Jun 2017 21:37:01 +0000 (06:37 +0900)]
ALSA: pcm: add a helper function to apply parameter rules

Application of rules to parameters of PCM substream is done in a call of
snd_pcm_hw_refine(), while the function includes much codes and is not
enough friendly to readers.

This commit splits the codes to a separated function so that readers can
get it easily. I leave desicion into compilers to merge the function into
its callee.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: add a helper function to constrain interval-type parameters
Takashi Sakamoto [Thu, 8 Jun 2017 21:37:00 +0000 (06:37 +0900)]
ALSA: pcm: add a helper function to constrain interval-type parameters

Application of constraints to interval-type parameters for PCM substream
is done in a call of snd_pcm_hw_refine(), while the function includes
much codes and is not enough friendly to readers.

This commit splits the codes to a separated function so that readers can
get it easily. I leave desicion into compilers to merge the function into
its callee.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: add a helper function to constrain mask-type parameters
Takashi Sakamoto [Thu, 8 Jun 2017 21:36:59 +0000 (06:36 +0900)]
ALSA: pcm: add a helper function to constrain mask-type parameters

Application of constraints to mask-type parameters for PCM substream is
done in a call of snd_pcm_hw_refine(), while the function includes much
codes and is not enough friendly to readers.

This commit splits the codes to a separated function so that readers can
get it easily. I leave desicion into compilers to merge the function into
its callee.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: firewire: arrange common PCM info/constraints for AMDTP engine applications
Takashi Sakamoto [Thu, 8 Jun 2017 00:11:03 +0000 (09:11 +0900)]
ALSA: firewire: arrange common PCM info/constraints for AMDTP engine applications

In ALSA firewire stack, 8 drivers uses IEC 61883-1/6 engine for data
transmission. They have common PCM info/constraints and duplicated codes.

This commit unifies the codes into fireiwre-lib.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: obsolete RULES_DEBUG local macro
Takashi Sakamoto [Tue, 6 Jun 2017 23:46:45 +0000 (08:46 +0900)]
ALSA: pcm: obsolete RULES_DEBUG local macro

Added tracepoints obsoleted RULES_DEBUG local macro and relevant codes.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: enable parameter tracepoints only when CONFIG_SND_DEBUG is enabled
Takashi Sakamoto [Tue, 6 Jun 2017 23:46:44 +0000 (08:46 +0900)]
ALSA: pcm: enable parameter tracepoints only when CONFIG_SND_DEBUG is enabled

In a previous commit, tracepoints are added for PCM parameter processing.
As long as I know, this implementation increases size of relocatable
object by 35%. For vendors who are conscious of memory footprint, it
brings apparent disadvantage.

This commit utilizes CONFIG_SND_DEBUG configuration to enable/disable the
tracepoints.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: tracepoints for refining PCM parameters
Takashi Sakamoto [Tue, 6 Jun 2017 23:46:43 +0000 (08:46 +0900)]
ALSA: pcm: tracepoints for refining PCM parameters

When working for devices which support configurable modes for its data
transmission or which consists of several components, developers are
likely to use rules of parameters of PCM substream. However, there's no
infrastructure to assist their work.

In old days, ALSA PCM core got a local 'RULES_DEBUG' macro to debug
refinement of parameters for PCM substream. Although this is merely a
makeshift. With some modifications, we get the infrastructure.

This commit is for the purpose. Refinement of mask/interval type of
PCM parameters is probed as tracepoint events as 'hw_mask_param' and
'hw_interval_param' on existent 'snd_pcm' subsystem.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: timer: Wrap with spinlock for queue access
Takashi Iwai [Fri, 2 Jun 2017 15:35:30 +0000 (17:35 +0200)]
ALSA: timer: Wrap with spinlock for queue access

For accessing the snd_timer_user queue indices, we take tu->qlock.
But it's forgotten in a couple of places.

The one in snd_timer_user_params() should be safe without the
spinlock as the timer is already stopped.  But it's better for
consistency.

The one in poll is just a read-out, so it's not inevitably needed, but
it'd be good to make the result consistent, too.

Tested-by: Alexander Potapenko <glider@google.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: timer: Improve user queue reallocation
Takashi Iwai [Fri, 2 Jun 2017 15:16:59 +0000 (17:16 +0200)]
ALSA: timer: Improve user queue reallocation

ALSA timer may reallocate the user queue upon request, and it happens
at three places for now: at opening, at SNDRV_TIMER_IOCTL_PARAMS, and
at SNDRV_TIMER_IOCTL_SELECT.  However, the last one,
snd_timer_user_tselect(), doesn't need to reallocate the buffer since
it doesn't change the queue size.  It does just because tu->tread
might have been changed before starting the timer.

Instead of *_SELECT ioctl, we should reallocate the queue at
SNDRV_TIMER_IOCTL_TREAD; then the timer is guaranteed to be stopped,
thus we can reassign the buffer more safely.

This patch implements that with a slight code refactoring.
Essentially, the patch achieves:
- Introduce realloc_user_queue() for (re-)allocating the ring buffer,
  and call it from all places.  Also, realloc_user_queue() uses
  kcalloc() for avoiding possible leaks.
- Add the buffer reallocation at SNDRV_TIMER_IOCTL_TREAD.  When it
  fails, tu->tread is restored to the old value, too.
- Drop the buffer reallocation at snd_timer_user_tselect().

Tested-by: Alexander Potapenko <glider@google.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoMerge branch 'for-linus' into for-next
Takashi Iwai [Wed, 7 Jun 2017 08:25:30 +0000 (10:25 +0200)]
Merge branch 'for-linus' into for-next

For applying more ALSA timer cleanups.

6 years agoALSA: timer: Fix missing queue indices reset at SNDRV_TIMER_IOCTL_SELECT
Takashi Iwai [Fri, 2 Jun 2017 15:26:56 +0000 (17:26 +0200)]
ALSA: timer: Fix missing queue indices reset at SNDRV_TIMER_IOCTL_SELECT

snd_timer_user_tselect() reallocates the queue buffer dynamically, but
it forgot to reset its indices.  Since the read may happen
concurrently with ioctl and snd_timer_user_tselect() allocates the
buffer via kmalloc(), this may lead to the leak of uninitialized
kernel-space data, as spotted via KMSAN:

  BUG: KMSAN: use of unitialized memory in snd_timer_user_read+0x6c4/0xa10
  CPU: 0 PID: 1037 Comm: probe Not tainted 4.11.0-rc5+ #2739
  Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
  Call Trace:
   __dump_stack lib/dump_stack.c:16
   dump_stack+0x143/0x1b0 lib/dump_stack.c:52
   kmsan_report+0x12a/0x180 mm/kmsan/kmsan.c:1007
   kmsan_check_memory+0xc2/0x140 mm/kmsan/kmsan.c:1086
   copy_to_user ./arch/x86/include/asm/uaccess.h:725
   snd_timer_user_read+0x6c4/0xa10 sound/core/timer.c:2004
   do_loop_readv_writev fs/read_write.c:716
   __do_readv_writev+0x94c/0x1380 fs/read_write.c:864
   do_readv_writev fs/read_write.c:894
   vfs_readv fs/read_write.c:908
   do_readv+0x52a/0x5d0 fs/read_write.c:934
   SYSC_readv+0xb6/0xd0 fs/read_write.c:1021
   SyS_readv+0x87/0xb0 fs/read_write.c:1018

This patch adds the missing reset of queue indices.  Together with the
previous fix for the ioctl/read race, we cover the whole problem.

Reported-by: Alexander Potapenko <glider@google.com>
Tested-by: Alexander Potapenko <glider@google.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: timer: Fix race between read and ioctl
Takashi Iwai [Fri, 2 Jun 2017 13:03:38 +0000 (15:03 +0200)]
ALSA: timer: Fix race between read and ioctl

The read from ALSA timer device, the function snd_timer_user_tread(),
may access to an uninitialized struct snd_timer_user fields when the
read is concurrently performed while the ioctl like
snd_timer_user_tselect() is invoked.  We have already fixed the races
among ioctls via a mutex, but we seem to have forgotten the race
between read vs ioctl.

This patch simply applies (more exactly extends the already applied
range of) tu->ioctl_lock in snd_timer_user_tread() for closing the
race window.

Reported-by: Alexander Potapenko <glider@google.com>
Tested-by: Alexander Potapenko <glider@google.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: fireface: constify ALSA specific operations
Takashi Sakamoto [Wed, 7 Jun 2017 00:38:06 +0000 (09:38 +0900)]
ALSA: fireface: constify ALSA specific operations

ALSA fireface driver has ALSA specific operations for MIDI/PCM data.
Structured data for the operations can be constified. Additionally,
The structured data can be function local.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: firewire: process packets in 'struct snd_pcm_ops.ack' callback
Takashi Sakamoto [Wed, 7 Jun 2017 00:38:05 +0000 (09:38 +0900)]
ALSA: firewire: process packets in 'struct snd_pcm_ops.ack' callback

In recent commit for ALSA PCM core, some arrangement is done for
'struct snd_pcm_ops.ack' callback. This is called when appl_ptr is
explicitly moved in intermediate buffer for PCM frames, except for
some cases described later.

For drivers in ALSA firewire stack, usage of this callback has a merit to
reduce latency between time of PCM frame queueing and handling actual
packets in recent isochronous cycle, because no need to wait for software
IRQ context from isochronous context of OHCI 1394.

If this works well in a case that mapped page frame is used for the
intermediate buffer, user process should execute some commands for ioctl(2)
to tell the number of handled PCM frames in the intermediate buffer just
after handling them. Therefore, at present, with a combination of below
conditions, this doesn't work as expected and user process should wait for
the software IRQ context as usual:
 - when ALSA PCM core judges page frame mapping is available for status
   data (struct snd_pcm_mmap_status) and control data
   (struct snd_pcm_mmap_control).
 - user process handles PCM frames by loop just with 'snd_pcm_mmap_begin()'
   and 'snd_pcm_mmap_commit()'.
 - user process uses PCM hw plugin in alsa-lib to operate I/O without
   'sync_ptr_ioctl' option.

Unfortunately, major use case include these three conditions.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoMerge tag 'asoc-fix-v4.12-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/broon...
Takashi Iwai [Tue, 6 Jun 2017 18:03:46 +0000 (20:03 +0200)]
Merge tag 'asoc-fix-v4.12-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound into for-linus

ASoC: Fixes for v4.12

This is the usual collection of device specific fixes, all accumilated
since the merge window, plus one fix from Takashi for a nasty use after
free bug that bit some things with deferred probe and an update to the
maintainer address for the former Wolfson parts.

6 years agoALSA: hda/realtek - Reorder ALC269 ASUS quirk entries
Takashi Iwai [Tue, 6 Jun 2017 10:33:17 +0000 (12:33 +0200)]
ALSA: hda/realtek - Reorder ALC269 ASUS quirk entries

A disorder is found in some ALC269 quirk entries for ASUS (1043:xxxx),
which should have been sorted in PCI SSID order.  Rearrange them, so
that I won't overlook the already existing entry like I did a couple
of times in the past...

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: hda/realtek: Fix mic and headset jack sense on Asus X705UD
Chris Chiu [Mon, 5 Jun 2017 21:05:30 +0000 (15:05 -0600)]
ALSA: hda/realtek: Fix mic and headset jack sense on Asus X705UD

The ASUS X705UD laptop requires the known fixup ALC256_FIXUP_ASUS_MIC
in order to fix headphone jack sensing and to enable use of the internal
microphone.

Unfortunately jack sensing for the headset mic is still not working.

[rearranged the position to keep the PCI SSID order -- tiwai]

Signed-off-by: Chris Chiu <chiu@endlessm.com>
Signed-off-by: Daniel Drake <drake@endlessm.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: doc: Update copy_user, copy_kernel and fill_silence PCM ops
Takashi Iwai [Thu, 1 Jun 2017 20:36:02 +0000 (22:36 +0200)]
ALSA: doc: Update copy_user, copy_kernel and fill_silence PCM ops

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: Build OSS writev/readv helpers conditionally
Takashi Iwai [Sun, 21 May 2017 17:08:57 +0000 (19:08 +0200)]
ALSA: pcm: Build OSS writev/readv helpers conditionally

The snd_pcm_oss_writev3() and snd_pcm_oss_readv3() are used only in
io.c with CONFIG_SND_PCM_OSS_PLUGINS=y.  Add an ifdef to reduce the
build of these functions.

Along with it, since they are called always for in-kernel copy, reduce
the argument and call snd_pcm_kernel_writev() and *_readv() directly
instead.

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: Kill set_fs() in PCM OSS layer
Takashi Iwai [Sun, 21 May 2017 08:14:42 +0000 (10:14 +0200)]
ALSA: pcm: Kill set_fs() in PCM OSS layer

This is the last-standing one: kill the set_fs() usage in PCM OSS
layer by replacing with the new API functions to deal with the direct
in-kernel buffer copying.

The code to fill the silence can be replaced even to a one-liner to
pass NULL buffer instead of the manual copying.

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agousb: gadget: u_uac1: Kill set_fs() usage
Takashi Iwai [Sun, 21 May 2017 08:19:16 +0000 (10:19 +0200)]
usb: gadget: u_uac1: Kill set_fs() usage

With the new API to perform the in-kernel buffer copy, we can get rid
of set_fs() usage in this driver, finally.

Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: Direct in-kernel read/write support
Takashi Iwai [Wed, 24 May 2017 16:23:20 +0000 (18:23 +0200)]
ALSA: pcm: Direct in-kernel read/write support

Now all materials are ready, let's allow the direct in-kernel
read/write, i.e. a kernel-space buffer is passed for read or write,
instead of the normal user-space buffer.  This feature is used by OSS
layer and UAC1 driver, for example.

The __snd_pcm_lib_xfer() takes in_kernel argument that indicates the
in-kernel buffer copy.  When this flag is set, another transfer code
is used.  It's either via copy_kernel PCM ops or the normal memcpy(),
depending on the driver setup.

As external API, snd_pcm_kernel_read(), *_write() and other variants
are provided.

That's all.  This support is really simple because of the code
refactoring until now.

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: Simplify snd_pcm_playback_silence()
Takashi Iwai [Wed, 24 May 2017 16:18:15 +0000 (18:18 +0200)]
ALSA: pcm: Simplify snd_pcm_playback_silence()

Use the existing silence helper codes for simplification.

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: Unify read/write loop
Takashi Iwai [Wed, 24 May 2017 20:36:23 +0000 (22:36 +0200)]
ALSA: pcm: Unify read/write loop

Both __snd_pcm_lib_read() and __snd_pcm_write() functions have almost
the same code to loop over samples.  For simplification, this patch
unifies both as the single helper, __snd_pcm_lib_xfer().

Other than that, there should be no functional change by this patch.

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: More unification of PCM transfer codes
Takashi Iwai [Wed, 24 May 2017 16:15:26 +0000 (18:15 +0200)]
ALSA: pcm: More unification of PCM transfer codes

This patch proceeds more abstraction of PCM read/write loop codes.

For both interleaved and non-interleaved transfers, the same copy or
silence transfer code (which is defined as pcm_transfer_f) is used
now.  This became possible since we switched to byte size to copy_*
and fill_silence ops argument instead of frames.

And, for both read and write, we can use the same copy function (which
is defined as pcm_copy_f), just depending on whether interleaved or
non-interleaved mode.

The transfer function is determined at the beginning of the loop,
depending on whether the driver gives the specific copy ops or it's
the standard read/write.

Another bonus by this change is that we now guarantee the silencing
behavior when NULL buffer is passed to write helpers.  It'll simplify
some codes later.

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: Call directly the common read/write helpers
Takashi Iwai [Sun, 21 May 2017 07:35:21 +0000 (09:35 +0200)]
ALSA: pcm: Call directly the common read/write helpers

Make snd_pcm_lib_read() and *_write() static inline functions that
call the common helper functions directly.  This reduces a slight
amount of codes, and at the same time, it's a preparation for the
further cleanups / fixes.

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: Shuffle codes
Takashi Iwai [Wed, 24 May 2017 15:59:17 +0000 (17:59 +0200)]
ALSA: pcm: Shuffle codes

Just shuffle the codes, without any change otherwise.

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: Check PCM state by a common helper function
Takashi Iwai [Wed, 24 May 2017 15:51:30 +0000 (17:51 +0200)]
ALSA: pcm: Check PCM state by a common helper function

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: pcm: Drop the old copy and silence ops
Takashi Iwai [Wed, 10 May 2017 20:21:52 +0000 (22:21 +0200)]
ALSA: pcm: Drop the old copy and silence ops

Now that all users of old copy and silence ops have been converted to
the new PCM ops, the old stuff can be retired and go away.

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years ago[media] solo6x10: Convert to the new PCM ops
Takashi Iwai [Wed, 10 May 2017 20:20:10 +0000 (22:20 +0200)]
[media] solo6x10: Convert to the new PCM ops

Replace the copy and the silence ops with the new PCM ops.
The device supports only 1 channel and 8bit sample, so it's always
bytes=frames, and we need no conversion of unit in the callback.
Also, it's a capture stream, thus no silence is needed.

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoASoC: blackfin: Convert to the new PCM ops
Takashi Iwai [Wed, 10 May 2017 19:59:12 +0000 (21:59 +0200)]
ASoC: blackfin: Convert to the new PCM ops

Replace the copy and the silence ops with the new PCM ops.
In AC97 and I2S-TDM mode, we need to convert back to frames, but
otherwise the conversion is pretty straightforward.

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Acked-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: sh: Convert to the new PCM ops
Takashi Iwai [Wed, 10 May 2017 19:57:16 +0000 (21:57 +0200)]
ALSA: sh: Convert to the new PCM ops

Replace the copy and the silence ops with the new PCM ops.
Fixed also the user-space buffer copy with the proper
copy_from_user*() variant.

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: sb: Convert to the new PCM ops
Takashi Iwai [Wed, 10 May 2017 18:34:45 +0000 (20:34 +0200)]
ALSA: sb: Convert to the new PCM ops

Replace the copy and the silence ops with the new PCM ops.
For avoiding the code redundancy, slightly hackish macros are
introduced.

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: gus: Convert to the new PCM ops
Takashi Iwai [Wed, 10 May 2017 18:33:05 +0000 (20:33 +0200)]
ALSA: gus: Convert to the new PCM ops

Replace the copy and the silence ops with the new PCM ops.
For simplifying the code a bit, two local helpers are introduced here:
get_bpos() and playback_copy_ack().

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: hdsp: Convert to the new PCM ops
Takashi Iwai [Wed, 10 May 2017 18:32:25 +0000 (20:32 +0200)]
ALSA: hdsp: Convert to the new PCM ops

Replace the copy and the silence ops with the new PCM ops.
The conversion is straightforward with standard helper functions.

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: rme9652: Convert to the new PCM ops
Takashi Iwai [Wed, 10 May 2017 18:31:41 +0000 (20:31 +0200)]
ALSA: rme9652: Convert to the new PCM ops

Replace the copy and the silence ops with the new PCM ops.
The conversion is straightforward with standard helper functions.

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: rme96: Convert to the new PCM ops
Takashi Iwai [Wed, 10 May 2017 18:30:34 +0000 (20:30 +0200)]
ALSA: rme96: Convert to the new PCM ops

Replace the copy and the silence ops with the new PCM ops.
The conversion is straightforward with standard helper functions, and
now we can drop the bytes <-> frames conversions in callbacks.

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
6 years agoALSA: rme32: Convert to the new PCM copy ops
Takashi Iwai [Wed, 10 May 2017 18:29:25 +0000 (20:29 +0200)]
ALSA: rme32: Convert to the new PCM copy ops

Replace the copy and the silence ops with the new ops.
The conversion is straightforward with standard helper functions, and
now we can drop the bytes <-> frames conversions in callbacks.

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