[PATCH v3] ASoC: qcom: qdsp6: Add an error handling path in q6usb_component_probe()
From: Christophe JAILLET
Date: Sat Oct 24 2026 - 05:42:37 EST
If an error occurs after a successful q6usb_dai_add_aux_device() call,
some resources should be released as already done in the remove function.
Re-order the code to avoid unnecessarily destruction of devices in the
probe path and add an error handling path with the missing clean-up.
Fixes: 72b0b8b29980 ("ASoC: qcom: qdsp6: Add USB backend ASoC driver for Q6")
Signed-off-by: Christophe JAILLET <christophe.jaillet@xxxxxxxxxx>
---
Changes in v3:
- Reorder code to avoid unnecessarily destroy devices in the probe path
[Dmitry Baryshkov]
Changes in v2:
- Propagate the error code returned by snd_soc_usb_allocate_port()
instead of an explicit -ENOMEM. [Dan Carpenter]
v2: https://lore.kernel.org/lkml/1a3bf0ee02f880919190944e581bef2b428ca864.1751703113.git.christophe.jaillet@xxxxxxxxxx/
v1: https://lore.kernel.org/lkml/7338875b20cb41693f803c6b9673cf7f3e5f089a.1746781775.git.christophe.jaillet@xxxxxxxxxx/
---
sound/soc/qcom/qdsp6/q6usb.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/sound/soc/qcom/qdsp6/q6usb.c b/sound/soc/qcom/qdsp6/q6usb.c
index 6381b289c55c..e226dd126364 100644
--- a/sound/soc/qcom/qdsp6/q6usb.c
+++ b/sound/soc/qcom/qdsp6/q6usb.c
@@ -322,22 +322,26 @@ static int q6usb_component_probe(struct snd_soc_component *component)
struct snd_soc_usb *usb;
int ret;
- /* Add the QC USB SND aux device */
- ret = q6usb_dai_add_aux_device(data, &data->uauxdev);
- if (ret < 0)
- return ret;
-
usb = snd_soc_usb_allocate_port(component, &data->priv);
if (IS_ERR(usb))
- return -ENOMEM;
+ return PTR_ERR(usb);
usb->connection_status_cb = q6usb_alsa_connection_cb;
usb->update_offload_route_info = q6usb_update_offload_route;
+ /* Add the QC USB SND aux device */
+ ret = q6usb_dai_add_aux_device(data, &data->uauxdev);
+ if (ret < 0)
+ goto free_usb_port;
+
snd_soc_usb_add_port(usb);
data->usb = usb;
return 0;
+
+free_usb_port:
+ snd_soc_usb_free_port(usb);
+ return ret;
}
static void q6usb_component_remove(struct snd_soc_component *component)
--
2.56.0