All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] ALSA: usb-audio: fix PCM device order
@ 2019-07-27  9:30 Takashi Iwai
  2019-07-27  9:30 ` [PATCH v2 1/2] ALSA: usb-audio: Unify audioformat release code Takashi Iwai
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Takashi Iwai @ 2019-07-27  9:30 UTC (permalink / raw)
  To: alsa-devel; +Cc: Tanu Kaskinen, Alexander Tsoy

Hi,

this is a rewrite of the old USB-audio fix patch I obviously
overlooked to adapt to 5.3 kernel with a preliminary cleanup patch.

Totally untested, so any test / feedback would be appreciated.


thanks,

Takashi

===

Alexander Tsoy (1):
  ALSA: usb-audio: fix PCM device order

Takashi Iwai (1):
  ALSA: usb-audio: Unify audioformat release code

 sound/usb/stream.c | 64 +++++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 47 insertions(+), 17 deletions(-)

-- 
2.16.4

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/2] ALSA: usb-audio: Unify audioformat release code
  2019-07-27  9:30 [PATCH v2 0/2] ALSA: usb-audio: fix PCM device order Takashi Iwai
@ 2019-07-27  9:30 ` Takashi Iwai
  2019-07-27  9:30 ` [PATCH v2 2/2] ALSA: usb-audio: fix PCM device order Takashi Iwai
  2019-07-28  9:56 ` [PATCH v2 0/2] " Tanu Kaskinen
  2 siblings, 0 replies; 6+ messages in thread
From: Takashi Iwai @ 2019-07-27  9:30 UTC (permalink / raw)
  To: alsa-devel; +Cc: Tanu Kaskinen, Alexander Tsoy

There are many open code for releasing audioformat object.
Provide a unified helper and call it from the all places.

Only a cleanup, no functional changes.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/usb/stream.c | 30 ++++++++++++++----------------
 1 file changed, 14 insertions(+), 16 deletions(-)

diff --git a/sound/usb/stream.c b/sound/usb/stream.c
index 7ee9d17d0143..963d425004f8 100644
--- a/sound/usb/stream.c
+++ b/sound/usb/stream.c
@@ -28,6 +28,14 @@
 #include "power.h"
 #include "media.h"
 
+static void audioformat_free(struct audioformat *fp)
+{
+	list_del(&fp->list); /* unlink for avoiding double-free */
+	kfree(fp->rate_table);
+	kfree(fp->chmap);
+	kfree(fp);
+}
+
 /*
  * free a substream
  */
@@ -37,11 +45,8 @@ static void free_substream(struct snd_usb_substream *subs)
 
 	if (!subs->num_formats)
 		return; /* not initialized */
-	list_for_each_entry_safe(fp, n, &subs->fmt_list, list) {
-		kfree(fp->rate_table);
-		kfree(fp->chmap);
-		kfree(fp);
-	}
+	list_for_each_entry_safe(fp, n, &subs->fmt_list, list)
+		audioformat_free(fp);
 	kfree(subs->rate_list.list);
 	kfree(subs->str_pd);
 	snd_media_stream_delete(subs);
