From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@kernel.org
Cc: stable-review@kernel.org, torvalds@linux-foundation.org,
akpm@linux-foundation.org, alan@lxorguk.ukuu.org.uk,
Daniel Mack <zonque@gmail.com>,
Sarah Sharp <sarah.a.sharp@linux.intel.com>,
Takashi Iwai <tiwai@suse.de>
Subject: [12/19] ALSA: snd_usb_caiaq: track submitted output urbs
Date: Fri, 26 Aug 2011 14:58:33 -0700 [thread overview]
Message-ID: <20110826220120.816637549@clark.kroah.org> (raw)
In-Reply-To: <20110826220137.GA14059@kroah.com>
2.6.32-longterm review patch. If anyone has any objections, please let us know.
------------------
From: Daniel Mack <zonque@gmail.com>
commit da6094ea7d3c2295473d8f5134279307255d6ebf upstream.
The snd_usb_caiaq driver currently assumes that output urbs are serviced
in time and doesn't track when and whether they are given back by the
USB core. That usually works fine, but due to temporary limitations of
the XHCI stack, we faced that urbs were submitted more than once with
this approach.
As it's no good practice to fire and forget urbs anyway, this patch
introduces a proper bit mask to track which requests have been submitted
and given back.
That alone however doesn't make the driver work in case the host
controller is broken and doesn't give back urbs at all, and the output
stream will stop once all pre-allocated output urbs are consumed. But
it does prevent crashes of the controller stack in such cases.
See http://bugzilla.kernel.org/show_bug.cgi?id=40702 for more details.
Signed-off-by: Daniel Mack <zonque@gmail.com>
Reported-and-tested-by: Matej Laitl <matej@laitl.cz>
Cc: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
sound/usb/caiaq/audio.c | 31 +++++++++++++++++++++++++++----
sound/usb/caiaq/device.h | 1 +
2 files changed, 28 insertions(+), 4 deletions(-)
--- a/sound/usb/caiaq/audio.c
+++ b/sound/usb/caiaq/audio.c
@@ -138,8 +138,12 @@ static void stream_stop(struct snd_usb_c
for (i = 0; i < N_URBS; i++) {
usb_kill_urb(dev->data_urbs_in[i]);
- usb_kill_urb(dev->data_urbs_out[i]);
+
+ if (test_bit(i, &dev->outurb_active_mask))
+ usb_kill_urb(dev->data_urbs_out[i]);
}
+
+ dev->outurb_active_mask = 0;
}
static int snd_usb_caiaq_substream_open(struct snd_pcm_substream *substream)
@@ -466,8 +470,8 @@ static void read_completed(struct urb *u
{
struct snd_usb_caiaq_cb_info *info = urb->context;
struct snd_usb_caiaqdev *dev;
- struct urb *out;
- int frame, len, send_it = 0, outframe = 0;
+ struct urb *out = NULL;
+ int i, frame, len, send_it = 0, outframe = 0;
size_t offset = 0;
if (urb->status || !info)
@@ -478,7 +482,17 @@ static void read_completed(struct urb *u
if (!dev->streaming)
return;
- out = dev->data_urbs_out[info->index];
+ /* find an unused output urb that is unused */
+ for (i = 0; i < N_URBS; i++)
+ if (test_and_set_bit(i, &dev->outurb_active_mask) == 0) {
+ out = dev->data_urbs_out[i];
+ break;
+ }
+
+ if (!out) {
+ log("Unable to find an output urb to use\n");
+ goto requeue;
+ }
/* read the recently received packet and send back one which has
* the same layout */
@@ -509,8 +523,12 @@ static void read_completed(struct urb *u
out->number_of_packets = outframe;
out->transfer_flags = URB_ISO_ASAP;
usb_submit_urb(out, GFP_ATOMIC);
+ } else {
+ struct snd_usb_caiaq_cb_info *oinfo = out->context;
+ clear_bit(oinfo->index, &dev->outurb_active_mask);
}
+requeue:
/* re-submit inbound urb */
for (frame = 0; frame < FRAMES_PER_URB; frame++) {
urb->iso_frame_desc[frame].offset = BYTES_PER_FRAME * frame;
@@ -532,6 +550,8 @@ static void write_completed(struct urb *
dev->output_running = 1;
wake_up(&dev->prepare_wait_queue);
}
+
+ clear_bit(info->index, &dev->outurb_active_mask);
}
static struct urb **alloc_urbs(struct snd_usb_caiaqdev *dev, int dir, int *ret)
@@ -682,6 +702,9 @@ int snd_usb_caiaq_audio_init(struct snd_
if (!dev->data_cb_info)
return -ENOMEM;
+ dev->outurb_active_mask = 0;
+ BUILD_BUG_ON(N_URBS > (sizeof(dev->outurb_active_mask) * 8));
+
for (i = 0; i < N_URBS; i++) {
dev->data_cb_info[i].dev = dev;
dev->data_cb_info[i].index = i;
--- a/sound/usb/caiaq/device.h
+++ b/sound/usb/caiaq/device.h
@@ -92,6 +92,7 @@ struct snd_usb_caiaqdev {
int input_panic, output_panic, warned;
char *audio_in_buf, *audio_out_buf;
unsigned int samplerates, bpp;
+ unsigned long outurb_active_mask;
struct snd_pcm_substream *sub_playback[MAX_STREAMS];
struct snd_pcm_substream *sub_capture[MAX_STREAMS];
next prev parent reply other threads:[~2011-08-27 14:55 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-26 22:01 [00/19] 2.6.32.46-longterm review Greg KH
2011-08-26 21:58 ` [01/19] USB: xhci: fix OS want to own HC Greg KH
2011-08-26 21:58 ` [02/19] USB: assign instead of equal in usbtmc.c Greg KH
2011-08-26 21:58 ` [03/19] USB: usb-storage: unusual_devs entry for ARM V2M motherboard Greg KH
2011-08-26 21:58 ` [04/19] USB: Serial: Added device ID for Qualcomm Modem in Sagemcom's HiLo3G Greg KH
2011-08-26 21:58 ` [05/19] atm: br2864: sent packets truncated in VC routed mode Greg KH
2011-08-26 21:58 ` [06/19] hwmon: (ibmaem) add missing kfree Greg KH
2011-08-26 21:58 ` [07/19] ALSA: snd-usb-caiaq: Correct offset fields of outbound iso_frame_desc Greg KH
2011-08-26 21:58 ` [08/19] mm: fix wrong vmap address calculations with odd NR_CPUS values Greg KH
2011-08-26 21:58 ` [09/19] perf tools: do not look at ./config for configuration Greg KH
2011-08-26 21:58 ` [10/19] fs/partitions/efi.c: corrupted GUID partition tables can cause kernel oops Greg KH
2011-08-26 21:58 ` [11/19] befs: Validate length of long symbolic links Greg KH
2011-08-26 21:58 ` Greg KH [this message]
2011-08-26 21:58 ` [13/19] ALSA: ac97: Add HP Compaq dc5100 SFF(PT003AW) to Headphone Jack Sense whitelist Greg KH
2011-08-26 21:58 ` [14/19] futex: Fix regression with read only mappings Greg KH
2011-08-26 21:58 ` [15/19] x86-32, vdso: On system call restart after SYSENTER, use int $0x80 Greg KH
2011-08-26 21:58 ` [16/19] x86, UV: Remove UV delay in starting slave cpus Greg KH
2011-08-26 21:58 ` [17/19] drm/ttm: fix ttm_bo_add_ttm(user) failure path Greg KH
2011-08-26 21:58 ` [18/19] fuse: check size of FUSE_NOTIFY_INVAL_ENTRY message Greg KH
2011-08-26 21:58 ` [19/19] igb: Fix lack of flush after register write and before delay Greg KH
2011-08-27 15:27 ` [00/19] 2.6.32.46-longterm review Christoph Biedl
2011-08-27 16:05 ` Greg KH
2011-08-27 16:25 ` Christoph Biedl
2011-08-28 12:34 ` Stratos Psomadakis
2011-08-28 15:07 ` [stable] " Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110826220120.816637549@clark.kroah.org \
--to=gregkh@suse.de \
--cc=akpm@linux-foundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=linux-kernel@vger.kernel.org \
--cc=sarah.a.sharp@linux.intel.com \
--cc=stable-review@kernel.org \
--cc=stable@kernel.org \
--cc=tiwai@suse.de \
--cc=torvalds@linux-foundation.org \
--cc=zonque@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox