public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
From: Meng Li <Meng.Li@windriver.com>
To: Thinh.Nguyen@synopsys.com, gregkh@linuxfoundation.org,
	quic_uaggarwa@quicinc.com, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: meng.li@windriver.com
Subject: [PATCH] usb: dwc3: core: remove lock of otg mode during gadget suspend/resume to avoid deadlock
Date: Thu, 13 Jun 2024 15:39:59 +0800	[thread overview]
Message-ID: <20240613073959.1939608-1-Meng.Li@windriver.com> (raw)

When config CONFIG_USB_DWC3_DUAL_ROLE is selected, and trigger system
to enter suspend status with below command:
echo mem > /sys/power/state
There will be a deadlock issue occurring. Because dwc3_gadget_suspend() also
try to get the lock again when previous invoked dwc3_suspend_common() has
got the lock . This issue is introduced by commit c7ebd8149ee5 ("usb: dwc3:
gadget: Fix NULL pointer dereference in dwc3_gadget_suspend") that removes
the code of checking whether dwc->gadget_driver is NULL or not. It causes the
following code is executed and deadlock occurs when trying to get the spinlock.
To fix the deadlock issue, refer to commit 5265397f9442("usb: dwc3: Remove
DWC3 locking during gadget suspend/resume"), remove lock of otg mode during
gadget suspend/resume.

Fixes: 61a348857e86 ("Fix NULL pointer dereference in dwc3_gadget_suspend")
Cc: stable@vger.kernel.org
Signed-off-by: Meng Li <Meng.Li@windriver.com>
---
 drivers/usb/dwc3/core.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 7ee61a89520b..9d47c3aa5777 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -2250,7 +2250,6 @@ static int dwc3_core_init_for_resume(struct dwc3 *dwc)
 
 static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
 {
-	unsigned long	flags;
 	u32 reg;
 	int i;
 
@@ -2293,9 +2292,7 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
 			break;
 
 		if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) {
-			spin_lock_irqsave(&dwc->lock, flags);
 			dwc3_gadget_suspend(dwc);
-			spin_unlock_irqrestore(&dwc->lock, flags);
 			synchronize_irq(dwc->irq_gadget);
 		}
 
@@ -2312,7 +2309,6 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
 
 static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)
 {
-	unsigned long	flags;
 	int		ret;
 	u32		reg;
 	int		i;
@@ -2366,9 +2362,7 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)
 		if (dwc->current_otg_role == DWC3_OTG_ROLE_HOST) {
 			dwc3_otg_host_init(dwc);
 		} else if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) {
-			spin_lock_irqsave(&dwc->lock, flags);
 			dwc3_gadget_resume(dwc);
-			spin_unlock_irqrestore(&dwc->lock, flags);
 		}
 
 		break;
-- 
2.34.1


             reply	other threads:[~2024-06-13  7:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-13  7:39 Meng Li [this message]
2024-06-13  8:06 ` [PATCH] usb: dwc3: core: remove lock of otg mode during gadget suspend/resume to avoid deadlock Greg KH
2024-06-13 11:59   ` Li, Meng
2024-06-17 23:59     ` Thinh Nguyen
  -- strict thread matches above, loose matches on Subject: below --
2024-06-13  7:23 Meng Li
2024-06-13  7:25 ` Li, Meng
2024-06-13  8:52 ` Krzysztof Kozlowski
2024-06-13 11:22   ` Li, Meng

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=20240613073959.1939608-1-Meng.Li@windriver.com \
    --to=meng.li@windriver.com \
    --cc=Thinh.Nguyen@synopsys.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=quic_uaggarwa@quicinc.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