From nobody Thu Feb 12 02:02:15 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53D44EE0203 for ; Thu, 14 Sep 2023 02:03:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234818AbjINCDf (ORCPT ); Wed, 13 Sep 2023 22:03:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234837AbjINCDV (ORCPT ); Wed, 13 Sep 2023 22:03:21 -0400 Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 956405FD4; Wed, 13 Sep 2023 18:58:10 -0700 (PDT) Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 38E1viQB007448; Thu, 14 Sep 2023 09:57:44 +0800 (+08) (envelope-from xingxing.luo@unisoc.com) Received: from SHDLP.spreadtrum.com (shmbx06.spreadtrum.com [10.0.1.11]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4RmL3f1Nrpz2Rssxt; Thu, 14 Sep 2023 09:54:38 +0800 (CST) Received: from zebjkernups01.spreadtrum.com (10.0.93.153) by shmbx06.spreadtrum.com (10.0.1.11) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Thu, 14 Sep 2023 09:57:43 +0800 From: Xingxing Luo To: , CC: , , , , , , Subject: [PATCH] usb: musb: Get the musb_qh poniter after musb_giveback Date: Thu, 14 Sep 2023 09:56:56 +0800 Message-ID: <20230914015656.20856-1-xingxing.luo@unisoc.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.0.93.153] X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To shmbx06.spreadtrum.com (10.0.1.11) X-MAIL: SHSQR01.spreadtrum.com 38E1viQB007448 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When multiple threads are performing USB transmission, musb->lock will be unlocked when musb_giveback is executed. At this time, qh may be released in the dequeue process in other threads, resulting in a wild pointer, so it needs to be here get qh again, and judge whether qh is NULL, and when dequeue, you need to set qh to NULL. Fixes: dbac5d07d13e ("usb: musb: host: don't start next rx urb if current o= ne failed") Signed-off-by: Xingxing Luo --- drivers/usb/musb/musb_host.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c index a02c29216955..9df27db5847a 100644 --- a/drivers/usb/musb/musb_host.c +++ b/drivers/usb/musb/musb_host.c @@ -321,10 +321,16 @@ static void musb_advance_schedule(struct musb *musb, = struct urb *urb, musb_giveback(musb, urb, status); qh->is_ready =3D ready; =20 + /* + * musb->lock had been unlocked in musb_giveback, so somtimes qh + * may freed, need get it again + */ + qh =3D musb_ep_get_qh(hw_ep, is_in); + /* reclaim resources (and bandwidth) ASAP; deschedule it, and * invalidate qh as soon as list_empty(&hep->urb_list) */ - if (list_empty(&qh->hep->urb_list)) { + if (qh !=3D NULL && list_empty(&qh->hep->urb_list)) { struct list_head *head; struct dma_controller *dma =3D musb->dma_controller; =20 @@ -2398,6 +2404,7 @@ static int musb_urb_dequeue(struct usb_hcd *hcd, stru= ct urb *urb, int status) * and its URB list has emptied, recycle this qh. */ if (ready && list_empty(&qh->hep->urb_list)) { + musb_ep_set_qh(qh->hw_ep, is_in, NULL); qh->hep->hcpriv =3D NULL; list_del(&qh->ring); kfree(qh); --=20 2.17.1