From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796033889; b=NFo1vfBIYT4yRGsHL3pp+4QvUxKgCAHXrX29Hs7KeeCoBiLN/y7vNlRbH1fHPfoA5qL5 2zbYBWDVoKrky9O86lgu4wP77yTzFo+1yeQD1vyr6jbbRFeY8y2OTeqAW61IY0jkIVWC7 Z+rPWv0srgTh5l026A+hqfqO9NLbzA1FrfkDwCPtL9pzG2rqDZauADxsl++4/ftLq2HvE wj7JjdLCDFA5p99XjajPpOyqEBlbNn2QQ7gfkC4Jwx8Xi1gXlLYragYa2js0jDJwHWN+p D9Q6HY70QQ4CNZwtmpmKpX61Ap6ULyiOcqu5MrOBPy+nvcULJ7EceTM6yXJZJ8hjy+w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796033889; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=bf60ADg7uDMzuzjr+VMdwXO1yu+g5c0FJomvzeEzZxA=; b=uAIZ9t1OUgk0j44VJXkMhL0USl+poMXH7/GwJ/LXJts2q7pyUkg1SDO4rbOHKI9gYBUj X0m8BmUbMkndJQhpRHC3G+zNGlDECoviSg59fOm6QBwto4x8zkKvWl9EkuKgAweo2b3wQ LoE8qJWtjKopCcpnmOT913cy6d1XbbIP/wFyVSvhx9lyB6U8gFz6X2sLzFLONPUZHtNCu Epy1VryAZI00djK83LI52CR4/NDXrNwTx5e1ASTrNnw6WjkmFjzWCYrkOXz/Wuwv4D9nQ Wobd6DLO89QXsOQjI0RWtTcv893WM9K0rCeQRK46wnCW9TqP2iik6aa/+RsDEIRGuFQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=A2RXnNIu; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B95B606A325; Mon, 30 Nov 2026 10:18:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=A2RXnNIu Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9A2031F0089A; Mon, 30 Nov 2026 10:18:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796033888; bh=bf60ADg7uDMzuzjr+VMdwXO1yu+g5c0FJomvzeEzZxA=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=A2RXnNIuLUh7S1OrUzo+Dvg5pocIty808R0pShodtjhbGM2HVnlRlZTfN9reqN2YK VymvaXTtCW/nvTQ1Cn+RLzHUQwfYYbDePo/nwOGhDQh1ROmGg8QuppD8zLR5oGObls Q83gfvpJPPOg8OQTu+vRt3qNuft4/ruRY3sSqsE7tbonmj/Z2EJO9cgZ+1B4w4s+p3 11HaEVFC2zJ9Tuthmpai3eyNfNgGT+iOUkojs4GsWsLaQGbvMyzBVh49xk65woYVfN W5Ub50qWIhrY33At/Ki7OqTwIcL1ME8ghcBbJnGRN6Oe7B8SocWaAOCJkOxVL1jh1o g5Gbdu5VUdLKg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v7 6/6] usb: gadget: udc: crg: Add core driver and build integration Reply-To: sashiko-reviews@lists.linux.dev To: "Petar Stepanovic" Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261130-axiado-ax3000-usb-device-controller-v7-6-f240b1418955@axiado.com> References: <20261130-axiado-ax3000-usb-device-controller-v7-0-f240b1418955@axiado.com> <20261130-axiado-ax3000-usb-device-controller-v7-6-f240b1418955@axiado.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 10:18:08 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [Medium] usb: gadget: udc: crg: lost sys_err disconnect in crg_udc_recover_endpoints() - [Medium] usb: gadget: udc: crg: stale usb_ep.enabled in crg_udc_suspend() after recovery - [Medium] usb: gadget: udc: crg: lost disconnect after failed crg_udc_recover_link() - [Medium] usb: gadget: udc: crg: stale suspend_complete in crg_udc_resume() stop path -- commit 77e0293ca43dcccddf4befcaabeb5cdfcd607a9d Author: Petar Stepanovic usb: gadget: udc: crg: Add core driver and build integration This commit adds the core platform driver, controller reset and recovery handling, power management callbacks, and Kconfig/Makefile integration for the Axiado AX3000/AX3005 USB Device Controller. > diff --git a/drivers/usb/gadget/udc/crg/crg-udc-core.c b/drivers/usb/gadg= et/udc/crg/crg-udc-core.c > new file mode 100644 > index 0000000000000..9177f5532db71 > --- /dev/null > +++ b/drivers/usb/gadget/udc/crg/crg-udc-core.c [ ... ] > +static int crg_udc_suspend(struct device *dev) > +{ > + struct crg_gadget_dev *crg_udc =3D dev_get_drvdata(dev); > + unsigned long flags; > + bool notify_disconnect; > + int i, ret; [ ... ] > + /* > + * Return requests before disconnect callbacks can free them. Keep > + * usb_ep.enabled visible until the function drivers disable their > + * endpoints. A failed halt leaves DMA mappings in quarantine. > + */ > + notify_disconnect =3D crg_udc->connected || crg_udc->bus_reset_pending; > + crg_udc->connected =3D false; > + crg_udc->bus_reset_pending =3D false; > + /* Use completed recovery or leave a pending reset to the worker. */ > + ret =3D crg_udc->suspend_recovery_result; > + if (ret =3D=3D -EINPROGRESS || (ret && !crg_udc->external_reset_pending= )) > + ret =3D crg_udc_recover(crg_udc, &flags, notify_disconnect); > + /* Endpoint disable can start a giveback while reset drops udc_lock. */ > + wait_event_lock_irq(crg_udc->teardown_wait, > + !crg_udc->gadget_callbacks_active, crg_udc->udc_lock); > + if (notify_disconnect && !crg_udc->gadget_stopping && > + !crg_udc->shutting_down) > + crg_udc_notify_disconnect(crg_udc, &flags); > + > + /* Disconnect drops udc_lock and may race with gadget teardown. */ > + if (crg_udc->gadget_stopping || crg_udc->shutting_down) { > + ret =3D ret ?: -EBUSY; > + goto failed; > + } > + if (notify_disconnect) > + for (i =3D 2; i < CRG_NUM_EP_CX; i++) > + crg_udc_ep_clear_enabled(&crg_udc->udc_ep[i]); [Severity: Medium] Can this leave usb_ep.enabled set on data endpoints after crg_udc_suspend() when notify_disconnect is false? While crg_udc_suspend() waits on teardown_wait for gadget_callbacks_active to drain, an in-flight disconnect or completion callback that hits a register poll timeout in crg_udc_ep_disable() calls crg_udc_recover_endpoints(). Because crg_udc->suspended is already true, crg_udc_recover_endpoints() calls crg_udc_recover(crg_udc, flags, true), which resets all data endpoints to EP_STATE_DISABLED with ep->desc =3D NULL while preserving usb_ep.enabled =3D true, and records suspend_recovery_result =3D 0. When that callback finishes with connected and bus_reset_pending already false, notify_disconnect is false and suspend_recovery_result is 0, so crg_udc_suspend() skips both crg_udc_recover(..., false) and the crg_udc_ep_clear_enabled() loop. Any endpoint not explicitly disabled by that callback stays marked enabled in the gadget core while disabled in the driver, causing later usb_ep_enable() calls to fail with -EBUSY. [ ... ] > +static int crg_udc_resume(struct device *dev) > +{ > + struct crg_gadget_dev *crg_udc =3D dev_get_drvdata(dev); > + int ret =3D 0; > + > + spin_lock_irq(&crg_udc->udc_lock); > + /* A gadget stopped while suspended deferred its hardware cleanup. */ > + if (crg_udc->suspend_complete && crg_udc->gadget_stopping && > + !crg_udc->controller_recovering && !crg_udc->shutting_down && > + crg_udc->hw_dma_armed) > + ret =3D crg_udc_finish_gadget_stop(crg_udc); > + > + crg_udc->suspend_complete =3D false; > + crg_udc->suspended =3D false; [Severity: Medium] Does leaving suspend_complete set across crg_udc_finish_gadget_stop() allow a concurrent crg_udc_stop_gadget() to return before hardware DMA is quiesced? CPU0 CPU1 crg_udc_resume() crg_udc_finish_gadget_stop() crg_udc_recovery_begin() spin_unlock_irq(&udc_lock) crg_udc_quiesce_hw() crg_udc_stop_gadget() if (crg_udc->suspend_complete) goto stopped_suspended; return 0; <-- DMA still active If the gadget was stopped while suspended (for example via pullup(0) at the start of gadget_unbind_driver()), crg_udc_stop_gadget() deferred hardware quiescing to crg_udc_resume(). Because crg_udc_stop_gadget() checks suspend_complete before waiting on teardown_wait for !controller_recovering, a second crg_udc_stop_gadget() call during unbind returns while crg_udc_quiesce_hw() is still running, and a subsequent start or pullup(1) can observe controller_recovering or suspended still set and fail with -EBUSY or -ESHUTDOWN. Clearing suspend_complete and suspended before calling crg_udc_finish_gadget_stop() would force concurrent callers to wait for the quiesce to finish. [ ... ] > +/* Called with udc_lock held for recovery of a live USB session. */ > +int crg_udc_recover_link(struct crg_gadget_dev *crg_udc, unsigned long *= flags, > + bool notify_reset) > +{ > + int ret; > + > + if (crg_udc->controller_recovering || crg_udc->shutting_down || > + crg_udc->gadget_stopping || crg_udc->suspended || > + crg_udc->hw_reset_asserted) > + return -EBUSY; > + > + notify_reset =3D notify_reset && crg_udc->async_callbacks && > + crg_udc->gadget_driver && !crg_udc->reset_callback_active; > + crg_udc->connected =3D false; > + crg_udc->gadget.speed =3D USB_SPEED_UNKNOWN; > + ret =3D crg_udc_recover(crg_udc, flags, notify_reset); > + > + if (crg_udc->shutting_down || crg_udc->gadget_stopping) > + return ret; > + > + if (ret) { > + dev_err(crg_udc->dev, "link recovery failed: %d\n", ret); > + if (crg_udc->external_reset_pending) > + crg_udc->bus_reset_pending =3D notify_reset; > + return ret; > + } > + > + return crg_udc_restart_link(crg_udc, notify_reset); > +} [Severity: Medium] Can a failed recovery in crg_udc_recover_link() or crg_udc_recover_external() drop the pending reset/disconnect notification to the gadget driver? crg_udc_recover_link() clears connected =3D false and crg_udc_reset_session= () clears bus_reset_pending =3D false while draining endpoint queues with preserve_enabled =3D true. If crg_udc_recover() fails without setting external_reset_pending (for example, when the optional rst control is absent or post-SWRST initialization fails), or if crg_udc_recover_external() later fails and clears bus_reset_pending =3D fal= se, both connected and bus_reset_pending remain false without notifying the gadget driver. A subsequent crg_udc_suspend() then sees notify_disconnect =3D=3D false, clears usb_ep.enabled across all endpoints without calling crg_udc_notify_disconnect(), and crg_udc_resume() re-enables pullup while the gadget driver still believes its previous configuration is active. > + > +/* A full endpoint recovery also invalidates the gadget configuration. */ > +int crg_udc_recover_endpoints(struct crg_gadget_dev *crg_udc, > + unsigned long *flags) > +{ > + bool notify_reset =3D !crg_udc->disconnect_callback_active && > + (crg_udc->device_state =3D=3D USB_STATE_CONFIGURED || > + crg_udc->bus_reset_pending || > + crg_udc->gadget_callbacks_active); > + > + if (crg_udc->suspended) { > + bool bus_reset_pending =3D crg_udc->bus_reset_pending; > + int ret; > + > + /* > + * Suspend can be waiting for the callback that called > + * ep_disable(). Give back its requests synchronously. Keep > + * pullup and disconnect notification under suspend's control. > + */ > + ret =3D crg_udc_recover(crg_udc, flags, true); > + if (!crg_udc->gadget_stopping && !crg_udc->shutting_down) { > + crg_udc->bus_reset_pending =3D bus_reset_pending; > + /* -EBUSY means another path still owns the controller. */ > + if (ret !=3D -EBUSY) > + crg_udc->suspend_recovery_result =3D ret; > + } > + return ret; > + } > + > + return crg_udc_recover_link(crg_udc, flags, notify_reset); > +} [Severity: Medium] Does calling crg_udc_recover_endpoints() synchronously from crg_udc_ep_disable() lose a pending system error disconnect notification? When CRG_U3DC_STATUS_SYS_ERR arrives while reset_callback_active or gadget_callbacks_active is set, crg_udc_handle_system_error() sets deferred_system_error =3D true and defers crg_udc_disconnect_link() until t= he active callback finishes. If that callback calls crg_udc_ep_disable() and the register poll times out because of the system error, crg_udc_ep_disable() synchronously calls crg_udc_recover_endpoints() -> crg_udc_recover_link() -> crg_udc_recover() -> crg_udc_reset() -> crg_udc_reset_session(), which clears deferred_system_error =3D false and connected =3D false (and forces notify_reset =3D false when reset_callback_active is set). When the outer callback finishes, crg_udc_handle_system_error() and crg_udc_disconnect_link() are never run, skipping driver->disconnect(). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130-axiado-ax3= 000-usb-device-controller-v7-0-f240b1418955@axiado.com?part=3D6