07 Oct, 2020

1 commit


07 Aug, 2020

1 commit

  • Pull sound updates from Takashi Iwai:
    "This became wide and scattered updates all over the sound tree as
    diffstat shows: lots of (still ongoing) refactoring works in ASoC,
    fixes and cleanups caught by static analysis, inclusive term
    conversions as well as lots of new drivers. Below are highlights:

    ASoC core:
    - API cleanups and conversions to the unified mute_stream() call
    - Simplify I/O helper functions
    - Use helper macros to retrieve RTD from substreams

    ASoC drivers:
    - Lots of fixes and cleanups in Intel ASoC drivers
    - Lots of new stuff: Freescale MQS and i.MX6sx, Intel KeemBay I2S,
    Maxim MAX98360A and MAX98373 SoundWire, various Mediatek boards,
    nVidia Tegra 186 and 210, RealTek RL6231, Samsung Midas and Aries
    boards, TI J721e EVM

    ALSA core:
    - Minor code refacotring for SG-buffer handling

    HD-audio:
    - Generalization of mute-LED handling with LED classdev
    - Intel silent stream support for HDMI
    - Device-specific fixes: CA0132, Loongson-3

    Others:
    - Usual USB- and HD-audio quirks for various devices
    - Fixes for echoaudio DMA position handling
    - Various documents and trivial fixes for sparse warnings
    - Conversion to adopt inclusive terms"

    * tag 'sound-5.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound: (479 commits)
    ALSA: pci: delete repeated words in comments
    ALSA: isa: delete repeated words in comments
    ALSA: hda/tegra: Add 100us dma stop delay
    ALSA: hda: Add dma stop delay variable
    ASoC: hda/tegra: Set buffer alignment to 128 bytes
    ALSA: seq: oss: Serialize ioctls
    ALSA: hda/hdmi: Add quirk to force connectivity
    ALSA: usb-audio: add startech usb audio dock name
    ALSA: usb-audio: Add support for Lenovo ThinkStation P620
    Revert "ALSA: hda: call runtime_allow() for all hda controllers"
    ALSA: hda/ca0132 - Fix AE-5 microphone selection commands.
    ALSA: hda/ca0132 - Add new quirk ID for Recon3D.
    ALSA: hda/ca0132 - Fix ZxR Headphone gain control get value.
    ALSA: hda/realtek: Add alc269/alc662 pin-tables for Loongson-3 laptops
    ALSA: docs: fix typo
    ALSA: doc: use correct config variable name
    ASoC: core: Two step component registration
    ASoC: core: Simplify snd_soc_component_initialize declaration
    ASoC: core: Relocate and expose snd_soc_component_initialize
    ASoC: sh: Replace 'select' DMADEVICES 'with depends on'
    ...

    Linus Torvalds
     

05 Aug, 2020

1 commit

  • Pull uninitialized_var() macro removal from Kees Cook:
    "This is long overdue, and has hidden too many bugs over the years. The
    series has several "by hand" fixes, and then a trivial treewide
    replacement.

    - Clean up non-trivial uses of uninitialized_var()

    - Update documentation and checkpatch for uninitialized_var() removal

    - Treewide removal of uninitialized_var()"

    * tag 'uninit-macro-v5.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux:
    compiler: Remove uninitialized_var() macro
    treewide: Remove uninitialized_var() usage
    checkpatch: Remove awareness of uninitialized_var() macro
    mm/debug_vm_pgtable: Remove uninitialized_var() usage
    f2fs: Eliminate usage of uninitialized_var() macro
    media: sur40: Remove uninitialized_var() usage
    KVM: PPC: Book3S PR: Remove uninitialized_var() usage
    clk: spear: Remove uninitialized_var() usage
    clk: st: Remove uninitialized_var() usage
    spi: davinci: Remove uninitialized_var() usage
    ide: Remove uninitialized_var() usage
    rtlwifi: rtl8192cu: Remove uninitialized_var() usage
    b43: Remove uninitialized_var() usage
    drbd: Remove uninitialized_var() usage
    x86/mm/numa: Remove uninitialized_var() usage
    docs: deprecated.rst: Add uninitialized_var()

    Linus Torvalds
     

03 Aug, 2020

1 commit


28 Jul, 2020

1 commit


17 Jul, 2020

