Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Xu Yang" <xu.yang_2@oss.nxp.com>
Cc: linux-usb@vger.kernel.org, imx@lists.linux.dev, Frank.Li@kernel.org
Subject: Re: [PATCH v2] usb: chipidea: stop asynchronous work before destroying roles
Date: Tue, 01 Dec 2026 09:36:07 +0000	[thread overview]
Message-ID: <sashiko-outbox-242988@kernel.org> (raw)
In-Reply-To: <20261201092430.2212461-1-xu.yang_2@oss.nxp.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] usb: chipidea: stale OTG event flags and teardown race in
  ci_hdrc_otg_destroy()
--

commit 2edcac291a5d2ee72c3e18a7f2116a86d7b33779
Author: Xu Yang <xu.yang_2@nxp.com>

usb: chipidea: stop asynchronous work before destroying roles

This commit reorders role teardown to disable power_lost_work and stop OTG
interrupts, FSM processing, and ci->work before destroying the gadget and
host roles.

> diff --git a/drivers/usb/chipidea/otg.c b/drivers/usb/chipidea/otg.c
> index fecc7d7e2f0d7..ec11056dddfaf 100644
> --- a/drivers/usb/chipidea/otg.c
> +++ b/drivers/usb/chipidea/otg.c
> @@ -264,12 +264,21 @@ int ci_hdrc_otg_init(struct ci_hdrc *ci)
>   */
>  void ci_hdrc_otg_destroy(struct ci_hdrc *ci)
>  {
> -	if (ci->wq)
> -		destroy_workqueue(ci->wq);
> +	disable_irq(ci->irq);
> +	if (disable_work_sync(&ci->work)) {
> +		ci->id_event = false;
> +		ci->b_sess_valid_event = false;
> +		/* Balance disable_irq_nosync() performed in ci_otg_queue_work() */
> +		enable_irq(ci->irq);
> +	}
> +
> +	if (ci_otg_is_fsm_mode(ci))
> +		ci_hdrc_otg_fsm_remove(ci);
>  
>  	/* Disable all OTG irq and clear status */
>  	hw_write_otgsc(ci, OTGSC_INT_EN_BITS | OTGSC_INT_STATUS_BITS,
>  						OTGSC_INT_STATUS_BITS);
> -	if (ci_otg_is_fsm_mode(ci))
> -		ci_hdrc_otg_fsm_remove(ci);
> +	if (ci->wq)
> +		destroy_workqueue(ci->wq);
> +	enable_irq(ci->irq);
>  }

[Severity: Medium]
Can ci_hdrc_otg_destroy() leave ci->id_event or ci->b_sess_valid_event set
when re-enabling ci->irq, causing a hardirq storm during role teardown?

ci->id_event and ci->b_sess_valid_event are only cleared when
disable_work_sync() cancels a pending work item, and hw_write_otgsc() does
not clear cable->enabled until after disable_work_sync() returns:

1. In OTG FSM mode, ci_otg_fsm_work() only clears ci->id_event when the
   state machine remains in OTG_STATE_A_IDLE.  If a completed work run
   transitioned to OTG_STATE_A_WAIT_VRISE, ci->id_event is still true when
   disable_work_sync() returns false.
2. disable_irq(ci->irq) does not block extcon notifications via
   ci_cable_notifier() -> ci_irq() -> ci_irq_handler(), which can still
   see cable->enabled == true and set ci->id_event or
   ci->b_sess_valid_event before hw_write_otgsc() runs:

CPU0                              CPU1
ci_hdrc_otg_destroy()
  disable_irq(ci->irq)
  disable_work_sync(&ci->work)
                                  ci_cable_notifier()
                                    ci_irq(ci)
                                      ci_otg_irq(ci)
                                        ci->id_event = true
                                        ci_otg_queue_work(ci)
  hw_write_otgsc(...)
  enable_irq(ci->irq)
ci_hdrc_gadget_destroy()
  <hardirq>
    ci_irq_handler()
      if (ci->id_event || ...)
        ci_otg_queue_work(ci)
        return IRQ_HANDLED;       <-- skips ci_role(ci)->irq(ci), IRQ storm

Because ci->work is now disabled, queue_work() in ci_otg_queue_work()
always returns false and immediately calls enable_irq(ci->irq), while
ci_irq_handler() returns IRQ_HANDLED before calling ci_role(ci)->irq(ci)
to clear the device or host interrupt status.

Calling ci_hdrc_otg_fsm_remove() and hw_write_otgsc() before
disable_work_sync(&ci->work), and clearing ci->id_event and
ci->b_sess_valid_event unconditionally afterwards, would avoid this.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201092430.2212461-1-xu.yang_2@oss.nxp.com?part=1

      reply	other threads:[~2026-12-01  9:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  9:24 [PATCH v2] usb: chipidea: stop asynchronous work before destroying roles Xu Yang
2026-12-01  9:36 ` 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-242988@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=imx@lists.linux.dev \
    --cc=linux-usb@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=xu.yang_2@oss.nxp.com \
    /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