Re: [PATCH] usb: typec: ucsi: destroy work queue on fwnode_usb_role_switch_get() fails

From: Heikki Krogerus

Date: Wed Jun 24 2026 - 06:57:05 EST


On Wed, Jun 24, 2026 at 04:13:01PM +0800, Haoxiang Li wrote:
> Call destroy_workqueue() if fwnode_usb_role_switch_get() fails
> to destroy the work queue con->wq.
>
> Fixes: 3c162511530c ("usb: typec: ucsi: Wait for the USB role switches")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Haoxiang Li <haoxiang_li2024@xxxxxxx>
> ---
> drivers/usb/typec/ucsi/ucsi.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index 61cb24ed820f..63303e26929f 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -1663,9 +1663,11 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con)
>
> cap->fwnode = ucsi_find_fwnode(con);
> con->usb_role_sw = fwnode_usb_role_switch_get(cap->fwnode);
> - if (IS_ERR(con->usb_role_sw))
> + if (IS_ERR(con->usb_role_sw)) {
> + destroy_workqueue(con->wq);
> return dev_err_probe(ucsi->dev, PTR_ERR(con->usb_role_sw),
> "con%d: failed to get usb role switch\n", con->num);
> + }

You need to add a label err_destroy_workqueue after the
mutex_unlock(&con->lock) and then here:

if (IS_ERR(con->usb_role_sw)) {
ret = PTR_ERR(con->usb_role_sw);
dev_err(ucsi->dev, "con%d: failed to get usb role switch\n", con->num);
goto err_destroy_workqueue;
}

thanks,

--
heikki