Linux USB
 help / color / mirror / Atom feed
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 v6 6/6] usb: gadget: udc: crg: Add core driver and build integration
Date: Tue, 24 Nov 2026 13:34:42 +0000	[thread overview]
Message-ID: <sashiko-outbox-231224@kernel.org> (raw)
In-Reply-To: <20261124-axiado-ax3000-usb-device-controller-v6-6-b991f9b27111@axiado.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] usb: gadget: udc: crg: premature suspend during stop in
  crg_udc_suspend()
--

commit b4599496ea6732d81644faa7d639b33738f4ec72
Author: Petar Stepanovic <pstepanovic@axiado.com>

usb: gadget: udc: crg: Add core driver and build integration

This commit adds the core probe, remove, power management, interrupt, and
controller recovery paths for the Axiado AX3000/AX3005 UDC driver, and
integrates it into Kconfig and Makefile.

> 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..4b5c28da74975
> --- /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;
> +
> +	spin_lock_irqsave(&crg_udc->udc_lock, flags);
> +	if (crg_udc->controller_recovering || crg_udc->shutting_down ||
> +	    crg_udc->external_reset_pending ||
> +	    crg_udc->endpoint_recovery_pending ||
> +	    (crg_udc->hw_reset_asserted && !crg_udc->gadget_stopping)) {
> +		ret = -EBUSY;
> +		goto unlock;
> +	}
> +	if (crg_udc->gadget_stopping) {
> +		ret = crg_udc->hw_dma_armed ? -EBUSY : 0;
> +		if (!ret)
> +			crg_udc->suspended = true;
> +		goto unlock;
> +	}

[Severity: Medium]
Can crg_udc_suspend() mark the device suspended and return 0 while
crg_udc_stop_gadget(), request DMA mapping, or completion callbacks are
still in progress?

When crg_udc->gadget_stopping is true, this fast path only checks
crg_udc->hw_dma_armed before setting crg_udc->suspended and
crg_udc->suspend_complete.  If crg_udc_stop_gadget() sets
crg_udc->gadget_stopping while crg_udc_recover() -> crg_udc_reset() has
dropped udc_lock, crg_udc_recover() clears hw_dma_armed and
controller_recovering and sets controller_faulted = true before
crg_udc_stop_gadget() finishes draining IRQ, workers, queueing, and
gadget_callbacks_active:

CPU0                              CPU1
crg_udc_recover()
  crg_udc_reset()
    unlock(&crg_udc->udc_lock)
                                  crg_udc_stop_gadget()
                                    crg_udc->gadget_stopping = true
                                    unlock(&crg_udc->udc_lock)
                                    synchronize_irq() / cancel_work
    lock(&crg_udc->udc_lock)
    crg_udc->hw_dma_armed = false
  crg_udc->controller_faulted = true
  crg_udc_recovery_end()
  unlock(&crg_udc->udc_lock)
                                  crg_udc_suspend() (on CPU2)
                                    /* gadget_stopping && !hw_dma_armed */
                                    crg_udc->suspended = true
                                    crg_udc->suspend_complete = true
                                    return 0;  <-- premature suspend
                                  lock(&crg_udc->udc_lock)
                                  /* sees suspend_complete, skips
                                     crg_udc_finish_gadget_stop() */

Because suspend_complete is set and hw_dma_armed is already false, both
crg_udc_stop_gadget() and crg_udc_resume() skip
crg_udc_finish_gadget_stop(), leaving controller_faulted set and VBUS
detection enabled.  The same fast path can also run after
crg_udc_finish_gadget_stop() while crg_udc_stop_gadget() is still waiting
for crg_udc->gadget_callbacks_active to drain.

Returning -EBUSY from crg_udc_suspend() while crg_udc_stop_gadget() is
active (or whenever gadget_callbacks_active, queueing, or
controller_faulted is set) would avoid completing suspend mid-teardown.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-axiado-ax3000-usb-device-controller-v6-0-b991f9b27111@axiado.com?part=6

      reply	other threads:[~2026-11-24 13:34 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 13:14 [PATCH v6 0/6] Axiado AX3000 and AX3005 USB Device Controller (UDC) Petar Stepanovic
2026-11-24 13:14 ` [PATCH v6 1/6] dt-bindings: usb: gadget: udc: add Axiado AX3000 and AX3005 UDC Petar Stepanovic
2026-11-24 13:19   ` sashiko-bot
2026-11-24 13:14 ` [PATCH v6 2/6] usb: gadget: udc: crg: Add hardware definitions and structs Petar Stepanovic
2026-11-24 13:14 ` [PATCH v6 3/6] usb: gadget: udc: crg: Add ring and transfer management Petar Stepanovic
2026-11-24 13:14 ` [PATCH v6 4/6] usb: gadget: udc: crg: Add endpoint 0 handling Petar Stepanovic
2026-11-24 13:14 ` [PATCH v6 5/6] usb: gadget: udc: crg: Add gadget and endpoint operations Petar Stepanovic
2026-11-24 13:14 ` [PATCH v6 6/6] usb: gadget: udc: crg: Add core driver and build integration Petar Stepanovic
2026-11-24 13:34   ` sashiko-bot [this message]

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-231224@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox