Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp395677rdb; Mon, 18 Sep 2023 20:35:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHuDg4w20dc7Ciafd3FPZWuL/LkTTg2DiwxbTz0922F9covgq4qikxPe9gAGSvfk6hcmLXz X-Received: by 2002:a17:902:728a:b0:1bb:d048:3173 with SMTP id d10-20020a170902728a00b001bbd0483173mr10985636pll.61.1695094556595; Mon, 18 Sep 2023 20:35:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695094556; cv=none; d=google.com; s=arc-20160816; b=oo0Eb8fbHAtPh5VFR1KG66+aGP7LjePuoLnInPTJL6HuZR/dORusNiYLoX2MJG7Zeu XaK2tDc0yR54j5hfc2Lxs13E5Q7Zk6Zn+M7NSC03H9f0A3PsKoRUE8q2XfwR2NlWwjtx r5KXhtdpSwvrQ71XXXU+ZPeLaFPxiaKir5zL3hlh2rwEEtX3arwj7yF1iZannnOoELjc HtyRFf4b+K4agqhYbhH3BFxQPiBP//ay4li1PLpjmvnv5FQPAvHM178aKfQmC4NF+6y8 OGSgbXIaN/zp2s56xAlISVn4/jPQpbCYIGTLgTlGEX7GtaTBm1dMcsXSLjp+1xzd4i+j eC2g== 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=vbulo+dIeUOsiJYmR+nIncAXwQMLS9qURgNO8B0e1OA=; fh=PHrkciEtZyUbtKGBqpQtfyKOOW8+TYX5VkaliqBcig4=; b=xxhWORtjfyZrGb6YXJKYVgcXy8hSkaIaTwejNBXnbJvgtRk9f7O1E1UWpBRp2F9r0W YzmHaw1JKAnAL8gd/eloelatgHSGq8GdRQEQB6piBcNfPdl9GaHmW5b1WxFE8+mk3VRu EJe588TzBKOWN16otDxgcsYP/4QjcDlDXLx2qHpgx496/j348pVzeplOlurVaMg0rzoX Tw5C4XkPUMT2gmxGyf5uhI1DpT6Pxq8mzr6MKLdqhsqx9tvtHiJXjp7Njw582Fpq1lnU PJuBEy40lRHqGr7bBD23EJ+xnPm+Zgu0wYAK8+oPvx2DjF9wuoF3TJeXUahewjLcnpPl /W9w== 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:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id y4-20020a17090322c400b001b86ddfd49bsi9220705plg.6.2023.09.18.20.35.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 20:35:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 9036580A9E18; Mon, 18 Sep 2023 20:32:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231279AbjISDcP (ORCPT + 99 others); Mon, 18 Sep 2023 23:32:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231190AbjISDcL (ORCPT ); Mon, 18 Sep 2023 23:32:11 -0400 Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F851112; Mon, 18 Sep 2023 20:32:03 -0700 (PDT) Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 38J3VERv084976; Tue, 19 Sep 2023 11:31:14 +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 4RqRv22qlzz2SGkjR; Tue, 19 Sep 2023 11:27:58 +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; Tue, 19 Sep 2023 11:31:13 +0800 From: Xingxing Luo To: , , CC: , , , , , , Subject: [PATCH V3] usb: musb: Get the musb_qh poniter after musb_giveback Date: Tue, 19 Sep 2023 11:30:55 +0800 Message-ID: <20230919033055.14085-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: SHCAS01.spreadtrum.com (10.0.1.201) To shmbx06.spreadtrum.com (10.0.1.11) X-MAIL: SHSQR01.spreadtrum.com 38J3VERv084976 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 morse.vger.email 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 (morse.vger.email [0.0.0.0]); Mon, 18 Sep 2023 20:32:18 -0700 (PDT) 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") Cc: stable@vger.kernel.org Signed-off-by: Xingxing Luo --- v2 -> v3: Add Cc: stable v1 -> v2: - Modified the comments section. - Modified "if (qh != NULL && ..." to "if (qh && ...". 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..bc4507781167 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 qh may + * be freed, need to 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 && 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