From: sashiko-bot@kernel.org
To: "Petar Stepanovic" <pstepanovic@axiado.com>
Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org,
robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v7 6/6] usb: gadget: udc: crg: Add core driver and build integration
Date: Mon, 30 Nov 2026 10:18:08 +0000 [thread overview]
Message-ID: <sashiko-outbox-240840@kernel.org> (raw)
In-Reply-To: <20261130-axiado-ax3000-usb-device-controller-v7-6-f240b1418955@axiado.com>
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 <pstepanovic@axiado.com>
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/gadget/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 = 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 = crg_udc->connected || crg_udc->bus_reset_pending;
> + crg_udc->connected = false;
> + crg_udc->bus_reset_pending = false;
> + /* Use completed recovery or leave a pending reset to the worker. */
> + ret = crg_udc->suspend_recovery_result;
> + if (ret == -EINPROGRESS || (ret && !crg_udc->external_reset_pending))
> + ret = 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 = ret ?: -EBUSY;
> + goto failed;
> + }
> + if (notify_disconnect)
> + for (i = 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 = NULL
while preserving usb_ep.enabled = true, and records
suspend_recovery_result = 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 = dev_get_drvdata(dev);
> + int ret = 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 = crg_udc_finish_gadget_stop(crg_udc);
> +
> + crg_udc->suspend_complete = false;
> + crg_udc->suspended = 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 = notify_reset && crg_udc->async_callbacks &&
> + crg_udc->gadget_driver && !crg_udc->reset_callback_active;
> + crg_udc->connected = false;
> + crg_udc->gadget.speed = USB_SPEED_UNKNOWN;
> + ret = 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 = 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 = false and crg_udc_reset_session()
clears bus_reset_pending = false while draining endpoint queues with
preserve_enabled = 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 = false,
both connected and bus_reset_pending remain false without notifying the
gadget driver. A subsequent crg_udc_suspend() then sees
notify_disconnect == 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 = !crg_udc->disconnect_callback_active &&
> + (crg_udc->device_state == USB_STATE_CONFIGURED ||
> + crg_udc->bus_reset_pending ||
> + crg_udc->gadget_callbacks_active);
> +
> + if (crg_udc->suspended) {
> + bool bus_reset_pending = 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 = crg_udc_recover(crg_udc, flags, true);
> + if (!crg_udc->gadget_stopping && !crg_udc->shutting_down) {
> + crg_udc->bus_reset_pending = bus_reset_pending;
> + /* -EBUSY means another path still owns the controller. */
> + if (ret != -EBUSY)
> + crg_udc->suspend_recovery_result = 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 = true and defers crg_udc_disconnect_link() until the
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 = false and
connected = false (and forces notify_reset = 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().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130-axiado-ax3000-usb-device-controller-v7-0-f240b1418955@axiado.com?part=6
next prev parent reply other threads:[~2026-11-30 10:18 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 9:51 [PATCH v7 0/6] Axiado AX3000 and AX3005 USB Device Controller (UDC) Petar Stepanovic
2026-11-30 9:51 ` [PATCH v7 1/6] dt-bindings: usb: gadget: udc: add Axiado AX3000 and AX3005 UDC Petar Stepanovic
2026-11-30 9:51 ` [PATCH v7 2/6] usb: gadget: udc: crg: Add hardware definitions and structs Petar Stepanovic
2026-11-30 9:51 ` [PATCH v7 3/6] usb: gadget: udc: crg: Add ring and transfer management Petar Stepanovic
2026-11-30 9:51 ` [PATCH v7 4/6] usb: gadget: udc: crg: Add endpoint 0 handling Petar Stepanovic
2026-11-30 10:18 ` sashiko-bot
2026-11-30 9:51 ` [PATCH v7 5/6] usb: gadget: udc: crg: Add gadget and endpoint operations Petar Stepanovic
2026-11-30 9:51 ` [PATCH v7 6/6] usb: gadget: udc: crg: Add core driver and build integration Petar Stepanovic
2026-11-30 10:18 ` sashiko-bot [this message]
2026-11-30 10:18 ` [PATCH v7 0/6] Axiado AX3000 and AX3005 USB Device Controller (UDC) sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-240840@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=pstepanovic@axiado.com \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.