1 commit

  • Using uninitialized_var() is dangerous as it papers over real bugs[1]
    (or can in the future), and suppresses unrelated compiler warnings
    (e.g. "unused variable"). If the compiler thinks it is uninitialized,
    either simply initialize the variable or make compiler changes.

    In preparation for removing[2] the[3] macro[4], remove all remaining
    needless uses with the following script:

    git grep '\buninitialized_var\b' | cut -d: -f1 | sort -u | \
    xargs perl -pi -e \
    's/\buninitialized_var\(([^\)]+)\)/\1/g;
    s:\s*/\* (GCC be quiet|to make compiler happy) \*/$::g;'

    drivers/video/fbdev/riva/riva_hw.c was manually tweaked to avoid
    pathological white-space.

    No outstanding warnings were found building allmodconfig with GCC 9.3.0
    for x86_64, i386, arm64, arm, powerpc, powerpc64le, s390x, mips, sparc64,
    alpha, and m68k.

    [1] https://lore.kernel.org/lkml/20200603174714.192027-1-glider@google.com/
    [2] https://lore.kernel.org/lkml/CA+55aFw+Vbj0i=1TGqCR5vQkCzWJ0QxK6CernOU6eedsudAixw@mail.gmail.com/
    [3] https://lore.kernel.org/lkml/CA+55aFwgbgqhbp1fkxvRKEpzyR5J8n1vKT1VZdz9knmPuXhOeg@mail.gmail.com/
    [4] https://lore.kernel.org/lkml/CA+55aFz2500WfbKXAx8s67wrm9=yVJu65TpLgN_ybYNv0VEOKA@mail.gmail.com/

    Reviewed-by: Leon Romanovsky # drivers/infiniband and mlx4/mlx5
    Acked-by: Jason Gunthorpe # IB
    Acked-by: Kalle Valo # wireless drivers
    Reviewed-by: Chao Yu # erofs
    Signed-off-by: Kees Cook

    Kees Cook
     

01 Jul, 2020

2 commits

  • Replace several occurences of "frame" with a "packet" where appropriate.

    Signed-off-by: Alexander Tsoy
    Link: https://lore.kernel.org/r/20200629025934.154288-2-alexander@tsoy.me
    Signed-off-by: Takashi Iwai

    Alexander Tsoy
     
  • Commit f0bd62b64016 ("ALSA: usb-audio: Improve frames size computation")
    introduced a regression for devices which have playback endpoints with
    bInterval > 1. Fix this by taking ep->datainterval into account.

    Note that frame and fps are actually mean packet and packets per second
    in the code introduces by the mentioned commit. This will be fixed in a
    follow-up patch.

    Fixes: f0bd62b64016 ("ALSA: usb-audio: Improve frames size computation")
    BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=208353
    Signed-off-by: Alexander Tsoy
    Link: https://lore.kernel.org/r/20200629025934.154288-1-alexander@tsoy.me
    Signed-off-by: Takashi Iwai

    Alexander Tsoy
     

16 May, 2020

