Commit e98696ed authored by Takashi Iwai's avatar Takashi Iwai
Browse files

ALSA: usb-audio: Avoid potentially repeated XRUN error messages

Some XRUN-related error messages may repeat themselves, because there
can be multiple pending packets.  Modify notify_xrun() function to
return whether it's being stopped or not, and show the error message
only once when the XRUN is actually handled.

Along with it, fix a typo of word package to packet in the error
message.

Link: https://patch.msgid.link/20260216141209.1849200-5-tiwai@suse.de


Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent fba2105a
Loading
Loading
Loading
Loading
+14 −9
Original line number Diff line number Diff line
@@ -402,18 +402,21 @@ static int prepare_inbound_urb(struct snd_usb_endpoint *ep,
}

/* notify an error as XRUN to the assigned PCM data substream */
static void notify_xrun(struct snd_usb_endpoint *ep)
static bool notify_xrun(struct snd_usb_endpoint *ep)
{
	struct snd_usb_substream *data_subs;
	struct snd_pcm_substream *psubs;

	data_subs = READ_ONCE(ep->data_subs);
	if (!data_subs)
		return;
		return false;
	psubs = data_subs->pcm_substream;
	if (psubs && psubs->runtime &&
	    psubs->runtime->state == SNDRV_PCM_STATE_RUNNING)
	    psubs->runtime->state == SNDRV_PCM_STATE_RUNNING) {
		snd_pcm_stop_xrun(psubs);
		return true;
	}
	return false;
}

static struct snd_usb_packet_info *
@@ -594,8 +597,9 @@ static void snd_complete_urb(struct urb *urb)
		return;

	if (!atomic_read(&ep->chip->shutdown)) {
		usb_audio_err(ep->chip, "cannot submit urb (err = %d)\n", err);
		notify_xrun(ep);
		if (notify_xrun(ep))
			usb_audio_err(ep->chip,
				      "cannot submit urb (err = %d)\n", err);
	}

exit_clear:
@@ -1779,10 +1783,11 @@ static void snd_usb_handle_sync_urb(struct snd_usb_endpoint *ep,
		spin_lock_irqsave(&ep->lock, flags);
		if (ep->next_packet_queued >= ARRAY_SIZE(ep->next_packet)) {
			spin_unlock_irqrestore(&ep->lock, flags);
			if (notify_xrun(ep)) {
				usb_audio_err(ep->chip,
				      "next package FIFO overflow EP 0x%x\n",
					      "next packet FIFO overflow EP 0x%x\n",
					      ep->ep_num);
			notify_xrun(ep);
			}
			return;
		}