Thread (87 messages) 87 messages, 5 authors, 2024-08-21

[PATCH v24 31/34] ASoC: usb: Rediscover USB SND devices on USB port add

flat view
STALE793d SUPERSEDED

From: Wesley Cheng <hidden>
Date: 2024-08-01 01:18:44
Also in: alsa-devel, linux-arm-msm, linux-doc, linux-sound, linux-usb, lkml
Subsystem: sound, sound - soc layer / dynamic audio power management (asoc), the rest · Maintainers: Jaroslav Kysela, Takashi Iwai, Liam Girdwood, Mark Brown, Linus Torvalds

Revision v24 of 36 in this series.

Revisions (36)
  1. v4 [diff vs current]
  2. v5 [diff vs current]
  3. v6 [diff vs current]
  4. v7 [diff vs current]
  5. v8 [diff vs current]
  6. v9 [diff vs current]
  7. v10 [diff vs current]
  8. v11 [diff vs current]
  9. v12 [diff vs current]
  10. v13 [diff vs current]
  11. v14 [diff vs current]
  12. v15 [diff vs current]
  13. v16 [diff vs current]
  14. v17 [diff vs current]
  15. v18 [diff vs current]
  16. v19 [diff vs current]
  17. v20 [diff vs current]
  18. v21 [diff vs current]
  19. v22 [diff vs current]
  20. v23 [diff vs current]
  21. v24 current
  22. v25 [diff vs current]
  23. v26 [diff vs current]
  24. v27 [diff vs current]
  25. v28 [diff vs current]
  26. v28 [diff vs current]
  27. v28 [diff vs current]
  28. v29 [diff vs current]
  29. v31 [diff vs current]
  30. v32 [diff vs current]
  31. v33 [diff vs current]
  32. v34 [diff vs current]
  33. v35 [diff vs current]
  34. v36 [diff vs current]
  35. v37 [diff vs current]
  36. v38 [diff vs current]
In case the USB backend device has not been initialized/probed, USB SND
device connections can still occur.  When the USB backend is eventually
made available, previous USB SND device connections are not communicated to
the USB backend.  Call snd_usb_rediscover_devices() to generate the connect
callbacks for all USB SND devices connected.  This will allow for the USB
backend to be updated with the current set of devices available.

The chip array entries are all populated and removed while under the
register_mutex, so going over potential race conditions:

Thread#1:
  q6usb_component_probe()
    --> snd_soc_usb_add_port()
      --> snd_usb_rediscover_devices()
        --> mutex_lock(register_mutex)

Thread#2
  --> usb_audio_disconnect()
    --> mutex_lock(register_mutex)

So either thread#1 or thread#2 will complete first.  If

Thread#1 completes before thread#2:
  SOC USB will notify DPCM backend of the device connection.  Shortly
  after, once thread#2 runs, we will get a disconnect event for the
  connected device.

Thread#2 completes before thread#1:
  Then during snd_usb_rediscover_devices() it won't notify of any
  connection for that particular chip index.

Signed-off-by: Wesley Cheng <redacted>
---
 sound/soc/soc-usb.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/sound/soc/soc-usb.c b/sound/soc/soc-usb.c
index 3c217ac67c57..b891beb77001 100644
--- a/sound/soc/soc-usb.c
+++ b/sound/soc/soc-usb.c
@@ -216,6 +216,8 @@ void snd_soc_usb_add_port(struct snd_soc_usb *usb)
 	mutex_lock(&ctx_mutex);
 	list_add_tail(&usb->list, &usb_ctx_list);
 	mutex_unlock(&ctx_mutex);
+
+	snd_usb_rediscover_devices();
 }
 EXPORT_SYMBOL_GPL(snd_soc_usb_add_port);
 
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help