Skip to contentSkip to conversation

ALSA: use irqsave in USB's completion callback

PATCH Applied Sebastian Andrzej Siewior 4 participants 6 messages Jul 1, 2018 – Jul 2, 2018

Subsystems (3)

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover ALSA: use irqsave in USB's completion callback

This series is about using _irqsave() primitives in the completion callback in order to get rid of local_irq_save() in __usb_hcd_giveback_urb().

Sebastian

#1 lore raw

PATCH 1/2 ALSA: usb: caiaq: audio: use irqsave() in USB's complete callback

From: John Ogness <[email protected]>

The USB completion callback does not disable interrupts while acquiring the lock. We want to remove the local_irq_disable() invocation from __usb_hcd_giveback_urb() and therefore it is required for the callback handler to disable the interrupts while acquiring the lock. The callback may be invoked either in IRQ or BH context depending on the USB host controller.
Use the _irqsave() variant of the locking primitives.

---
 sound/usb/caiaq/audio.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
sound/usb/caiaq/audio.c +3 -2
index f35d29f49ffe..15344d39a6cd 100644
@@ -636,6 +636,7 @@ static void read_completed(struct urb *urb)
 	struct device *dev;
 	struct urb *out = NULL;
 	int i, frame, len, send_it = 0, outframe = 0;
+	unsigned long flags;
 	size_t offset = 0;
 
 	if (urb->status || !info)
@@ -672,10 +673,10 @@ static void read_completed(struct urb *urb)
 		offset += len;
 
 		if (len > 0) {
-			spin_lock(&cdev->spinlock);
+			spin_lock_irqsave(&cdev->spinlock, flags);
 			fill_out_urb(cdev, out, &out->iso_frame_desc[outframe]);
 			read_in_urb(cdev, urb, &urb->iso_frame_desc[frame]);
-			spin_unlock(&cdev->spinlock);
+			spin_unlock_irqrestore(&cdev->spinlock, flags);
 			check_for_elapsed_periods(cdev, cdev->sub_playback);
 			check_for_elapsed_periods(cdev, cdev->sub_capture);
 			send_it = 1;
Signature · 1 line
2.18.0
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH REPOST 1/2] ALSA: usb: caiaq: audio: use irqsave() in USB's complete callback

Quoted 9 lines · Sebastian Andrzej Siewior

From: John Ogness <[email protected]>

The USB completion callback does not disable interrupts while acquiring the lock. We want to remove the local_irq_disable() invocation from __usb_hcd_giveback_urb() and therefore it is required for the callback handler to disable the interrupts while acquiring the lock. The callback may be invoked either in IRQ or BH context depending on the USB host controller.
Use the _irqsave() variant of the locking primitives.

Quoted 34 lines
---
  sound/usb/caiaq/audio.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
sound/usb/caiaq/audio.c +3 -2
index f35d29f49ffe..15344d39a6cd 100644
@@ -636,6 +636,7 @@ static void read_completed(struct urb *urb)
  	struct device *dev;
  	struct urb *out = NULL;
  	int i, frame, len, send_it = 0, outframe = 0;
+	unsigned long flags;
  	size_t offset = 0;
 
  	if (urb->status || !info)
