Blob Blame History Raw
From b099b9693d23d035c77c218508e083484ff63024 Mon Sep 17 00:00:00 2001
From: Takashi Iwai <tiwai@suse.de>
Date: Wed, 2 May 2018 09:36:28 +0200
Subject: [PATCH] ALSA: usb-audio: Avoid superfluous usb_set_interface() calls
Git-commit: b099b9693d23d035c77c218508e083484ff63024
Patch-mainline: v4.18-rc1
References: bsc#1089467

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: Takashi Iwai <tiwai@suse.de>

---
 sound/usb/pcm.c |   11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

--- a/sound/usb/pcm.c
+++ b/sound/usb/pcm.c
@@ -507,7 +507,7 @@ static int set_format(struct snd_usb_sub
 	iface = usb_ifnum_to_if(dev, fmt->iface);
 	if (WARN_ON(!iface))
 		return -EINVAL;
-	alts = &iface->altsetting[fmt->altset_idx];
+	alts = usb_altnum_to_altsetting(iface, fmt->altsetting);
 	altsd = get_iface_desc(alts);
 	if (WARN_ON(altsd->bAlternateSetting != fmt->altsetting))
 		return -EINVAL;
@@ -529,9 +529,7 @@ static int set_format(struct snd_usb_sub
 	}
 
 	/* set interface */
-	if (subs->interface != fmt->iface ||
-	    subs->altset_idx != fmt->altset_idx) {
-
+	if (iface->cur_altsetting != alts) {
 		err = snd_usb_select_mode_quirk(subs, fmt);
 		if (err < 0)
 			return -EIO;
@@ -545,12 +543,11 @@ static int set_format(struct snd_usb_sub
 		}
 		dev_dbg(&dev->dev, "setting usb interface %d:%d\n",
 			fmt->iface, fmt->altsetting);
-		subs->interface = fmt->iface;
-		subs->altset_idx = fmt->altset_idx;
-
 		snd_usb_set_interface_quirk(dev);
 	}
 
+	subs->interface = fmt->iface;
+	subs->altset_idx = fmt->altset_idx;
 	subs->data_endpoint = snd_usb_add_endpoint(subs->stream->chip,
 						   alts, fmt->endpoint, subs->direction,
 						   SND_USB_ENDPOINT_TYPE_DATA);