1. 22 7月, 2020 1 次提交
  2. 09 7月, 2020 1 次提交
  3. 07 7月, 2020 1 次提交
  4. 01 7月, 2020 1 次提交
  5. 17 6月, 2020 1 次提交
    • T
      ALSA: usb-audio: Fix potential use-after-free of streams · ff58bbc7
      Takashi Iwai 提交于
      With the recent full-duplex support of implicit feedback streams, an
      endpoint can be still running after closing the capture stream as long
      as the playback stream with the sync-endpoint is running.  In such a
      state, the URBs are still be handled and they may call retire_data_urb
      callback, which tries to transfer the data from the PCM buffer.  Since
      the PCM stream gets closed, this may lead to use-after-free.
      
      This patch adds the proper clearance of the callback at stopping the
      capture stream for addressing the possible UAF above.
      
      Fixes: 10ce77e4 ("ALSA: usb-audio: Add duplex sound support for USB devices using implicit feedback")
      Link: https://lore.kernel.org/r/20200616120921.12249-1-tiwai@suse.deSigned-off-by: NTakashi Iwai <tiwai@suse.de>
      ff58bbc7
  6. 12 6月, 2020 1 次提交
  7. 02 6月, 2020 1 次提交
  8. 16 5月, 2020 1 次提交
  9. 24 4月, 2020 1 次提交
    • A
      ALSA: usb-audio: Improve frames size computation · f0bd62b6
      Alexander Tsoy 提交于
      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: NAlexander Tsoy <alexander@tsoy.me>
      Link: https://lore.kernel.org/r/20200424022449.14972-1-alexander@tsoy.meSigned-off-by: NTakashi Iwai <tiwai@suse.de>
      f0bd62b6
  10. 06 3月, 2020 1 次提交
  11. 16 1月, 2020 1 次提交
  12. 14 1月, 2020 1 次提交
  13. 20 12月, 2019 1 次提交
  14. 19 12月, 2019 1 次提交
    • H
      ALSA: usb-audio: set the interface format after resume on Dell WD19 · 92adc96f
      Hui Wang 提交于
      Recently we found the headset-mic on the Dell Dock WD19 doesn't work
      anymore after s3 (s2i or deep), this problem could be workarounded by
      closing (pcm_close) the app and then reopening (pcm_open) the app, so
      this bug is not easy to be detected by users.
      
      When problem happens, retire_capture_urb() could still be called
      periodically, but the size of captured data is always 0, it could be
      a firmware bug on the dock. Anyway I found after resuming, the
      snd_usb_pcm_prepare() will be called, and if we forcibly run
      set_format() to set the interface and its endpoint, the capture
      size will be normal again. This problem and workaound also apply to
      playback.
      
      To fix it in the kernel, add a quirk to let set_format() run
      forcibly once after resume.
      Signed-off-by: NHui Wang <hui.wang@canonical.com>
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20191218132650.6303-1-hui.wang@canonical.comSigned-off-by: NTakashi Iwai <tiwai@suse.de>
      92adc96f
  15. 11 12月, 2019 3 次提交
  16. 06 11月, 2019 1 次提交
  17. 17 10月, 2019 1 次提交
  18. 20 8月, 2019 1 次提交
  19. 06 8月, 2019 1 次提交
  20. 31 5月, 2019 1 次提交
  21. 22 4月, 2019 1 次提交
    • S
      media: sound/usb: Use Media Controller API to share media resources · 66354f18
      Shuah Khan 提交于
      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: NTakashi Iwai <tiwai@suse.de>
      Signed-off-by: NShuah Khan <shuah@kernel.org>
      Signed-off-by: NHans Verkuil <hverkuil-cisco@xs4all.nl>
      Signed-off-by: NMauro Carvalho Chehab <mchehab+samsung@kernel.org>
      66354f18
  22. 01 3月, 2019 1 次提交
    • M
      ALSA: usb-audio: Add quirk for MOTU MicroBook II · a634090a
      Manuel Reinhardt 提交于
      Add an entry to the quirks-table to for usb-audio to recognize the
      Microbook II (although it only exposes vendor interfaces). A simple boot
      quirk is also implemented to set up the sample rate and  make sure that
      no audio urbs are sent before the device is ready.
      
      This patch only provides audio playback and capture at 96kHz sample
      rate. Notice the following shortcomings:
      
      - The sample rate is currently hardcoded to 96k although the device also
        supports 48k and 44.1k.
      
      - The various mixer controls of the MicroBook are not made available.
      
      - The keep-iface control should be on by default because the device
        shuts down whenever the altsetting is reset which is usually unwanted.
        (I don't know the best way to do this)
      
      - The communication format used by the MicroBook for sample rate setting
        and also other setup has been reverse engineered by looking at the
        usbmon output while running the windows driver through virtualbox. In
        this patch the first byte of every message is set to \0 while in the
        observed communications the first byte acts as a "message-counter"
        increasing its value with every message sent. Leaving it at \0 does
        not seem to affect the device.
      Signed-off-by: NManuel Reinhardt <manuel.rhdt@gmail.com>
      Signed-off-by: NTakashi Iwai <tiwai@suse.de>
      a634090a
  23. 08 2月, 2019 1 次提交
  24. 02 8月, 2018 1 次提交
  25. 31 7月, 2018 2 次提交
    • J
      ALSA: usb-audio: Operate UAC3 Power Domains in PCM callbacks · a0a4959e
      Jorge Sanjuan 提交于
      Make use of UAC3 Power Domains associated to an Audio Streaming
      path within the PCM's logic. This means, when there is no audio
      being transferred (pcm is closed), the host will set the Power Domain
      associated to that substream to state D1. When audio is being transferred
      (from hw_params onwards), the Power Domain will be set to D0 state.
      
      This is the way the host lets the device know which Terminal
      is going to be actively used and it is for the device to
      manage its own internal resources on that UAC3 Power Domain.
      
      Note the resume method now sets the Power Domain to D1 state as
      resuming the device doesn't mean audio streaming will occur.
      Signed-off-by: NJorge Sanjuan <jorge.sanjuan@codethink.co.uk>
      Signed-off-by: NTakashi Iwai <tiwai@suse.de>
      a0a4959e
    • J
      ALSA: usb-audio: Add UAC3 Power Domains to suspend/resume · 3f59aa11
      Jorge Sanjuan 提交于
      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: NJorge Sanjuan <jorge.sanjuan@codethink.co.uk>
      Signed-off-by: NTakashi Iwai <tiwai@suse.de>
      3f59aa11
  26. 18 7月, 2018 1 次提交
  27. 13 6月, 2018 1 次提交
    • K
      treewide: kmalloc() -> kmalloc_array() · 6da2ec56
      Kees Cook 提交于
      The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
      patch replaces cases of:
      
              kmalloc(a * b, gfp)
      
      with:
              kmalloc_array(a * b, gfp)
      
      as well as handling cases of:
      
              kmalloc(a * b * c, gfp)
      
      with:
      
              kmalloc(array3_size(a, b, c), gfp)
      
      as it's slightly less ugly than:
      
              kmalloc_array(array_size(a, b), c, gfp)
      
      This does, however, attempt to ignore constant size factors like:
      
              kmalloc(4 * 1024, gfp)
      
      though any constants defined via macros get caught up in the conversion.
      
      Any factors with a sizeof() of "unsigned char", "char", and "u8" were
      dropped, since they're redundant.
      
      The tools/ directory was manually excluded, since it has its own
      implementation of kmalloc().
      
      The Coccinelle script used for this was:
      
      // Fix redundant parens around sizeof().
      @@
      type TYPE;
      expression THING, E;
      @@
      
      (
        kmalloc(
      -	(sizeof(TYPE)) * E
      +	sizeof(TYPE) * E
        , ...)
      |
        kmalloc(
      -	(sizeof(THING)) * E
      +	sizeof(THING) * E
        , ...)
      )
      
      // Drop single-byte sizes and redundant parens.
      @@
      expression COUNT;
      typedef u8;
      typedef __u8;
      @@
      
      (
        kmalloc(
      -	sizeof(u8) * (COUNT)
      +	COUNT
        , ...)
      |
        kmalloc(
      -	sizeof(__u8) * (COUNT)
      +	COUNT
        , ...)
      |
        kmalloc(
      -	sizeof(char) * (COUNT)
      +	COUNT
        , ...)
      |
        kmalloc(
      -	sizeof(unsigned char) * (COUNT)
      +	COUNT
        , ...)
      |
        kmalloc(
      -	sizeof(u8) * COUNT
      +	COUNT
        , ...)
      |
        kmalloc(
      -	sizeof(__u8) * COUNT
      +	COUNT
        , ...)
      |
        kmalloc(
      -	sizeof(char) * COUNT
      +	COUNT
        , ...)
      |
        kmalloc(
      -	sizeof(unsigned char) * COUNT
      +	COUNT
        , ...)
      )
      
      // 2-factor product with sizeof(type/expression) and identifier or constant.
      @@
      type TYPE;
      expression THING;
      identifier COUNT_ID;
      constant COUNT_CONST;
      @@
      
      (
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(TYPE) * (COUNT_ID)
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(TYPE) * COUNT_ID
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(TYPE) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(TYPE) * COUNT_CONST
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(THING) * (COUNT_ID)
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(THING) * COUNT_ID
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(THING) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(THING)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(THING) * COUNT_CONST
      +	COUNT_CONST, sizeof(THING)
        , ...)
      )
      
      // 2-factor product, only identifiers.
      @@
      identifier SIZE, COUNT;
      @@
      
      - kmalloc
      + kmalloc_array
        (
      -	SIZE * COUNT
      +	COUNT, SIZE
        , ...)
      
      // 3-factor product with 1 sizeof(type) or sizeof(expression), with
      // redundant parens removed.
      @@
      expression THING;
      identifier STRIDE, COUNT;
      type TYPE;
      @@
      
      (
        kmalloc(
      -	sizeof(TYPE) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kmalloc(
      -	sizeof(TYPE) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kmalloc(
      -	sizeof(TYPE) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kmalloc(
      -	sizeof(TYPE) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kmalloc(
      -	sizeof(THING) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kmalloc(
      -	sizeof(THING) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kmalloc(
      -	sizeof(THING) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kmalloc(
      -	sizeof(THING) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      )
      
      // 3-factor product with 2 sizeof(variable), with redundant parens removed.
      @@
      expression THING1, THING2;
      identifier COUNT;
      type TYPE1, TYPE2;
      @@
      
      (
        kmalloc(
      -	sizeof(TYPE1) * sizeof(TYPE2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        kmalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        kmalloc(
      -	sizeof(THING1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        kmalloc(
      -	sizeof(THING1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        kmalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      |
        kmalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      )
      
      // 3-factor product, only identifiers, with redundant parens removed.
      @@
      identifier STRIDE, SIZE, COUNT;
      @@
      
      (
        kmalloc(
      -	(COUNT) * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kmalloc(
      -	COUNT * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kmalloc(
      -	COUNT * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kmalloc(
      -	(COUNT) * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kmalloc(
      -	COUNT * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kmalloc(
      -	(COUNT) * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kmalloc(
      -	(COUNT) * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kmalloc(
      -	COUNT * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      )
      
      // Any remaining multi-factor products, first at least 3-factor products,
      // when they're not all constants...
      @@
      expression E1, E2, E3;
      constant C1, C2, C3;
      @@
      
      (
        kmalloc(C1 * C2 * C3, ...)
      |
        kmalloc(
      -	(E1) * E2 * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kmalloc(
      -	(E1) * (E2) * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kmalloc(
      -	(E1) * (E2) * (E3)
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kmalloc(
      -	E1 * E2 * E3
      +	array3_size(E1, E2, E3)
        , ...)
      )
      
      // And then all remaining 2 factors products when they're not all constants,
      // keeping sizeof() as the second factor argument.
      @@
      expression THING, E1, E2;
      type TYPE;
      constant C1, C2, C3;
      @@
      
      (
        kmalloc(sizeof(THING) * C2, ...)
      |
        kmalloc(sizeof(TYPE) * C2, ...)
      |
        kmalloc(C1 * C2 * C3, ...)
      |
        kmalloc(C1 * C2, ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(TYPE) * (E2)
      +	E2, sizeof(TYPE)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(TYPE) * E2
      +	E2, sizeof(TYPE)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(THING) * (E2)
      +	E2, sizeof(THING)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	sizeof(THING) * E2
      +	E2, sizeof(THING)
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	(E1) * E2
      +	E1, E2
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	(E1) * (E2)
      +	E1, E2
        , ...)
      |
      - kmalloc
      + kmalloc_array
        (
      -	E1 * E2
      +	E1, E2
        , ...)
      )
      Signed-off-by: NKees Cook <keescook@chromium.org>
      6da2ec56
  28. 29 5月, 2018 1 次提交
    • T
      ALSA: usb-audio: Allow non-vmalloc buffer for PCM buffers · f274baa4
      Takashi Iwai 提交于
      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: NDaniel Danzberger <daniel@dd-wrt.com>
      Signed-off-by: NTakashi Iwai <tiwai@suse.de>
      f274baa4
  29. 28 5月, 2018 3 次提交
  30. 17 5月, 2018 1 次提交
  31. 02 5月, 2018 2 次提交
    • T
      ALSA: usb-audio: Add keep_iface flag · 8a463225
      Takashi Iwai 提交于
      Introduce a new flag to struct snd_usb_audio for allowing the device
      to skip usb_set_interface() calls at changing or closing the stream.
      As of this patch, the flag is nowhere set, so it's just a place
      holder.  The dynamic switching will be added in the following patch.
      
      A background information for this change:
      
      Dell WD15 dock with Realtek chip gives a very long pause at each time
      the driver changes the altset, which eventually happens at every PCM
      stream open/close and parameter change.  As the long pause happens in
      each usb_set_interface() call, there is nothing we can do as long as
      it's called.  The workaround is to reduce calling it as much as
      possible, and this flag indicates that behavior.
      Signed-off-by: NTakashi Iwai <tiwai@suse.de>
      8a463225
    • T
      ALSA: usb-audio: Avoid superfluous usb_set_interface() calls · b099b969
      Takashi Iwai 提交于
      This is a preliminary change for the upcoming quirk implementation.
      
      Currently USB-audio driver tries to call usb_set_interface() whenever
      the format change with interface/altset modification happens.  In this
      patch, the check is replaced with the comparison of cur_altsetting and
      the targeted altsetting pointer, so that the driver may skip the
      unnecessary function calls.
      Signed-off-by: NTakashi Iwai <tiwai@suse.de>
      b099b969
  32. 19 4月, 2018 2 次提交
  33. 12 2月, 2018 1 次提交