From eeef1223025c68bd546a1f9411bdcdf518f8cb97 Mon Sep 17 00:00:00 2001 From: Stephan Gerhold Date: Mon, 7 Apr 2025 16:59:35 +0200 Subject: usb: gadget: f_acm: Claim requested USB endpoints U-Boot has an older version of the Linux gadget API, where USB endpoints returned by usb_ep_autoconfig() are not automatically claimed. As written in the documentation comment: "To prevent the endpoint from being returned by a later autoconfig call, claim it by assigning ep->driver_data to some non-null value." Right now f_acm doesn't do that, which means that e.g. ep_in and ep_notify may end up being assigned the same endpoint. Surprisingly, the ACM console is still somehow working, but this is not the expected behavior. It will break with a later commit that disallows calling usb_ep_enable() multiple times. Fix this by assigning some data to ep->driver_data, similar to the other gadget drivers. Fixes: fc2b399ac03b ("usb: gadget: Add CDC ACM function") Signed-off-by: Stephan Gerhold Reviewed-by: Mattijs Korpershoek Link: https://lore.kernel.org/r/20250407-acm-fixes-v1-1-e3dcb592d6d6@linaro.org Signed-off-by: Mattijs Korpershoek --- drivers/usb/gadget/f_acm.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'drivers') diff --git a/drivers/usb/gadget/f_acm.c b/drivers/usb/gadget/f_acm.c index f18c6a0a761..2665fa4168f 100644 --- a/drivers/usb/gadget/f_acm.c +++ b/drivers/usb/gadget/f_acm.c @@ -238,18 +238,21 @@ static int acm_bind(struct usb_configuration *c, struct usb_function *f) return -ENODEV; f_acm->ep_in = ep; + ep->driver_data = c->cdev; /* claim */ ep = usb_ep_autoconfig(gadget, &acm_fs_out_desc); if (!ep) return -ENODEV; f_acm->ep_out = ep; + ep->driver_data = c->cdev; /* claim */ ep = usb_ep_autoconfig(gadget, &acm_fs_notify_desc); if (!ep) return -ENODEV; f_acm->ep_notify = ep; + ep->driver_data = c->cdev; /* claim */ if (gadget_is_dualspeed(gadget)) { /* Assume endpoint addresses are the same for both speeds */ -- cgit v1.3.1 From 22b5aad20ae0f17bd9617fb9c10ddb38d2b91920 Mon Sep 17 00:00:00 2001 From: Stephan Gerhold Date: Mon, 7 Apr 2025 16:59:36 +0200 Subject: usb: gadget: f_acm: Allow restarting ACM console after stopping it When using IOMUX, the "usbacm" console can be added/removed dynamically from the stdout/stderr/stdin environment variables to allow temporarily starting other USB gadgets (e.g. Fastboot). However, right now acm_stdio_stop() does not completely undo acm_stdio_start(): The USB gadget is unregistered, but as long as dev->priv stays set acm_stdio_start() will never register the USB gadget again. Clear dev->priv after we detach to make sure a start operation after a stop operation registers the gadget again. Fixes: fc2b399ac03b ("usb: gadget: Add CDC ACM function") Signed-off-by: Stephan Gerhold Reviewed-by: Mattijs Korpershoek Link: https://lore.kernel.org/r/20250407-acm-fixes-v1-2-e3dcb592d6d6@linaro.org Signed-off-by: Mattijs Korpershoek --- drivers/usb/gadget/f_acm.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers') diff --git a/drivers/usb/gadget/f_acm.c b/drivers/usb/gadget/f_acm.c index 2665fa4168f..8f7256069f5 100644 --- a/drivers/usb/gadget/f_acm.c +++ b/drivers/usb/gadget/f_acm.c @@ -663,6 +663,7 @@ static int acm_stdio_stop(struct stdio_dev *dev) { g_dnl_unregister(); g_dnl_clear_detach(); + dev->priv = NULL; return 0; } -- cgit v1.3.1