@@ -832,8 +837,7 @@ snd_usb_get_audioformat_uac12(struct snd_usb_audio *chip,
 	/* ok, let's parse further... */
 	if (snd_usb_parse_audio_format(chip, fp, format,
 					fmt, stream) < 0) {
-		kfree(fp->rate_table);
-		kfree(fp);
+		audioformat_free(fp);
 		return NULL;
 	}
 
@@ -1043,8 +1047,7 @@ snd_usb_get_audioformat_uac3(struct snd_usb_audio *chip,
 
 		pd = kzalloc(sizeof(*pd), GFP_KERNEL);
 		if (!pd) {
-			kfree(fp->rate_table);
-			kfree(fp);
+			audioformat_free(fp);
 			return NULL;
 		}
 		pd->pd_id = (stream == SNDRV_PCM_STREAM_PLAYBACK) ?
@@ -1063,9 +1066,7 @@ snd_usb_get_audioformat_uac3(struct snd_usb_audio *chip,
 		/* ok, let's parse further... */
 		if (snd_usb_parse_audio_format_v3(chip, fp, as, stream) < 0) {
 			kfree(pd);
-			kfree(fp->chmap);
-			kfree(fp->rate_table);
-			kfree(fp);
+			audioformat_free(fp);
 			return NULL;
 		}
 	}
@@ -1184,11 +1185,8 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
 			err = snd_usb_add_audio_stream(chip, stream, fp);
 
 		if (err < 0) {
-			list_del(&fp->list); /* unlink for avoiding double-free */
+			audioformat_free(fp);
 			kfree(pd);
-			kfree(fp->rate_table);
-			kfree(fp->chmap);
-			kfree(fp);
 			return err;
 		}
 		/* try to set the interface... */
-- 
2.16.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/2] ALSA: usb-audio: fix PCM device order
  2019-07-27  9:30 [PATCH v2 0/2] ALSA: usb-audio: fix PCM device order Takashi Iwai
  2019-07-27  9:30 ` [PATCH v2 1/2] ALSA: usb-audio: Unify audioformat release code Takashi Iwai
@ 2019-07-27  9:30 ` Takashi Iwai
  2019-07-28  9:56 ` [PATCH v2 0/2] " Tanu Kaskinen
  2 siblings, 0 replies; 6+ messages in thread
From: Takashi Iwai @ 2019-07-27  9:30 UTC (permalink / raw)
  To: alsa-devel; +Cc: Tanu Kaskinen, Alexander Tsoy

From: Alexander Tsoy <alexander@tsoy.me>

Some cards have alternate setting with non-PCM format as the first
altsetting in the interface descriptors. This confuses userspace, since
alsa-lib uses device 0 by default. So lets parse interfaces in two steps:
 1. Parse altsettings with PCM formats.
 2. Parse altsettings with non-PCM formats.

This fixes at least following cards:
 - Audinst HUD-mx2
 - Audinst HUD-mini

[ Adapted 5.3 kernel by tiwai ]

Signed-off-by: Alexander Tsoy <alexander@tsoy.me>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/usb/stream.c | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/sound/usb/stream.c b/sound/usb/stream.c
index 963d425004f8..fc3e9fcfbc38 100644
--- a/sound/usb/stream.c
+++ b/sound/usb/stream.c
@@ -1077,7 +1077,9 @@ snd_usb_get_audioformat_uac3(struct snd_usb_audio *chip,
 	return fp;
 }
 
-int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
+static int __snd_usb_parse_audio_interface(struct snd_usb_audio *chip,
+					   int iface_no,
+					   bool *has_non_pcm, bool non_pcm)
 {
 	struct usb_device *dev;
 	struct usb_interface *iface;
@@ -1178,6 +1180,16 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
 		else if (IS_ERR(fp))
 			return PTR_ERR(fp);
 
+		if (fp->fmt_type != UAC_FORMAT_TYPE_I)
+			*has_non_pcm = true;
+		if ((fp->fmt_type == UAC_FORMAT_TYPE_I) == non_pcm) {
+			audioformat_free(fp);
+			kfree(pd);
+			fp = NULL;
+			pd = NULL;
+			continue;
+		}
+
 		dev_dbg(&dev->dev, "%u:%d: add audio endpoint %#x\n", iface_no, altno, fp->endpoint);
 		if (protocol == UAC_VERSION_3)
 			err = snd_usb_add_audio_stream_v3(chip, stream, fp, pd);
@@ -1197,3 +1209,23 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
 	return 0;
 }
 
+int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
+{
+	int err;
+	bool has_non_pcm = false;
+
+	/* parse PCM formats */
+	err = __snd_usb_parse_audio_interface(chip, iface_no, &has_non_pcm, false);
+	if (err < 0)
+		return err;
+
+	if (has_non_pcm) {
+		/* parse non-PCM formats */
+		err = __snd_usb_parse_audio_interface(chip, iface_no, &has_non_pcm, true);
+		if (err < 0)
+			return err;
+	}
+
+	return 0;
+}
+
-- 
2.16.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/2] ALSA: usb-audio: fix PCM device order
  2019-07-27  9:30 [PATCH v2 0/2] ALSA: usb-audio: fix PCM device order Takashi Iwai
  2019-07-27  9:30 ` [PATCH v2 1/2] ALSA: usb-audio: Unify audioformat release code Takashi Iwai
  2019-07-27  9:30 ` [PATCH v2 2/2] ALSA: usb-audio: fix PCM device order Takashi Iwai
@ 2019-07-28  9:56 ` Tanu Kaskinen
  2019-12-30 18:01   ` [alsa-devel] " Alexander Tsoy
  2 siblings, 1 reply; 6+ messages in thread
From: Tanu Kaskinen @ 2019-07-28  9:56 UTC (permalink / raw)
  To: Takashi Iwai, alsa-devel; +Cc: Alexander Tsoy

On Sat, 2019-07-27 at 11:30 +0200, Takashi Iwai wrote:
> Hi,
> 
> this is a rewrite of the old USB-audio fix patch I obviously
> overlooked to adapt to 5.3 kernel with a preliminary cleanup patch.
> 
> Totally untested, so any test / feedback would be appreciated.

Thanks for the patches! Unfortunately I can't test them, and the
reporter who prompted me to ping apparently isn't going to test them
either. Hopefully the patches are still relevant to Alexander so maybe
he could test them.

-- 
Tanu

https://www.patreon.com/tanuk
https://liberapay.com/tanuk

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [alsa-devel] [PATCH v2 0/2] ALSA: usb-audio: fix PCM device order
  2019-07-28  9:56 ` [PATCH v2 0/2] " Tanu Kaskinen
@ 2019-12-30 18:01   ` Alexander Tsoy
  2019-12-30 21:27     ` Takashi Iwai
  0 siblings, 1 reply; 6+ messages in thread
From: Alexander Tsoy @ 2019-12-30 18:01 UTC (permalink / raw)
  To: Tanu Kaskinen, Takashi Iwai, alsa-devel

В Вс, 28/07/2019 в 12:56 +0300, Tanu Kaskinen пишет:
> On Sat, 2019-07-27 at 11:30 +0200, Takashi Iwai wrote:
> > Hi,
> > 
> > this is a rewrite of the old USB-audio fix patch I obviously
> > overlooked to adapt to 5.3 kernel with a preliminary cleanup patch.
> > 
> > Totally untested, so any test / feedback would be appreciated.
> 
> Thanks for the patches! Unfortunately I can't test them, and the
> reporter who prompted me to ping apparently isn't going to test them
> either. Hopefully the patches are still relevant to Alexander so
> maybe
> he could test them.

Sorry for the late reply, I messed up my mail filters. HUD-mx2 now
works as expected without workarounds in alsa or pulse. Tested with
5.4.x. Thanks!

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [alsa-devel] [PATCH v2 0/2] ALSA: usb-audio: fix PCM device order
  2019-12-30 18:01   ` [alsa-devel] " Alexander Tsoy
@ 2019-12-30 21:27     ` Takashi Iwai
  0 siblings, 0 replies; 6+ messages in thread
From: Takashi Iwai @ 2019-12-30 21:27 UTC (permalink / raw)
  To: Alexander Tsoy; +Cc: Tanu Kaskinen, alsa-devel

On Mon, 30 Dec 2019 19:01:43 +0100,
Alexander Tsoy wrote:
> 
> В Вс, 28/07/2019 в 12:56 +0300, Tanu Kaskinen пишет:
> > On Sat, 2019-07-27 at 11:30 +0200, Takashi Iwai wrote:
> > > Hi,
> > > 
> > > this is a rewrite of the old USB-audio fix patch I obviously
> > > overlooked to adapt to 5.3 kernel with a preliminary cleanup patch.
> > > 
> > > Totally untested, so any test / feedback would be appreciated.
> > 
> > Thanks for the patches! Unfortunately I can't test them, and the
> > reporter who prompted me to ping apparently isn't going to test them
> > either. Hopefully the patches are still relevant to Alexander so
> > maybe
> > he could test them.
> 
> Sorry for the late reply, I messed up my mail filters. HUD-mx2 now
> works as expected without workarounds in alsa or pulse. Tested with
> 5.4.x. Thanks!

Good to hear.

So far there is no real regression report, so it seems working for
other devices, too.


thanks,

Takashi
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-12-30 21:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-27  9:30 [PATCH v2 0/2] ALSA: usb-audio: fix PCM device order Takashi Iwai
2019-07-27  9:30 ` [PATCH v2 1/2] ALSA: usb-audio: Unify audioformat release code Takashi Iwai
2019-07-27  9:30 ` [PATCH v2 2/2] ALSA: usb-audio: fix PCM device order Takashi Iwai
2019-07-28  9:56 ` [PATCH v2 0/2] " Tanu Kaskinen
2019-12-30 18:01   ` [alsa-devel] " Alexander Tsoy
2019-12-30 21:27     ` Takashi Iwai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.