Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3624757rdb; Wed, 13 Sep 2023 19:10:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE6B29XfqIyOGNmQKS+w5fMnU6g35rADx3yWH1JniXKiUgHcMk9DiGR7AlpC5/88IYV2Gme X-Received: by 2002:a25:b097:0:b0:d7b:9187:b92e with SMTP id f23-20020a25b097000000b00d7b9187b92emr4357186ybj.58.1694657401215; Wed, 13 Sep 2023 19:10:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694657401; cv=none; d=google.com; s=arc-20160816; b=ND7E6XECbJ4kbuP5Vu7QGV6uAsgr0/InNStleOzMrxlVxhKJ2HRQdmfGgIth1jSCBT REaJHNvdWiYJQAeL00nyuFHZDLaHoJjIjEPL7mkQFQfPK74WPxafOXSd90EdociTko2t hQ3x9L7VAcY3eFM2mYWNK0XMQe9ou3jPaP4OTb5n67cvQcvLCqMmZv7WUolmiRtMd7qr C3QxSY+hRZA9G/WB74iw+LzdyKmBg1wkRljH8kVqXjAX7DDtLbTLCTg9ZUQjDJbHAWPA foLH5Kf+/zEeYleRBiWloYmNi8eAS4wWYWTu/cEh9TIT6FvrwUBhgkdkhL5TY7rDMtUs fBNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=QXIUvKCKtf6qZj9FrKhUDo2aOh9teVGWRXINUIckCJc=; fh=Hk8Ejs+0w4c3nuCU/PRxzdfRo0zmpnVwKMma1x+exrI=; b=prY2XvxM588HjQIt0e2BndnU0MEC5Q9sqnEo2VLjX0AGWk2//Tmklgvap3F1kyaf/H iDhw7PeISWySjp3cSIt+uUgB4bp/xiLJ5tjkGPLPu/LVtcuS3W2xpz9oI+/R6bXDyZ3Y qy7NtXs7emmvzdjbzjQREy/2fWtlxlsiPNQzyqa0glSdVzxJboDOOaPWbLg6VNAo/80N 58oZsFQcrdxfgcYakqXZb8b4r42mefS1nTp5JL8o7Aj+y1yeQ/XEjYMEzl23VlLX+4SG SyTJVO4V9MHtp6XeRFlgirtS4zUfUV/582vaVV6yOn0OBcL6JQ0hbRgKRzqGDRsiUbDF 3gCw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id h5-20020a636c05000000b005774452aa40si408383pgc.269.2023.09.13.19.10.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 19:10:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 311FA822919B; Wed, 13 Sep 2023 19:04:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234791AbjINCDe (ORCPT + 99 others); Wed, 13 Sep 2023 22:03:34 -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 Content-Type: text/plain 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 13 Sep 2023 19:04:11 -0700 (PDT) X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email 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 one 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 = ready; + /* + * musb->lock had been unlocked in musb_giveback, so somtimes qh + * may freed, need get it again + */ + qh = 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 != NULL && list_empty(&qh->hep->urb_list)) { struct list_head *head; struct dma_controller *dma = musb->dma_controller; @@ -2398,6 +2404,7 @@ static int musb_urb_dequeue(struct usb_hcd *hcd, struct 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 = NULL; list_del(&qh->ring); kfree(qh); -- 2.17.1