@@ -672,10 +673,10 @@ static void read_completed(struct urb *urb)
  		offset += len;
 
  		if (len > 0) {
-			spin_lock(&cdev->spinlock);
+			spin_lock_irqsave(&cdev->spinlock, flags);
  			fill_out_urb(cdev, out, &out->iso_frame_desc[outframe]);
  			read_in_urb(cdev, urb, &urb->iso_frame_desc[frame]);
-			spin_unlock(&cdev->spinlock);
+			spin_unlock_irqrestore(&cdev->spinlock, flags);
  			check_for_elapsed_periods(cdev, cdev->sub_playback);
  			check_for_elapsed_periods(cdev, cdev->sub_capture);
  			send_it = 1;
#3 lore raw

PATCH 2/2 ALSA: usb-midi: use irqsave() in USB's complete callback

In reply to Sebastian Andrzej Siewior

From: John Ogness <[email protected]>

The USB completion callback does not disable interrupts while acquiring the lock. We want to remove the local_irq_disable() invocation from __usb_hcd_giveback_urb() and therefore it is required for the callback handler to disable the interrupts while acquiring the lock. The callback may be invoked either in IRQ or BH context depending on the USB host controller.
Use the _irqsave() variant of the locking primitives.

Cc Clemens Ladisch <[email protected]>
Cc Jaroslav Kysela <[email protected]>
Cc Takashi Iwai <[email protected]>
---
 sound/usb/midi.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
sound/usb/midi.c +3 -2
index 2c1aaa3292bf..dcfc546d81b9 100644
@@ -281,15 +281,16 @@ static void snd_usbmidi_out_urb_complete(struct urb *urb)
 	struct out_urb_context *context = urb->context;
 	struct snd_usb_midi_out_endpoint *ep = context->ep;
 	unsigned int urb_index;
+	unsigned long flags;
 
-	spin_lock(&ep->buffer_lock);
+	spin_lock_irqsave(&ep->buffer_lock, flags);
 	urb_index = context - ep->urbs;
 	ep->active_urbs &= ~(1 << urb_index);
 	if (unlikely(ep->drain_urbs)) {
 		ep->drain_urbs &= ~(1 << urb_index);
 		wake_up(&ep->drain_wait);
 	}
-	spin_unlock(&ep->buffer_lock);
+	spin_unlock_irqrestore(&ep->buffer_lock, flags);
 	if (urb->status < 0) {
 		int err = snd_usbmidi_urb_error(urb);
 		if (err < 0) {
Signature · 1 line
2.18.0
maintainer Acked-by on v1 2/2
#4 lore raw

Re: [PATCH REPOST 2/2] ALSA: usb-midi: use irqsave() in USB's complete callback

Quoted 10 lines · Sebastian Andrzej Siewior

From: John Ogness <[email protected]>

The USB completion callback does not disable interrupts while acquiring the lock. We want to remove the local_irq_disable() invocation from __usb_hcd_giveback_urb() and therefore it is required for the callback handler to disable the interrupts while acquiring the lock. The callback may be invoked either in IRQ or BH context depending on the USB host controller.
Use the _irqsave() variant of the locking primitives.

Quoted 5 lines
Cc Clemens Ladisch <[email protected]>
Cc Jaroslav Kysela <[email protected]>
Cc Takashi Iwai <[email protected]>
Quoted 27 lines
---
 sound/usb/midi.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
sound/usb/midi.c +3 -2
index 2c1aaa3292bf..dcfc546d81b9 100644
@@ -281,15 +281,16 @@ static void snd_usbmidi_out_urb_complete(struct urb *urb)
 	struct out_urb_context *context = urb->context;
 	struct snd_usb_midi_out_endpoint *ep = context->ep;
 	unsigned int urb_index;
+	unsigned long flags;
 
-	spin_lock(&ep->buffer_lock);
+	spin_lock_irqsave(&ep->buffer_lock, flags);
 	urb_index = context - ep->urbs;
 	ep->active_urbs &= ~(1 << urb_index);
 	if (unlikely(ep->drain_urbs)) {
 		ep->drain_urbs &= ~(1 << urb_index);
 		wake_up(&ep->drain_wait);
 	}
-	spin_unlock(&ep->buffer_lock);
+	spin_unlock_irqrestore(&ep->buffer_lock, flags);
 	if (urb->status < 0) {
 		int err = snd_usbmidi_urb_error(urb);
 		if (err < 0) {
Applied
#5 lore raw
In reply to Sebastian Andrzej Siewior
Quoted 3 lines · Sebastian Andrzej Siewior

This series is about using _irqsave() primitives in the completion callback in order to get rid of local_irq_save() in __usb_hcd_giveback_urb().

Applied both patches now. Thanks.

Takashi