22 Jul, 2020

2 commits

  • [ Upstream commit d8695bc5b1fe88305396b1f788d3b5f218e28a30 ]

    A slight refactoring of the registration quirk code. Now it uses the
    table lookup for easy additions in future. Also the return type was
    changed to bool, and got a few more comments.

    Link: https://lore.kernel.org/r/20200325103322.2508-2-tiwai@suse.de
    Signed-off-by: Takashi Iwai
    Signed-off-by: Sasha Levin

    Takashi Iwai
     
  • [ Upstream commit 55f7326170d9e83e2d828591938e1101982a679c ]

    Create a quirk that allows special processing and/or
    skipping the call to snd_card_register.

    For HyperX AMP, which uses two interfaces, but only has
    a capture stream in the second, this allows the capture
    stream to merge with the first PCM.

    Signed-off-by: Chris Wulff
    Link: https://lore.kernel.org/r/20200314165449.4086-3-crwulff@gmail.com
    Signed-off-by: Takashi Iwai
    Signed-off-by: Sasha Levin

    Chris Wulff
     

17 Jun, 2020

1 commit

  • commit 862b2509d157c629dd26d7ac6c6cdbf043d332eb upstream.

    When a USB-audio interface gets runtime-suspended via auto-pm feature,
    the driver suspends all functionality and increment
    chip->num_suspended_intf. Later on, when the system gets suspended to
    S3, the driver increments chip->num_suspended_intf again, skips the
    device changes, and sets the card power state to
    SNDRV_CTL_POWER_D3hot. In return, when the system gets resumed from
    S3, the resume callback decrements chip->num_suspended_intf. Since
    this refcount is still not zero (it's been runtime-suspended), the
    whole resume is skipped. But there is a small pitfall here.

    The problem is that the driver doesn't restore the card power state
    after this resume call, leaving it as SNDRV_CTL_POWER_D3hot. So,
    even after the system resume finishes, the card instance still appears
    as if it were system-suspended, and this confuses many ioctl accesses
    that are blocked unexpectedly.

    In details, we have two issues behind the scene: one is that the card
    power state is changed only when the refcount becomes zero, and
    another is that the prior auto-suspend check is kept in a boolean
    flag. Although the latter problem is almost negligible since the
    auto-pm feature is imposed only on the primary interface, but this can
    be a potential problem on the devices with multiple interfaces.

    This patch addresses those issues by the following:

    - Replace chip->autosuspended boolean flag with chip->system_suspend
    counter

    - At the first system-suspend, chip->num_suspended_intf is recorded to
    chip->system_suspend

    - At system-resume, the card power state is restored when the
    chip->num_suspended_intf refcount reaches to chip->system_suspend,
    i.e. the state returns to the auto-suspended

    Also, the patch fixes yet another hidden problem by the code
    refactoring along with the fixes above: namely, when some resume
    procedure failed, the driver left chip->num_suspended_intf that was
    already decreased, and it might lead to the refcount unbalance.
    In the new code, the refcount decrement is done after the whole resume
    procedure, and the problem is avoided as well.

    Fixes: 0662292aec05 ("ALSA: usb-audio: Handle normal and auto-suspend equally")
    Reported-and-tested-by: Macpaul Lin
    Cc:
    Link: https://lore.kernel.org/r/20200603153709.6293-1-tiwai@suse.de
    Signed-off-by: Takashi Iwai
    Signed-off-by: Greg Kroah-Hartman

    Takashi Iwai
     

24 Feb, 2020

2 commits

  • [ Upstream commit a3afa29942b84b4e2548beacccc3a68b8d77e3dc ]

    We need to unlock before we returning on this error path.

    Fixes: 73ac9f5e5b43 ("ALSA: usb-audio: Add boot quirk for MOTU M Series")
    Signed-off-by: Dan Carpenter
    Link: https://lore.kernel.org/r/20200115174604.rhanfgy4j3uc65cx@kili.mountain
    Signed-off-by: Takashi Iwai
    Signed-off-by: Sasha Levin

    Dan Carpenter
     
  • [ Upstream commit 73ac9f5e5b43a5dbadb61f27dae7a971f7ec0d22 ]

    Add delay to make sure that audio urbs are not sent too early.
    Otherwise the device hangs. Windows driver makes ~2s delay, so use
    about the same time delay value.

    snd_usb_apply_boot_quirk() is called 3 times for my MOTU M4, which
    is an overkill. Thus a quirk that is called only once is implemented.

    Also send two vendor-specific control messages before and after
    the delay. This behaviour is blindly copied from the Windows driver.

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

    Alexander Tsoy
     

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
     

22 Apr, 2019

1 commit

  • Media Device Allocator API to allows multiple drivers share a media device.
    This API solves a very common use-case for media devices where one physical
    device (an USB stick) provides both audio and video. When such media device
    exposes a standard USB Audio class, a proprietary Video class, two or more
    independent drivers will share a single physical USB bridge. In such cases,
    it is necessary to coordinate access to the shared resource.

    Using this API, drivers can allocate a media device with the shared struct
    device as the key. Once the media device is allocated by a driver, other
    drivers can get a reference to it. The media device is released when all
    the references are released.

    Change the ALSA driver to use the Media Controller API to share media
    resources with DVB, and V4L2 drivers on a AU0828 media device.

    The Media Controller specific initialization is done after sound card is
    registered. ALSA creates Media interface and entity function graph nodes
    for Control, Mixer, PCM Playback, and PCM Capture devices.

    snd_usb_hw_params() will call Media Controller enable source handler
    interface to request the media resource. If resource request is granted,
    it will release it from snd_usb_hw_free(). If resource is busy, -EBUSY is
    returned.

    Media specific cleanup is done in usb_audio_disconnect().

    Reviewed-by: Takashi Iwai
    Signed-off-by: Shuah Khan
    Signed-off-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Shuah Khan
     

19 Jan, 2019

1 commit


16 Jan, 2019

1 commit


07 Jan, 2019

1 commit

  • There are a few places where we access the data without checking the
    actual object size from the USB audio descriptor. This may result in
    OOB access, as recently reported.

    This patch addresses these missing checks. Most of added codes are
    simple bLength checks in the caller side. For the input and output
    terminal parsers, we put the length check in the parser functions.
    For the input terminal, a new argument is added to distinguish between
    UAC1 and the rest, as they treat different objects.

    Reported-by: Mathias Payer
    Reported-by: Hui Peng
    Tested-by: Hui Peng
    Cc:
    Signed-off-by: Takashi Iwai

    Takashi Iwai
     

03 Dec, 2018

1 commit

  • If a USB sound card reports 0 interfaces, an error condition is triggered
    and the function usb_audio_probe errors out. In the error path, there was a
    use-after-free vulnerability where the memory object of the card was first
    freed, followed by a decrement of the number of active chips. Moving the
    decrement above the atomic_dec fixes the UAF.

    [ The original problem was introduced in 3.1 kernel, while it was
    developed in a different form. The Fixes tag below indicates the
    original commit but it doesn't mean that the patch is applicable
    cleanly. -- tiwai ]

    Fixes: 362e4e49abe5 ("ALSA: usb-audio - clear chip->probing on error exit")
    Reported-by: Hui Peng
    Reported-by: Mathias Payer
    Signed-off-by: Hui Peng
    Signed-off-by: Mathias Payer
    Cc:
    Signed-off-by: Takashi Iwai

    Hui Peng
     

31 Jul, 2018

1 commit

  • Set the UAC3 Power Domain state for an Audio Streaming interface
    to D2 state before suspending the device (usb_driver callback).
    This lets the device know there is no intention to use any of the
    Units in the Audio Function and that the host is not going to
    even listen for wake-up events (interrupts) on the units.

    When the usb_driver gets resumed, the state D0 (fully powered) will
    be set. This ties up the UAC3 Power Domains to the runtime PM.

    Signed-off-by: Jorge Sanjuan
    Signed-off-by: Takashi Iwai

    Jorge Sanjuan
     

29 May, 2018

1 commit

  • Currently, USB-audio driver allocates the PCM buffer via vmalloc(), as
    this serves merely as an intermediate buffer that is copied to each
    URB transfer buffer. This works well in general on x86, but on some
    archs this may result in cache coherency issues when mmap is used.
    OTOH, it works also on such arch unless mmap is used.

    This patch is a step for mitigating the inconvenience; a new module
    option "use_vmalloc" is provided so that user can choose to allocate
    the DMA coherent buffer instead of the existing vmalloc buffer.
    The drawback is that it'd be the standard dma_alloc_coherent() calls
    and the system would require contiguous pages on non-x86 archs.

    Note that it's a global option and not dynamically switchable since
    the buffer is pre-allocated at the probe time. In theory, it's
    possible to be switchable, but it'd be trickier and racier.

    As default use_vmalloc option is set to true, so that the old behavior
    is kept. For allowing the coherent mmap on ARM or MIPS, pass
    use_vmalloc=0 option explicitly.

    Reported-and-tested-by: Daniel Danzberger
    Signed-off-by: Takashi Iwai

    Takashi Iwai
     

28 May, 2018

2 commits


13 May, 2018

1 commit

  • Recently released USB Audio Class 3.0 specification
    contains BADD (Basic Audio Device Definition) document
    which describes pre-defined UAC3 configurations.

    BADD support is mandatory for UAC3 devices, it should be
    implemented as a separate USB device configuration.
    As per BADD document, class-specific descriptors
    shall not be included in the Device’s Configuration
    descriptor ("inferred"), but host can guess them
    from BADD profile number, number of endpoints and
    their max packed sizes.

    This patch adds support of all BADD profiles from the spec

    Signed-off-by: Ruslan Bilovol
    Tested-by: Jorge Sanjuan
    Signed-off-by: Takashi Iwai

    Ruslan Bilovol
     

04 May, 2018

1 commit

  • The control header needs to be read from buffer at this point only
    in the case of UAC1 protocol. Move it inside the switch case as other
    protocols such as the Basic Audio Device spec will have an empty buffer
    that is latter filled as inferred.

    Signed-off-by: Jorge Sanjuan
    [Ruslan: updated with recently added sanity checks]
    Signed-off-by: Ruslan Bilovol
    Signed-off-by: Takashi Iwai

    Jorge Sanjuan
     

02 May, 2018

1 commit

  • Historically USB-audio driver sets the card's longname field with the
    details of the device and the bus information. It's good per se, but
    not preferable when it's referred as the identifier for UCM profile.

    This patch adds a quirk profile_name field to override the card's
    longname string to a pre-defined one, so that one can create a unique
    and consistent ID string for the specific USB device via a quirk table
    to be used as a UCM profile name.

    The patch does a slight code refactoring to split out the functions to
    set shortname and longname fields as well.

    Signed-off-by: Takashi Iwai

    Takashi Iwai
     

21 Mar, 2018

1 commit

  • Recently released USB Audio Class 3.0 specification
    introduces many significant changes comparing to
    previous versions, like
    - new Power Domains, support for LPM/L1
    - new Cluster descriptor
    - changed layout of all class-specific descriptors
    - new High Capability descriptors
    - New class-specific String descriptors
    - new and removed units
    - additional sources for interrupts
    - removed Type II Audio Data Formats
    - ... and many other things (check spec)

    It also provides backward compatibility through
    multiple configurations, as well as requires
    mandatory support for BADD (Basic Audio Device
    Definition) on each ADC3.0 compliant device

    This patch adds initial support of UAC3 specification
    that is enough for Generic I/O Profile (BAOF, BAIF)
    device support from BADD document.

    Signed-off-by: Ruslan Bilovol
    Reviewed-by: Greg Kroah-Hartman
    Signed-off-by: Takashi Iwai

    Ruslan Bilovol
     

30 Nov, 2017

1 commit


22 Sep, 2017

1 commit

  • When a USB-audio device receives a maliciously adjusted or corrupted
    buffer descriptor, the USB-audio driver may access an out-of-bounce
    value at its parser. This was detected by syzkaller, something like:

    BUG: KASAN: slab-out-of-bounds in usb_audio_probe+0x27b2/0x2ab0
    Read of size 1 at addr ffff88006b83a9e8 by task kworker/0:1/24
    CPU: 0 PID: 24 Comm: kworker/0:1 Not tainted 4.14.0-rc1-42251-gebb2c2437d80 #224
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
    Workqueue: usb_hub_wq hub_event
    Call Trace:
    __dump_stack lib/dump_stack.c:16
    dump_stack+0x292/0x395 lib/dump_stack.c:52
    print_address_description+0x78/0x280 mm/kasan/report.c:252
    kasan_report_error mm/kasan/report.c:351
    kasan_report+0x22f/0x340 mm/kasan/report.c:409
    __asan_report_load1_noabort+0x19/0x20 mm/kasan/report.c:427
    snd_usb_create_streams sound/usb/card.c:248
    usb_audio_probe+0x27b2/0x2ab0 sound/usb/card.c:605
    usb_probe_interface+0x35d/0x8e0 drivers/usb/core/driver.c:361
    really_probe drivers/base/dd.c:413
    driver_probe_device+0x610/0xa00 drivers/base/dd.c:557
    __device_attach_driver+0x230/0x290 drivers/base/dd.c:653
    bus_for_each_drv+0x161/0x210 drivers/base/bus.c:463
    __device_attach+0x26e/0x3d0 drivers/base/dd.c:710
    device_initial_probe+0x1f/0x30 drivers/base/dd.c:757
    bus_probe_device+0x1eb/0x290 drivers/base/bus.c:523
    device_add+0xd0b/0x1660 drivers/base/core.c:1835
    usb_set_configuration+0x104e/0x1870 drivers/usb/core/message.c:1932
    generic_probe+0x73/0xe0 drivers/usb/core/generic.c:174
    usb_probe_device+0xaf/0xe0 drivers/usb/core/driver.c:266
    really_probe drivers/base/dd.c:413
    driver_probe_device+0x610/0xa00 drivers/base/dd.c:557
    __device_attach_driver+0x230/0x290 drivers/base/dd.c:653
    bus_for_each_drv+0x161/0x210 drivers/base/bus.c:463
    __device_attach+0x26e/0x3d0 drivers/base/dd.c:710
    device_initial_probe+0x1f/0x30 drivers/base/dd.c:757
    bus_probe_device+0x1eb/0x290 drivers/base/bus.c:523
    device_add+0xd0b/0x1660 drivers/base/core.c:1835
    usb_new_device+0x7b8/0x1020 drivers/usb/core/hub.c:2457
    hub_port_connect drivers/usb/core/hub.c:4903
    hub_port_connect_change drivers/usb/core/hub.c:5009
    port_event drivers/usb/core/hub.c:5115
    hub_event+0x194d/0x3740 drivers/usb/core/hub.c:5195
    process_one_work+0xc7f/0x1db0 kernel/workqueue.c:2119
    worker_thread+0x221/0x1850 kernel/workqueue.c:2253
    kthread+0x3a1/0x470 kernel/kthread.c:231
    ret_from_fork+0x2a/0x40 arch/x86/entry/entry_64.S:431

    This patch adds the checks of out-of-bounce accesses at appropriate
    places and bails out when it goes out of the given buffer.

    Reported-by: Andrey Konovalov
    Tested-by: Andrey Konovalov
    Cc:
    Signed-off-by: Takashi Iwai

    Takashi Iwai
     

07 Aug, 2017

1 commit


31 Mar, 2017

1 commit

  • Recently snd-usb-audio driver received a new option, quirk_alias, to
    allow user to apply the existing quirk for a different device. This
    works for many quirks as is, but some still need more tune-ups:
    namely, some quirks check the USB vendor/device IDs in various places,
    thus it doesn't work as long as the ID is different from the expected
    one.

    With this patch, the driver stores the aliased USB ID, so that these
    rest quirks per device ID are applied. The transition to use the
    cached USB ID was already done in the past, so what we needed now is
    only to overwrite chip->usb_id.

    Signed-off-by: Takashi Iwai

    Takashi Iwai
     

30 Nov, 2016

1 commit

  • The function returns -EINVAL even if it builds the stream properly.
    The bogus error code sneaked in during the code refactoring, but it
    wasn't noticed until now since the returned error code itself is
    ignored in anyway. Kill it here, but there is no behavior change by
    this patch, obviously.

    Fixes: e5779998bf8b ('ALSA: usb-audio: refactor code')
    Signed-off-by: Takashi Iwai

    Takashi Iwai
     

15 Nov, 2016

1 commit

  • The usb-audio driver implements the deferred device disconnection for
    the device in use. In this mode, the disconnection callback returns
    immediately while the actual ALSA card object removal happens later
    when all files get closed. As Shuah reported, this code flow,
    however, leads to a use-after-free, detected by KASAN:

    BUG: KASAN: use-after-free in snd_usb_audio_free+0x134/0x160 [snd_usb_audio] at addr ffff8801c863ce10
    Write of size 8 by task pulseaudio/2244
    Call Trace:
    [] dump_stack+0x67/0x94
    [] kasan_object_err+0x21/0x70
    [] kasan_report_error+0x1fa/0x4e0
    [] ? kasan_slab_free+0x87/0xb0
    [] __asan_report_store8_noabort+0x43/0x50
    [] ? snd_usb_audio_free+0x134/0x160 [snd_usb_audio]
    [] snd_usb_audio_free+0x134/0x160 [snd_usb_audio]
    [] snd_usb_audio_dev_free+0x31/0x40 [snd_usb_audio]
    [] __snd_device_free+0x12a/0x210
    [] snd_device_free_all+0x85/0xd0
    [] release_card_device+0x34/0x130
    [] device_release+0x76/0x1e0
    [] kobject_release+0x107/0x370
    .....
    Object at ffff8801c863cc80, in cache kmalloc-2048 size: 2048
    Allocated:
    [] save_stack_trace+0x2b/0x50
    [] save_stack+0x46/0xd0
    [] kasan_kmalloc+0xad/0xe0
    [] kmem_cache_alloc_trace+0xfa/0x240
    [] usb_alloc_dev+0x57/0xc90
    [] hub_event+0xf1d/0x35f0
    ....
    Freed:
    [] save_stack_trace+0x2b/0x50
    [] save_stack+0x46/0xd0
    [] kasan_slab_free+0x71/0xb0
    [] kfree+0xd9/0x280
    [] usb_release_dev+0xde/0x110
    [] device_release+0x76/0x1e0
    ....

    It's the code trying to clear drvdata of the assigned usb_device where
    the usb_device itself was already released in usb_release_dev() after
    the disconnect callback.

    This patch fixes it by checking whether the code path is via the
    disconnect callback, i.e. chip->shutdown flag is set.

    Fixes: 79289e24194a ('ALSA: usb-audio: Refer to chip->usb_id for quirks...')
    Reported-and-tested-by: Shuah Khan
    Cc: # v4.6+
    Signed-off-by: Takashi Iwai

    Takashi Iwai
     

18 Jul, 2016

1 commit

  • snd_usb_{set_interface,ctl_msg}_quirk checks chip->usb_id to need
    calling a quirks code. But existed code path that not calling
    dev_set_drvdata in usb_audio_probe.

    Fixes: 79289e24194a ("ALSA: usb-audio: Refer to chip->usb_id for quirks and MIDI creation")
    Signed-off-by: Kazuki Oikawa
    Cc: # v4.6+
    Reviewed-by: Takashi Sakamoto
    Tested-by: Takashi Sakamoto
    Signed-off-by: Takashi Iwai

    Kazuki Oikawa
     

10 May, 2016

1 commit


08 May, 2016

1 commit


01 Apr, 2016

1 commit

  • Unfortunately, this patch caused several regressions at au0828 and
    snd-usb-audio, like this one:
    https://bugzilla.kernel.org/show_bug.cgi?id=115561

    It also showed several troubles at the MC core that handles pretty
    poorly the memory protections and data lifetime management.

    So, better to revert it and fix the core before reapplying this
    change.

    This reverts commit aebb2b89bff0 ("[media] sound/usb: Use Media
    Controller API to share media resources")'

    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     

19 Mar, 2016

1 commit

  • Pull sound updates from Takashi Iwai:
    "After a heavy storm by syzkaller in 4.5 cycle, we have relatively few
    changes in the core at this time while a lot of changes are found in
    the driver side, unsurprisingly. Below are some highlights:

    ALSA core:
    - A few more hardening in ALSA timer codes
    - An extension of sequencer API for advertising the card / pid
    - Small fixes in compress-offload and jack layers

    HD-audio:
    - Dynamic PCM assignment in HDMI/DP codec; preparation for upcoming
    DP-MST support
    - Lots of code refactoring for sharing with ASoC SKL driver
    - Regression fixes for Intel HDMI/DP
    - Fixups for CX20724 codec, Lenovo AiO

    USB-audio:
    - Add quirk_alias option to make quirk debugging easier
    - Fixes for possible Oops by malformed firmware

    Firewire:
    - Add support for FW-1804 in tascam driver
    - Improvements / changes in card registration, multi stream handling,
    etc for DICE
    - Lots of code refactoring

    ASoC:
    - Enhancements of still ongoing topology API
    - Lots of commits for Intel Skylake support including HDMI support
    - A few Intel Atom driver updates for recent devices
    - Lots of improvements to the Renesas drivers
    - Capture support for Qualcomm drivers
    - Support for TI DaVinci DRA7xxx devices
    - New machine drivers for Freescale systems with Cirrus CODECs,
    Mediatek systems with RT5650 CODECs
    - New CPU drivers for Allwinner S/PDIF controllers
    - New CODEC drivers for Maxim MAX9867 and MAX98926 and Realtek RT5514"

    * tag 'sound-4.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound: (291 commits)
    ALSA: hda - Fix mutex deadlock at HDMI/DP hotplug
    ALSA: ctl: change return value in compatibility layer so that it's the same value in core implementation
    ALSA: mixart: silence an uninitialized variable warning
    ALSA: usb-audio: Add sanity checks for endpoint accesses
    ALSA: usb-audio: Minor code cleanup in create_fixed_stream_quirk()
    ALSA: usb-audio: Fix NULL dereference in create_fixed_stream_quirk()
    ALSA: hda - Limit i915 HDMI binding only for HSW and later
    ALSA: hda - Fix unconditional GPIO toggle via automute
    ALSA: mixart: silence unitialized variable warnings
    ALSA: hda - Fixes double fault in nvhdmi_chmap_cea_alloc_validate_get_type
    ALSA: intel8x0: Add clock quirk entry for AD1981B on IBM ThinkPad X41.
    ALSA: hda - Add new GPU codec ID 0x10de0082 to snd-hda
    ASoC: rsnd: add simplified module explanation
    ASoC: hdac_hdmi: Add broxton device ID
    ASoC: Intel: Bxtn: Add Broxton PCI ID
    ASoC: Intel: Skylake: Move Skylake dsp ops & loader ops
    ASoC: Intel: add dmabuffer to common sst_dsp
    ASoC: Intel: Skylake: Unstatify skl_dsp_enable_core
    ASoC: Intel: Skylake: Fix whitepsace issues
    ASoC: Intel: Skylake: Move module id defines
    ...

    Linus Torvalds
     

04 Mar, 2016

1 commit

  • Change ALSA driver to use Media Controller API to share media resources
    with DVB and V4L2 drivers on a AU0828 media device. Media Controller
    specific initialization is done after sound card is registered. ALSA
    creates Media interface and entity function graph nodes for Control,
    Mixer, PCM Playback, and PCM Capture devices.

    snd_usb_hw_params() will call Media Controller enable source handler
    interface to request the media resource. If resource request is
    granted, it will release it from snd_usb_hw_free(). If resource is
    busy, -EBUSY is returned.

    Media specific cleanup is done in usb_audio_disconnect().

    Signed-off-by: Shuah Khan
    Acked-by: Takashi Iwai
    Signed-off-by: Mauro Carvalho Chehab

    Shuah Khan
     

29 Jan, 2016

2 commits

  • This patch adds a new option "quirk_alias" to snd-usb-audio driver for
    allowing user to pass the quirk alias list. A quirk alias consists of
    a string form like 0123abcd:5678beef, which makes to apply a quirk to
    a device with USB ID 0123:abcd treated as if it were 5678:beef.
    This feature is useful to test an existing quirk, typically for a
    newer model of the same vendor, without patching / rebuilding the
    kernel driver.

    The current implementation is fairly simplistic: since there is no API
    for matching a usb_device_id to the given ID pair, it has an open code
    to loop over the id table and matches only with vendor:product pair.
    So far, this is OK, as all existing entries are with vendor:product
    pairs, indeed. Once when we have another matching entry, however,
    we'd need to update get_alias_quirk() as well.

    Note that this option is provided only for testing / development. If
    you want to have a proper support, contact to upstream for adding the
    matching quirk in the driver code statically.

    Signed-off-by: Takashi Iwai

    Takashi Iwai
     
  • This is a preliminary patch for the later change to allow a better
    quirk ID management. In the current USB-audio code, there are a few
    places looking at usb_device idVendor and idProduct fields directly
    even though we have already a static member in snd_usb_audio.usb_id.
    This patch modifies such codes to refer to the latter field.

    For achieving this, two slightly intensive changes have been done:
    - The snd_usb_audio object is set/reset via dev_getdrv() for the given
    USB device; it's needed for minimizing the changes for some existing
    quirks that take only usb_device object.

    - __snd_usbmidi_create() is introduced to receive the pre-given usb_id
    argument. The exported snd_usbmidi_create() is unchanged by calling
    this new function internally.

    Signed-off-by: Takashi Iwai

    Takashi Iwai
     

12 Jan, 2016

1 commit

  • ALSA PCM may still have a leftover instance after disconnection and
    it delays its release. The problem is that the PCM close code path of
    USB-audio driver has a call of snd_usb_autosuspend(). This involves
    with the call of usb_autopm_put_interface() and it may lead to a
    kernel Oops due to the NULL object like:

    BUG: unable to handle kernel NULL pointer dereference at 0000000000000190
    IP: [] usb_autopm_put_interface+0xf/0x30 PGD 0
    Call Trace:
    [] snd_usb_autosuspend+0x14/0x20
    [] snd_usb_pcm_close.isra.14+0x5c/0x90
    [] snd_usb_playback_close+0xf/0x20
    [] snd_pcm_release_substream.part.36+0x3a/0x90
    [] snd_pcm_release+0xa3/0xb0
    [] snd_disconnect_release+0xd0/0xe0
    [] __fput+0x97/0x1d0
    [] ____fput+0x9/0x10
    [] task_work_run+0x72/0x90
    [] do_exit+0x280/0xa80
    [] do_group_exit+0x3a/0xa0
    [] get_signal+0x1df/0x540
    [] do_signal+0x23/0x620
    [] ? do_readv_writev+0x128/0x200
    [] prepare_exit_to_usermode+0x91/0xd0
    [] syscall_return_slowpath+0x9a/0x120
    [] ? __sys_recvmsg+0x5d/0x70
    [] ? ktime_get_ts64+0x45/0xe0
    [] ? SyS_poll+0x60/0xf0
    [] int_ret_from_sys_call+0x25/0x8f

    We have already a check of disconnection in snd_usb_autoresume(), but
    the check is missing its counterpart. The fix is just to put the same
    check in snd_usb_autosuspend(), too.

    Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=109431
    Cc:
    Signed-off-by: Takashi Iwai

    Takashi Iwai
     

26 Aug, 2015

3 commits

  • In theory, the device may get suspended even at runtime PM suspend.
    Currently we don't save the mixer state for autopm, and it may bring
    inconsistency.

    This patch removes the special handling for autosuspend.

    Signed-off-by: Takashi Iwai

    Takashi Iwai
     
  • We can use active refcount for preventing autopm during probe.

    Signed-off-by: Takashi Iwai

    Takashi Iwai
     
  • 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
     

19 Aug, 2015

1 commit

  • The fix for deadlock in PM in commit [1ee23fe07ee8: ALSA: usb-audio:
    Fix deadlocks at resuming] introduced a new check of in_pm flag.
    However, the brainless patch author evaluated it in a wrong way
    (logical AND instead of logical OR), thus usb_autopm_get_interface()
    is wrongly called at probing, leading to unbalance of runtime PM
    refcount.

    This patch fixes it by correcting the logic.

    Reported-by: Hans Yang
    Fixes: 1ee23fe07ee8 ('ALSA: usb-audio: Fix deadlocks at resuming')
    Cc: [v3.15+]
    Signed-off-by: Takashi Iwai

    Takashi Iwai
     

05 Nov, 2014

2 commits

  • This merges the USB-audio disconnect fix and resolves the conflicts
    so that we can continue working on development of usb-audio stuff.

    Conflicts:
    sound/usb/card.c

    Takashi Iwai
     
  • Some USB-audio devices show weird sysfs warnings at disconnecting the
    devices, e.g.
    usb 1-3: USB disconnect, device number 3
    ------------[ cut here ]------------
    WARNING: CPU: 0 PID: 973 at fs/sysfs/group.c:216 device_del+0x39/0x180()
    sysfs group ffffffff8183df40 not found for kobject 'midiC1D0'
    Call Trace:
    [] ? dump_stack+0x49/0x71
    [] ? warn_slowpath_common+0x82/0xb0
    [] ? warn_slowpath_fmt+0x45/0x50
    [] ? device_del+0x39/0x180
    [] ? device_unregister+0x9/0x20
    [] ? device_destroy+0x34/0x40
    [] ? snd_unregister_device+0x7f/0xd0 [snd]
    [] ? snd_rawmidi_dev_disconnect+0xce/0x100 [snd_rawmidi]
    [] ? snd_device_disconnect+0x62/0x90 [snd]
    [] ? snd_device_disconnect_all+0x3c/0x60 [snd]
    [] ? snd_card_disconnect+0x124/0x1a0 [snd]
    [] ? usb_audio_disconnect+0x88/0x1c0 [snd_usb_audio]
    [] ? usb_unbind_interface+0x5e/0x1b0 [usbcore]
    [] ? __device_release_driver+0x79/0xf0
    [] ? device_release_driver+0x25/0x40
    [] ? bus_remove_device+0xf1/0x130
    [] ? device_del+0x109/0x180
    [] ? usb_disable_device+0x95/0x1f0 [usbcore]
    [] ? usb_disconnect+0x8f/0x190 [usbcore]
    [] ? hub_thread+0x539/0x13a0 [usbcore]
    [] ? sched_clock_local+0x15/0x80
    [] ? sched_clock_cpu+0xb8/0xd0
    [] ? bit_waitqueue+0xb0/0xb0
    [] ? usb_port_resume+0x430/0x430 [usbcore]
    [] ? usb_port_resume+0x430/0x430 [usbcore]
    [] ? kthread+0xce/0xf0
    [] ? kthread_create_on_node+0x1c0/0x1c0
    [] ? ret_from_fork+0x7c/0xb0
    [] ? kthread_create_on_node+0x1c0/0x1c0
    ---[ end trace 40b1928d1136b91e ]---

    This comes from the fact that usb-audio driver may receive the
    disconnect callback multiple times, per each usb interface. When a
    device has both audio and midi interfaces, it gets called twice, and
    currently the driver tries to release resources at the last call.
    At this point, the first parent interface has been already deleted,
    thus deleting a child of the first parent hits such a warning.

    For fixing this problem, we need to call snd_card_disconnect() and
    cancel pending operations at the very first disconnect while the
    release of the whole objects waits until the last disconnect call.

    Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=80931
    Reported-and-tested-by: Tomas Gayoso
    Reported-and-tested-by: Chris J Arges
    Cc:
    Signed-off-by: Takashi Iwai

    Takashi Iwai