From nobody Sat May 18 21:16:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1624764584555861.8264054808749; Sat, 26 Jun 2021 20:29:44 -0700 (PDT) Received: from localhost ([::1]:59208 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lxLUM-0003mm-RE for importer@patchew.org; Sat, 26 Jun 2021 23:29:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44336) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lxLTc-00036H-Gt for qemu-devel@nongnu.org; Sat, 26 Jun 2021 23:28:56 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]:40540) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lxLTa-00063T-LK for qemu-devel@nongnu.org; Sat, 26 Jun 2021 23:28:56 -0400 Received: by mail-wr1-x429.google.com with SMTP id g7so11254391wri.7 for ; Sat, 26 Jun 2021 20:28:53 -0700 (PDT) Received: from localhost ([147.78.177.108]) by smtp.gmail.com with ESMTPSA id c12sm10003795wrw.46.2021.06.26.20.28.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 26 Jun 2021 20:28:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=Zubl8mgJImZll2lQi+hFnjquenEVGAsVZioeT3sF1Kc=; b=Dbc4tdmqqhiQHcEDFyc1vgs5CkM0iBEIXDVRBQphaovB6Tx1PAGX6BIgS43R3hh41/ C9JVKpGsToHgx5uqUMqmR7KPECDMy/0EaSjI6/zbYQerMhXWgeGWO5rUYWJlrhPDXY6c lEb5d8WSgJAyatAIdtMoXejdxr7SmDkjMjfXkUGzmYqELWXl4TdScVzGnr5HbK2bWeI5 W6aavMYVz0eVHdFrTK+9wzEhrm3lNOUoLE+Q+FteYfuWeaMlarpuD3AClDvAeF0/i1ek 6xeFLNNwqVjLEhPu87crYd3WOoPh2AHIaqevnfqMFIcZEkuTm6JRyubzWDyFBweOd6p6 4Zug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Zubl8mgJImZll2lQi+hFnjquenEVGAsVZioeT3sF1Kc=; b=TOsJ3Av9+7W3f5KJy+/wmmPipe3RyepbJvsMNpcQIJS7rPiMePidttUv/j0Mj1Gnig TuZNqOizvngj5e77oKuXE+0zf/OT0LYhb78sMw5IlZ0tqy6I32gZiLjh85dAXeaTSo19 75C1pewiCNdKY56K/Nt5d/7aJ2KNK8zXl53T8d+7VWMHd9+Dmzzzptonpvtp+NAM7x8R YdM73eCESwXU38W7HmGkqp3YiR45vIbWBIvZgnsVVv9adfGN5DnfdsXWcUmjdPuIpMru uS+5geHxtashikcGz2bxH13fd17sZRKTCVUbi7Ba8PFUlPtnArq0gUQoBP1oDl9hDfzu cegg== X-Gm-Message-State: AOAM5319cna5zcn03trOEJt5DBFz2xoovkkzu4vEKQdsRvPUXSrQrC83 go7PAVOF5dsJtcfX3WJQiNo= X-Google-Smtp-Source: ABdhPJx3NuSYdFoPe+QI6GurMzsDocn7NwV/FnrgytfoFEmpC8HRnRR77lg7xdYtt13elDgafXhdmQ== X-Received: by 2002:adf:ebd2:: with SMTP id v18mr13838985wrn.248.1624764531838; Sat, 26 Jun 2021 20:28:51 -0700 (PDT) From: Qiang Liu To: Subject: [PATCH] hw/usb/hcd-dwc2: Enforce epnum to 0 for the control endpoint to avoid the assertion failure in usb_ep_get() Date: Sun, 27 Jun 2021 11:28:26 +0800 Message-Id: <1624764506-19841-1-git-send-email-cyruscyliu@gmail.com> X-Mailer: git-send-email 2.7.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=cyruscyliu@gmail.com; helo=mail-wr1-x429.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "open list:All patches CC here" , Qiang Liu , Gerd Hoffmann , Paul Zimmerman Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When eptype is USB_ENDPOINT_XFER_CONTROL and pid is TSIZ_SC_MC_PID_SETUP, usb_ep_get() should return the control endpoint. In hw/usb/core.c, the assumed epnum of the control endpoint is 0. When epnum is not 0, usb_ep_get() will crash due to the check assert(pid =3D=3D USB_TOKEN_IN || pid =3D=3D USB_TOKEN_OUT). The description http://www.capital-micro.com/PDF/CME-M7_Family_User_Guide_EN.pdf (18.5.3.4 (14), 18.5.3.4 (10)) a) mentions that the pid is maintained by the host, b) but doesn't mention that whether the epnum should be 0 for the control endpoint. However, usb_ep_get() assumes it is 0. To avoid potential assertion failure in usb_ep_get(), we could enforce epnum to 0 and warn users. Fixes: 153ef1662c3 ("dwc-hsotg (dwc2) USB host controller emulation") Signed-off-by: Qiang Liu --- hw/usb/hcd-dwc2.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/usb/hcd-dwc2.c b/hw/usb/hcd-dwc2.c index e1d96ac..65d9d46 100644 --- a/hw/usb/hcd-dwc2.c +++ b/hw/usb/hcd-dwc2.c @@ -636,6 +636,11 @@ static void dwc2_enable_chan(DWC2State *s, uint32_t i= ndex) } =20 if (eptype =3D=3D USB_ENDPOINT_XFER_CONTROL && pid =3D=3D TSIZ_SC_MC_P= ID_SETUP) { + if (epnum !=3D 0) { + qemu_log_mask(LOG_GUEST_ERROR, + "epnum should be 0 for the control endpoint\n"); + epnum =3D 0; + } pid =3D USB_TOKEN_SETUP; } else { pid =3D epdir ? USB_TOKEN_IN : USB_TOKEN_OUT; --=20 2.7.4