[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <671a524d-b4c8-78d8-33de-40170a23d189@linux.intel.com>
Date: Tue, 25 Jul 2023 11:15:11 +0200
From: Pierre-Louis Bossart <pierre-louis.bossart@...ux.intel.com>
To: Wesley Cheng <quic_wcheng@...cinc.com>, agross@...nel.org,
andersson@...nel.org, robh+dt@...nel.org,
krzysztof.kozlowski+dt@...aro.org, conor+dt@...nel.org,
catalin.marinas@....com, will@...nel.org, mathias.nyman@...el.com,
gregkh@...uxfoundation.org, lgirdwood@...il.com,
broonie@...nel.org, perex@...ex.cz, tiwai@...e.com,
srinivas.kandagatla@...aro.org, bgoswami@...cinc.com,
Thinh.Nguyen@...opsys.com
Cc: linux-arm-msm@...r.kernel.org, devicetree@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
linux-usb@...r.kernel.org, alsa-devel@...a-project.org,
quic_jackp@...cinc.com, oneukum@...e.com, albertccwang@...gle.com,
o-takashi@...amocchi.jp
Subject: Re: [PATCH v4 31/32] sound: usb: card: Allow for rediscovery of
connected USB SND devices
On 7/25/23 04:34, Wesley Cheng wrote:
> In case of notifying SND platform drivers of connection events, some of
> these use cases, such as offloading, require an ASoC USB backend device to
> be initialized before the events can be handled. If the USB backend device
> has not yet been probed, this leads to missing initial USB audio device
> connection events.
>
> Expose an API that traverses the usb_chip array for connected devices, and
> to call the respective connection callback registered to the SND platform
> driver.
>
> Signed-off-by: Wesley Cheng <quic_wcheng@...cinc.com>
> ---
> sound/usb/card.c | 19 +++++++++++++++++++
> sound/usb/card.h | 2 ++
> 2 files changed, 21 insertions(+)
>
> diff --git a/sound/usb/card.c b/sound/usb/card.c
> index 365f6d978608..27a89aaa0bf3 100644
> --- a/sound/usb/card.c
> +++ b/sound/usb/card.c
> @@ -170,6 +170,25 @@ struct snd_usb_stream *snd_usb_find_suppported_substream(int card_idx,
> }
> EXPORT_SYMBOL_GPL(snd_usb_find_suppported_substream);
>
> +/*
> + * in case the platform driver was not ready at the time of USB SND
> + * device connect, expose an API to discover all connected USB devices
> + * so it can populate any dependent resources/structures.
> + */
> +void snd_usb_rediscover_devices(void)
> +{
> + int i;
> +
> + mutex_lock(®ister_mutex);
> + for (i = 0; i < SNDRV_CARDS; i++) {
> + if (usb_chip[i])
> + if (platform_ops && platform_ops->connect_cb)
> + platform_ops->connect_cb(usb_chip[i]);
what happens if the USB device is removed while the platform device adds
a port?
This sounds super-racy to me. It's the same set of problems we're having
between audio and display/DRM, I would be surprised if this function
dealt with all corner cases of insertion/removal, bind/unbind.
> + }
> + mutex_unlock(®ister_mutex);
> +}
> +EXPORT_SYMBOL_GPL(snd_usb_rediscover_devices);
> +
> /*
> * disconnect streams
> * called from usb_audio_disconnect()
> diff --git a/sound/usb/card.h b/sound/usb/card.h
> index db735680d155..dfd241334e3d 100644
> --- a/sound/usb/card.h
> +++ b/sound/usb/card.h
> @@ -219,6 +219,7 @@ int snd_usb_register_platform_ops(struct snd_usb_platform_ops *ops);
> int snd_usb_unregister_platform_ops(void);
> struct snd_usb_stream *snd_usb_find_suppported_substream(int card_idx,
> struct snd_pcm_hw_params *params, int direction);
> +void snd_usb_rediscover_devices(void);
> #else
> static int snd_usb_register_platform_ops(struct snd_usb_platform_ops *ops)
> {
> @@ -235,5 +236,6 @@ static struct snd_usb_stream *snd_usb_find_suppported_substream(int card_idx,
> {
> return NULL;
> }
> +void snd_usb_rediscover_devices(void) { }
> #endif /* IS_ENABLED(CONFIG_SND_USB_AUDIO) */
> #endif /* __USBAUDIO_CARD_H */
Powered by blists - more mailing lists