1 commit

  • For USB sound devices using implicit feedback the endpoint used for
    this feedback should be able to be opened twice, once for required
    feedback and second time for audio data. This way these devices can be
    put in duplex audio mode. Since this only works if the settings of the
    endpoint don't change a check is included for this.

    This fixes bug 207023 ("MOTU M2 regression on duplex audio") and
    should also fix bug 103751 ("M-Audio Fast Track Ultra usb audio device
    will not operate full-duplex")

    Fixes: c249177944b6 ("ALSA: usb-audio: add implicit fb quirk for MOTU M Series")
    Signed-off-by: Erwin Burema
    BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=207023
    BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=103751
    Link: https://lore.kernel.org/r/2410739.SCZni40SNb@alpha-wolf
    Signed-off-by: Takashi Iwai

    Erwin Burema
     

24 Apr, 2020

2 commits

  • The linked list entry from FIFO is peeked at
    queue_pending_output_urbs() but the actual element pop-out is
    performed outside the spinlock, and it's potentially racy.

    Do delete the link at the right place inside the spinlock.

    Fixes: 8fdff6a319e7 ("ALSA: snd-usb: implement new endpoint streaming model")
    Link: https://lore.kernel.org/r/20200424074016.14301-1-tiwai@suse.de
    Signed-off-by: Takashi Iwai

    Takashi Iwai
     
  • For computation of the the next frame size current value of fs/fps and
    accumulated fractional parts of fs/fps are used, where values are stored
    in Q16.16 format. This is quite natural for computing frame size for
    asynchronous endpoints driven by explicit feedback, since in this case
    fs/fps is a value provided by the feedback endpoint and it's already in
    the Q format. If an error is accumulated over time, the device can
    adjust fs/fps value to prevent buffer overruns/underruns.

    But for synchronous endpoints the accuracy provided by these computations
    is not enough. Due to accumulated error the driver periodically produces
    frames with incorrect size (+/- 1 audio sample).

    This patch fixes this issue by implementing a different algorithm for
    frame size computation. It is based on accumulating of the remainders
    from division fs/fps and it doesn't accumulate errors over time. This
    new method is enabled for synchronous and adaptive playback endpoints.

    Signed-off-by: Alexander Tsoy
    Link: https://lore.kernel.org/r/20200424022449.14972-1-alexander@tsoy.me
    Signed-off-by: Takashi Iwai

    Alexander Tsoy
     

13 Nov, 2019

1 commit

  • While output urb's snd_complete_urb() is executing, calling
    prepare_outbound_urb() may cause endpoint stopped before
    prepare_outbound_urb() returns and result in next urb submitted
    to stopped endpoint. usb-audio driver cannot re-use it afterwards as
    the urb is still hold by usb stack.

    This change checks EP_FLAG_RUNNING flag after prepare_outbound_urb() again
    to let snd_complete_urb() know the endpoint already stopped and does not
    submit next urb. Below kind of error will be fixed:

    [ 213.153103] usb 1-2: timeout: still 1 active urbs on EP #1
    [ 213.164121] usb 1-2: cannot submit urb 0, error -16: unknown error

    Signed-off-by: Henry Lin
    Cc:
    Link: https://lore.kernel.org/r/20191113021420.13377-1-henryl@nvidia.com
    Signed-off-by: Takashi Iwai

    Henry Lin
     

31 May, 2019

1 commit

  • 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 either version 2 of the license or at
    your option any later version this program is distributed in the
    hope that it will be useful but without any warranty without even
    the implied warranty of merchantability or fitness for a particular
    purpose see the gnu general public license for more details you
    should have received a copy of the gnu general public license along
    with this program if not write to the free software foundation inc
    59 temple place suite 330 boston ma 02111 1307 usa

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-or-later

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

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Allison Randal
    Reviewed-by: Richard Fontana
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190527070033.113240726@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

01 Aug, 2018

1 commit


05 Jan, 2017

2 commits

  • Testing EP_FLAG_RUNNING in snd_complete_urb() before running the completion
    logic allows us to save a few cpu cycles by returning early, skipping the
    pending urb in case the stream was stopped; the stop logic handles the urb
    and sets the completion callbacks to NULL.

    Signed-off-by: Ioan-Adrian Ratiu
    Signed-off-by: Takashi Iwai

    Ioan-Adrian Ratiu
     
  • Commit 16200948d83 ("ALSA: usb-audio: Fix race at stopping the stream") was
    incomplete causing another more severe kernel panic, so it got reverted.
    This fixes both the original problem and its fallout kernel race/crash.

    The original fix is to move the endpoint member NULL clearing logic inside
    wait_clear_urbs() so the irq triggering the urb completion doesn't call
    retire_capture/playback_urb() after the NULL clearing and generate a panic.

    However this creates a new race between snd_usb_endpoint_start()'s call
    to wait_clear_urbs() and the irq urb completion handler which again calls
    retire_capture/playback_urb() leading to a new NULL dereference.

    We keep the EP deactivation code in snd_usb_endpoint_start() because
    removing it will break the EP reference counting (see [1] [2] for info),
    however we don't need the "can_sleep" mechanism anymore because a new
    function was introduced (snd_usb_endpoint_sync_pending_stop()) which
    synchronizes pending stops and gets called inside the pcm prepare callback.

    It also makes sense to remove can_sleep because it was also removed from
    deactivate_urbs() signature in [3] so we benefit from more simplification.

    [1] commit 015618b90 ("ALSA: snd-usb: Fix URB cancellation at stream start")
    [2] commit e9ba389c5 ("ALSA: usb-audio: Fix scheduling-while-atomic bug in PCM capture stream")
    [3] commit ccc1696d5 ("ALSA: usb-audio: simplify endpoint deactivation code")

    Fixes: f8114f8583bb ("Revert "ALSA: usb-audio: Fix race at stopping the stream"")

    Signed-off-by: Ioan-Adrian Ratiu
    Signed-off-by: Takashi Iwai

    Ioan-Adrian Ratiu
     

22 Dec, 2016

1 commit

  • This reverts commit 16200948d8353fe29a473a394d7d26790deae0e7.

    The commit was intended to cover the race condition, but it introduced
    yet another regression for devices with the implicit feedback, leading
    to a kernel panic due to NULL-dereference in an irq context.

    As the race condition that was addressed by the commit is very rare
    and the regression is much worse, let's revert the commit for rc1, and
    fix the issue properly in a later patch.

    Fixes: 16200948d835 ("ALSA: usb-audio: Fix race at stopping the stream")
    Reported-by: Ioan-Adrian Ratiu
    Cc:
    Signed-off-by: Takashi Iwai
    Signed-off-by: Linus Torvalds

    Takashi Iwai
     

13 Dec, 2016

1 commit

  • [Problem]
    In some USB DACs, a terrible pop noise comes to be heard
    at the start of DSD playback (in the following situations).

    - play first DSD track
    - change from PCM track to DSD track
    - change from DSD64 track to DSD128 track (and etc...)
    - seek DSD track
    - Fast-Forward/Rewind DSD track

    [Cause]
    At the start of playback, there is a little silence.
    The silence bit pattern "0x69" is required on DSD mode,
    but it is not like that.

    [Solution]
    This patch adds DSD silence pattern to the endpoint settings.

    Signed-off-by: Nobutaka Okabe
    Signed-off-by: Takashi Iwai

    Nobutaka Okabe
     

09 Dec, 2016

1 commit


06 Dec, 2016

1 commit

  • since commit 57e6dae1087b ("ALSA: usb-audio: do not trust too-big
    wMaxPacketSize values"), the expected packetsize is always limited
    to nominal + 25%. It was discovered, that some devices (Android audio
    accessory) have a much higher jitter in used packetsizes than 25%
    which would result in BABBLE condition and dropping of packets.
    A better solution is so assume the jitter to be the nominal packetsize:
    -one nearly empty packet followed by a almost 150% sized one.

    V2: changed to assume max frequency is +50 of nominal packetsize.

    Signed-off-by: Andreas Pape
    Signed-off-by: Jiada Wang
    Acked-by: Clemens Ladisch
    Signed-off-by: Takashi Iwai

    Andreas Pape
     

05 Dec, 2016

1 commit

  • We've got a kernel crash report showing like:

    Unable to handle kernel NULL pointer dereference at virtual address 00000008 pgd = a1d7c000
    [00000008] *pgd=31c93831, *pte=00000000, *ppte=00000000
    Internal error: Oops: 17 [#1] PREEMPT SMP ARM
    CPU: 0 PID: 250 Comm: dbus-daemon Not tainted 3.14.51-03479-gf50bdf4 #1
    task: a3ae61c0 ti: a08c8000 task.ti: a08c8000
    PC is at retire_capture_urb+0x10/0x1f4 [snd_usb_audio]
    LR is at snd_complete_urb+0x140/0x1f0 [snd_usb_audio]
    pc : [] lr : [] psr: 200e0193
    sp : a08c9c98 ip : a08c9ce8 fp : a08c9ce4
    r10: 0000000a r9 : 00000102 r8 : 94cb3000
    r7 : 94cb3000 r6 : 94d0f000 r5 : 94d0e8e8 r4 : 94d0e000
    r3 : 7f0eb21c r2 : 00000000 r1 : 94cb3000 r0 : 00000000
    Flags: nzCv IRQs off FIQs on Mode SVC_32 ISA ARM Segment user
    Control: 10c5387d Table: 31d7c04a DAC: 00000015
    Process dbus-daemon (pid: 250, stack limit = 0xa08c8238)
    Stack: (0xa08c9c98 to 0xa08ca000)
    ...
    Backtrace:
    [] (retire_capture_urb [snd_usb_audio]) from [] (snd_complete_urb+0x140/0x1f0 [snd_usb_audio])
    [] (snd_complete_urb [snd_usb_audio]) from [] (__usb_hcd_giveback_urb+0x78/0xf4)
    [] (__usb_hcd_giveback_urb) from [] (usb_giveback_urb_bh+0x8c/0xc0)
    [] (usb_giveback_urb_bh) from [] (tasklet_hi_action+0xc4/0x148)
    [] (tasklet_hi_action) from [] (__do_softirq+0x190/0x380)
    [] (__do_softirq) from [] (irq_exit+0x8c/0xfc)
    [] (irq_exit) from [] (handle_IRQ+0x8c/0xc8)
    [] (handle_IRQ) from [] (gic_handle_irq+0xbc/0xf8)
    [] (gic_handle_irq) from [] (__irq_svc+0x44/0x78)
    [] (_raw_spin_unlock_irq) from [] (finish_task_switch+0x5c/0x100)
    [] (finish_task_switch) from [] (__schedule+0x48c/0x6d8)
    [] (__schedule) from [] (schedule+0x98/0x9c)
    [] (schedule) from [] (do_work_pending+0x30/0xd0)
    [] (do_work_pending) from [] (work_pending+0xc/0x20)
    Code: e1a0c00d e92ddff0 e24cb004 e24dd024 (e5902008)
    Kernel panic - not syncing: Fatal exception in interrupt

    There is a race between retire_capture_urb() and stop_endpoints().
    The latter is called at stopping the stream and it sets some endpoint
    fields to NULL. But its call is asynchronous, thus the pending
    complete callback might get called after these NULL clears, and it
    leads the NULL dereference like the above.

    The fix is to move the NULL clearance after the synchronization,
    i.e. wait_clear_urbs(). This is called at prepare and hw_free
    callbacks, so it's assured to be called before the restart of the
    stream or the release of the stream.

    Also, while we're at it, put the EP_FLAG_RUNNING flag check at the
    beginning of snd_complete_urb() to skip the pending complete after the
    stream is stopped.

    Fixes: b2eb950de2f0 ("ALSA: usb-audio: stop both data and sync...")
    Reported-by: Jiada Wang
    Reported-by: Mark Craske
    Cc:
    Signed-off-by: Takashi Iwai

    Takashi Iwai
     

22 Aug, 2016

3 commits

  • Users of devices affected by the Tenor feedback data error report
    buffer underruns, even with the +/- 0x1.0000 quirk applied.
    Compensating the error with 0xf000 instead seems to reliably fix
    that issue.

    See

    https://sourceforge.net/p/alsa/mailman/message/35230259/

    Reported-and-tested-by: Norman Nolte
    Reported-and-tested-by: Thomas Gresens
    Signed-off-by: Daniel Mack
    Signed-off-by: Takashi Iwai

    Daniel Mack
     
  • The quirk seems to be necessary not only for TEAC UD-H01 devices, but to
    more that are based on the Tenor 8802TL chipset. Devices built by T+A
    are affected too, and they apparently all use the same USB PID:PID.

    Extend the quirky handling for that device as well, and rename the
    quirks flag.

    Reported-and-tested-by: Thomas Gresens
    Signed-off-by: Daniel Mack
    Signed-off-by: Takashi Iwai

    Daniel Mack
     
  • That's a quirk, after all, so move it where to all the other quirks
    live.

    Signed-off-by: Daniel Mack
    Signed-off-by: Takashi Iwai

    Daniel Mack
     

16 Mar, 2016

1 commit

  • Add some sanity check codes before actually accessing the endpoint via
    get_endpoint() in order to avoid the invalid access through a
    malformed USB descriptor. Mostly just checking bNumEndpoints, but in
    one place (snd_microii_spdif_default_get()), the validity of iface and
    altsetting index is checked as well.

    Bugzilla: https://bugzilla.suse.com/show_bug.cgi?id=971125
    Cc:
    Signed-off-by: Takashi Iwai

    Takashi Iwai
     

19 Oct, 2015

3 commits

  • For the Zoom R16/24 (tx_length_quirk set), when calculating the maximum
    sample frequency, consideration must be made for the fact that four bytes
    of the packet contain a length descriptor and consequently must not be
    counted as part of the audio data.

    This is corroborated by the wMaxPacketSize for this device, which is 108
    bytes according for the USB playback endpoint descriptor. The frame size
    is 8 bytes (2 channels of 4 bytes each), and the 108 bytes thus work out
    as 13 * 8 + 4, i.e. corresponding to 13 frames plus the additional 4 byte
    length descriptor.

    Signed-off-by: Ricard Wanderlof
    Signed-off-by: Takashi Iwai

    Ricard Wanderlof
     
  • The Zoom R16/24 have a nonstandard playback format where each isochronous
    packet contains a length descriptor in the first four bytes. (Curiously,
    capture data does not contain this and requires no quirk.)

    The quirk involves adding the extra length descriptor whenever outgoing
    isochronous packets are generated, both in pcm.c (outgoing audio) and
    endpoint.c (silent data).

    In order to make the quirk as unintrusive as possible, for
    pcm.c:prepare_playback_urb(), the isochronous packet descriptors are
    initially set up in the same way no matter if the quirk is enabled or not.
    Once it is time to actually copy the data into the outgoing packet buffer
    (together with the added length descriptors) the isochronous descriptors
    are adjusted in order take the increased payload length into account.

    For endpoint.c:prepare_silent_urb() it makes more sense to modify the
    actual function, partly because the function is less complex to start with
    and partly because it is not as time-critical as prepare_playback_urb()
    (whose bulk is run with interrupts disabled), so the (minute) additional
    time spent in the non-quirk case is motivated by the simplicity of having
    a single function for all cases.

    The quirk is controlled by the new tx_length_quirk member in struct
    snd_usb_substream and struct snd_usb_audio, which is conveyed to pcm.c
    and endpoint.c from quirks.c in a similar manner to the txfr_quirk member
    in the same structs.

    In contrast to txfr_quirk however, the quirk is enabled directly in
    quirks.c:create_standard_audio_quirk() by checking the USB ID in that
    function. Another option would be to introduce a new
    QUIRK_AUDIO_ZOOM_INTERFACE or somesuch, which would have made the quirk
    very plain to see in the quirk table, but it was felt that the additional
    code needed to implement it this way would just make the implementation
    more complex with no real gain.

    Tested with a Zoom R16, both by doing capture and playback separately
    using arecord and aplay (8 channel capture and 2 channel playback,
    respectively), as well as capture and playback together using Ardour, as
    well as Audacity and Qtractor together with jackd.

    The R24 is reportedly compatible with the R16 when used as an audio
    interface. Both devices share the same USB ID and have the same number of
    inputs (8) and outputs (2). Therefore "R16/24" is mentioned throughout the
    patch.

    Regression tested using an Edirol UA-5 in both class compliant (16-bit)
    and "advanced" (24 bit, forces the use of quirks) modes.

    Signed-off-by: Ricard Wanderlof
    Tested-by: Panu Matilainen
    Signed-off-by: Takashi Iwai

    Ricard Wanderlof
     
  • Refactoring in preparation for adding Zoom R16/24 quirk.
    No functional change.

    Signed-off-by: Ricard Wanderlof
    Signed-off-by: Takashi Iwai

    Ricard Wanderlof
     

13 Oct, 2015

1 commit

  • Rounding must take place before multiplication with the frame size, since
    each packet contains a whole number of frames.

    We must also properly consider the data interval, as a larger data
    interval will result in larger packets, which, depending on the sampling
    frequency, can result in packet sizes that are less than integral
    multiples of the packet size for a lower data interval.

    Detailed explanation and rationale:

    The code before this commit had the following expression on line 613 to
    calculate the maximum isochronous packet size:

    maxsize = ((ep->freqmax + 0xffff) * (frame_bits >> 3))
    >> (16 - ep->datainterval);

    Here, ep->freqmax is the maximum assumed sample frequency, calculated from the
    nominal sample frequency plus 25%. It is ultimately derived from ep->freqn,
    which is in the units of frames per packet, from get_usb_full_speed_rate()
    or usb_high_speed_rate(), as applicable, in Q16.16 format.

    The expression essentially adds the Q16.16 equivalent of 0.999... (i.e.
    the largest number less than one) to the sample rate, in order to get a
    rate whose integer part is rounded up from the fractional value. The
    multiplication with (frame_bits >> 3) yields the number of bytes in a
    packet, and the (16 >> ep->datainterval) then converts it from Q16.16 back
    to an integer, taking into consideration the bDataInterval field of the
    endpoint descriptor (which describes how often isochronous packets are
    transmitted relative to the (micro)frame rate (125us or 1ms, for USB high
    speed and full speed, respectively)). For this discussion we will initially
    assume a bDataInterval of 0, so the second line of the expression just
    converts the Q16.16 value to an integer.

    In order to illustrate the problem, we will set frame_bits 64, which
    corresponds to a frame size of 8 bytes.

    The problem here is twofold. First, the rounding operation consists
    of the addition of 0x0.ffff and subsequent conversion to integer, but as the
    expression stands, the conversion to integer is done after multiplication
    with the frame size, rather than before. This results in the resulting
    maxsize becoming too large.

    Let's take an example. We have a sample rate of 96 kHz, so our ep->freqn is
    0xc0000 (see usb_high_speed_rate()). Add 25% (line 612) and we get 0xf0000.
    The calculated maxsize is then ((0xf0000 + 0x0ffff) * 8) >> 16 = 127 .
    However, if we do the number of bytes calculation in a less obscure way it's
    more apparent what the true corresponding packet size is: we get
    ceil(96000 * 1.25 / 8000) * 8 = 120, where 1.25 is the 25% from line 612,
    and the 8000 is the number of isochronous packets per second on a high
    speed USB connection (125 us microframe interval).

    This is fixed by performing the complete rounding operation prior to
    multiplication with the frame rate.

    The second problem is that when considering the ep->datainterval, this
    must be done before rounding, in order to take the advantage of the fact
    that if the number of bytes per packet is not an integer, the resulting
    rounded-up integer is not necessarily a factor of two when the data
    interval is increased by the same factor.

    For instance, assuming a freqency of 41 kHz, the resulting
    bytes-per-packet value for USB high speed is 41 kHz / 8000 = 5.125, or
    0x52000 in Q16.16 format. With a data interval of 1 (ep->datainterval = 0),
    this means that 6 frames per packet are needed, whereas with a data
    interval of 2 we need 10.25, i.e. 11 frames needed.

    Rephrasing the maxsize expression to:

    maxsize = (((ep->freqmax << ep->datainterval) + 0xffff) >> 16) *
    (frame_bits >> 3);

    for the above 96 kHz example we instead get
    ((0xf0000 + 0xffff) >> 16) * 8 = 120 which is the correct value.

    We can also do the calculation with a non-integer sample rate which is when
    rounding comes into effect: say we have 44.1 kHz (resulting ep->freqn =
    0x58333, and resulting ep->freqmax 0x58333 * 1.25 = 0x6e3ff (rounded down)):

    Original maxsize = ((0x6e3ff + 0xffff) * 8) << 16 = 63 (63.124.. rounded down)
    True maxsize = ceil(44100 * 1.25 / 8000) * 8 = 7 * 8 = 56
    New maxsize = ((0x6e3ff + 0xffff) >> 16) * 8 = 7 * 8 = 56

    This is also corroborated by the wMaxPacketSize check on line 616. Assume
    that wMaxPacketSize = 104, with ep->maxpacksize then having the same value.
    As 104 < 127, we get maxsize = 104. ep->freqmax is then recalculated to
    (104 / 8) << 16 = 0xd0000 . Putting that rate into the original maxsize
    calculation yields a maxsize of ((0xd0000 + 0xffff) * 8) >> 16 = 111
    (with decimals 111.99988). Clearly, we should get back the 104 here,
    which we would with the new expression: ((0xd0000 + 0xffff) >> 16) * 8 = 104 .

    (The error has not been a problem because it only results in maxsize being
    a bit too big which just wastes a couple of bytes, either as a result of
    the first maxsize calculation, or because the resulting calculation will
    hit the wMaxPacketSize value before the packet is too big, resulting in
    fixing the size to wMaxPacketSize even though the packet is actually not
    too long.)

    Tested with an Edirol UA-5 both at 44.1 kHz and 96 kHz.

    Signed-off-by: Ricard Wanderlof
    Signed-off-by: Takashi Iwai

    Ricard Wanderlof
     

26 Aug, 2015

1 commit

  • After the recent fix of runtime PM for USB-audio driver, we got a
    lockdep warning like:

    =============================================
    [ INFO: possible recursive locking detected ]
    4.2.0-rc8+ #61 Not tainted
    ---------------------------------------------
    pulseaudio/980 is trying to acquire lock:
    (&chip->shutdown_rwsem){.+.+.+}, at: [] snd_usb_autoresume+0x1d/0x52 [snd_usb_audio]
    but task is already holding lock:
    (&chip->shutdown_rwsem){.+.+.+}, at: [] snd_usb_autoresume+0x1d/0x52 [snd_usb_audio]

    This comes from snd_usb_autoresume() invoking down_read() and it's
    used in a nested way. Although it's basically safe, per se (as these
    are read locks), it's better to reduce such spurious warnings.

    The read lock is needed to guarantee the execution of "shutdown"
    (cleanup at disconnection) task after all concurrent tasks are
    finished. This can be implemented in another better way.

    Also, the current check of chip->in_pm isn't good enough for
    protecting the racy execution of multiple auto-resumes.

    This patch rewrites the logic of snd_usb_autoresume() & co; namely,
    - The recursive call of autopm is avoided by the new refcount,
    chip->active. The chip->in_pm flag is removed accordingly.
    - Instead of rwsem, another refcount, chip->usage_count, is introduced
    for tracking the period to delay the shutdown procedure. At
    the last clear of this refcount, wake_up() to the shutdown waiter is
    called.
    - The shutdown flag is replaced with shutdown atomic count; this is
    for reducing the lock.
    - Two new helpers are introduced to simplify the management of these
    refcounts; snd_usb_lock_shutdown() increases the usage_count, checks
    the shutdown state, and does autoresume. snd_usb_unlock_shutdown()
    does the opposite. Most of mixer and other codes just need this,
    and simply returns an error if it receives an error from lock.

    Fixes: 9003ebb13f61 ('ALSA: usb-audio: Fix runtime PM unbalance')
    Reported-and-tested-by: Alexnader Kuleshov
    Signed-off-by: Takashi Iwai

    Takashi Iwai
     

10 Nov, 2014

1 commit

  • Add a new helper function snd_pcm_stop_xrun() to the standard sequnce
    lock/snd_pcm_stop(XRUN)/unlock by a single call, and replace the
    existing open codes with this helper.

    The function checks the PCM running state to prevent setting the wrong
    state, too, for more safety.

    Signed-off-by: Takashi Iwai

    Takashi Iwai
     

06 Nov, 2014

1 commit

  • The usb-audio driver detects XRUN at its complete callback, but the
    actual code to trigger PCM XRUN is commented out because it caused
    deadlock in the past. This patch revives the PCM trigger properly.
    It resulted in more than just enabling snd_pcm_stop(), but it had to
    deduce the PCM substream with proper NULL checks and holds the stream
    lock around the call.

    Signed-off-by: Takashi Iwai

    Takashi Iwai
     

04 Nov, 2014

1 commit

  • Some functions in mixer.c and endpoint.c receive list_head instead of
    the object itself. This is not obvious and rather error-prone. Let's
    pass the proper object directly instead.

    The functions in midi.c still receive list_head and this can't be
    changed since the object definition isn't exposed to the outside of
    midi.c, so left as is.

    Signed-off-by: Takashi Iwai

    Takashi Iwai
     

26 Jun, 2014

1 commit

  • When a USB-audio device is disconnected while PCM is still running, we
    still see some race: the disconnect callback calls
    snd_usb_endpoint_free() that calls release_urbs() and then kfree()
    while a PCM stream would be closed at the same time and calls
    stop_endpoints() that leads to wait_clear_urbs(). That is, the EP
    object might be deallocated while a PCM stream is syncing with
    wait_clear_urbs() with the same EP.

    Basically calling multiple wait_clear_urbs() would work fine, also
    calling wait_clear_urbs() and release_urbs() would work, too, as
    wait_clear_urbs() just reads some fields in ep. The problem is the
    succeeding kfree() in snd_pcm_endpoint_free().

    This patch moves out the EP deallocation into the later point, the
    destructor callback. At this stage, all PCMs must have been already
    closed, so it's safe to free the objects.

    Reported-by: Alan Stern
    Cc:
    Signed-off-by: Takashi Iwai

    Takashi Iwai
     

03 May, 2014

1 commit

  • The TEAC UD-H01 firmware sends wrong feedback frequency values, thus
    causing the PC to send the samples at a wrong rate, which results in
    clicks and crackles in the output.

    Add a workaround to detect and fix the corruption.

    Signed-off-by: Clemens Ladisch
    [mick37@gmx.de: use sender->udh01_fb_quirk rather than
    ep->udh01_fb_quirk in snd_usb_handle_sync_urb()]
    Reported-and-tested-by: Mick
    Reported-and-tested-by: Andrea Messa
    Cc:
    Signed-off-by: Takashi Iwai

    Clemens Ladisch
     

26 Feb, 2014

1 commit

  • Convert with dev_err() and co from snd_printk(), etc.
    As there are too deep indirections (e.g. ep->chip->dev->dev),
    a few new local macros, usb_audio_err() & co, are introduced.

    Also, the device numbers in some messages are dropped, as they are
    shown in the prefix automatically.

    Signed-off-by: Takashi Iwai

    Takashi Iwai
     

27 Nov, 2013

1 commit


07 Oct, 2013

3 commits