From patchwork Tue May 28 08:35:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 799452 Delivered-To: patch@linaro.org Received: by 2002:adf:e110:0:b0:35b:5a80:51b4 with SMTP id t16csp126918wrz; Tue, 28 May 2024 01:35:11 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUadLoF/gAc25L0DBkwSrglDRCiBhdH6t4AlC8roHGRXUTFnZIxpr5x2/8o5SxYG5Mb9A8Ztxfjz48uVo6nBdgT X-Google-Smtp-Source: AGHT+IEho5KkWPK6n58/6rsstnO4hAb9A5eP5hUeEXgXpBgNY+0eRz/DhemyffVkukeOBqX8PZQn X-Received: by 2002:a17:907:7844:b0:a5e:612e:fd58 with SMTP id a640c23a62f3a-a6264f126demr750441866b.51.1716885311392; Tue, 28 May 2024 01:35:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1716885311; cv=none; d=google.com; s=arc-20160816; b=fZ1W/xxUGKncNS4Wuh8/TfdBM3jfEHK0ioe8IWpzGmj/aPJnk3CG6Skeh8x8BbVXml PgxFZ+IH1aj+H2bYq/29+W0PwKylNwCaDg8CwZp3C6lucW8lbgG/F43ieRc5W/Vnveya UmhV4dJYDoZlJylDMoiAfO5mPPC0RkSkjPJrlwjAYynR9cSbg6glvyqfzpKSc4ZZ6L8+ bNRn/GEWECwatNf3kLUG9MoPoNPMWNWZ1bT2m9JKi9s1PVP6SCfbGJS/4BfZ4DGcI2Y/ YHaj/DCqyd9+LR9vBiqHdQPWmd3JsW4iUEUR7U5TS1bkM+aY+2xo52+0T9Cw8V6y9+pg cCEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:cc:to:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=kVQB5ZBz5/WJEBlYx9gP0Yo61aobCxqH47fDiuwoehA=; fh=b75IbHyf2VNGJ8g8Ft/bH/MlayMn8zx3JDmPA7L78VY=; b=Mhu6nWqT+Z2ZBQlfg2eA4ONJfgyJrfMbYM1V26IiPYFfLvBGtQmKeRwCQP2OuN3mpX J4PRRXTtUWpyRH/x+DUtYfe+7u0eJq5tutHasOcgkoxhzPPMoZjIrBfNTVYW6SPDLaPk aSdxFO8sAuZ4tpp+qeXc10Q8GS7cA6kF9SG6cXWK7c5KDT55lPWh09UcQKwU1pSHklRQ RD+j96fVOw8W/p5S3ap5BLoWMSFngoRgtGaGtEd/PKCCZnr4oquXYXpSYAt50lfLLJ0n nd3rNY2sR6le1mWqlMa33siZepRwI9L4Ump4hz2cQ/s3ZLLF17eKlxh/05eqTeYyJxnV oOxQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=e+u3nmeH; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id a640c23a62f3a-a626cc36f19si468884966b.300.2024.05.28.01.35.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 01:35:11 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=e+u3nmeH; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6AAC588445; Tue, 28 May 2024 10:35:10 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="e+u3nmeH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 77A3388418; Tue, 28 May 2024 10:35:09 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8ACE588441 for ; Tue, 28 May 2024 10:35:05 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=neil.armstrong@linaro.org Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-354ba5663c9so404338f8f.0 for ; Tue, 28 May 2024 01:35:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1716885305; x=1717490105; darn=lists.denx.de; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=kVQB5ZBz5/WJEBlYx9gP0Yo61aobCxqH47fDiuwoehA=; b=e+u3nmeHDMICrMG3PqXudLa7cDw7EGa0km2qVlQLg+grMicbY9qusieIklnmr4E8rf fop+OYGpVQh5F4gKQjF2qxNhjAC3R6FjgJtpYaI/25wm4uHDSUccNh/wKB9ycQviENVD F3MHPrj82MJ3OvDnXgDwgiklZtVNFtGehJsjyRQiE6w6od+WjrDJ0BzNLgo2ExwVBDzP e4YaOulcKQUzubSexLKTSP/F1Bbe8G2ARsTjaodac+YDAY8EeD7hSIvzAnJYHTFcLs24 1UXPLtlPhxVvBXrAZmNKb2+0R7m4z2wwfJ6hhw0lkFxZUTeaiYI5DtwmBkPHFvj8kK2C thng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716885305; x=1717490105; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=kVQB5ZBz5/WJEBlYx9gP0Yo61aobCxqH47fDiuwoehA=; b=h7qjCw4N+G5XsA1HXJ4ediz45NPgnamDO3fyzOGJyOZXwPYDYl+/4GPrNi5+zxeo/B VB5YwILvXJREZUYhRnuhHGEYQ89hgQS0BSzxTHnWpzIGnkgcmE0e8oIHzzktRJLAKqiA rxNQ02vhy0gcQ7DP/WSDaLEEFdje/SSe5cEZXPZ8VHYKsN/y8/UHqcXbU+32IId8SJ0J gcxAi9UgxTzSXtAQeJEyDhsZh/sB7kxY1MaVOA5ElaGjeJ95/AGdfuCqu3Y5S7h+sEad PimE6prQm+k2w0j0LCanr4tBddmCiQKfFU2cH78lZgpGMuUysIsRFVlrJ0bhMEXjeVdF z7ng== X-Gm-Message-State: AOJu0YzGGth5l1kBNciWcRo5jwUtbU6Mx8+tUNUQonP70ToGJynbr/cn CVLzpdA0q/8RKt1+uxp2aeH0LaZHfrjA39U6PbkfLufWK/wvUzSknoehh36ZBnc= X-Received: by 2002:adf:f506:0:b0:355:433:8f80 with SMTP id ffacd0b85a97d-35526c569f7mr7215241f8f.33.1716885304791; Tue, 28 May 2024 01:35:04 -0700 (PDT) Received: from arrakeen.starnux.net ([2a01:e0a:982:cbb0:52eb:f6ff:feb3:451a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-358ffe5de1esm5234527f8f.34.2024.05.28.01.35.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 01:35:04 -0700 (PDT) From: Neil Armstrong Date: Tue, 28 May 2024 10:35:03 +0200 Subject: [PATCH] usb: dwc3: gadget: fix crash in dwc3_gadget_giveback() MIME-Version: 1.0 Message-Id: <20240528-topic-sm8x50-dwc3-gadget-crash-fix-v1-1-58434ab4b3d3@linaro.org> X-B4-Tracking: v=1; b=H4sIADaXVWYC/x2NywqEMAwAf0Vy3kC2rSD+yuKhpGnNwQeNuIL47 1v2OHOYucGkqhiM3Q1VTjXd1gbvVwc8x7UIamoMjlyg3g14bLsy2jJcPWH6sscSU5EDuUabMeu FOVKgkDOL99BCe5Wm/5PP9Dw/lr4qBHQAAAA= To: Lukasz Majewski , Mattijs Korpershoek , Marek Vasut , Tom Rini , Marek Szyprowski Cc: u-boot@lists.denx.de, Neil Armstrong X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1593; i=neil.armstrong@linaro.org; h=from:subject:message-id; bh=B5v3p5TfjpucgwVaRmabxLJsVbrZ2qBAHNeqCVZ+8EQ=; b=owEBbQKS/ZANAwAKAXfc29rIyEnRAcsmYgBmVZc3LMXx7uOk71tX6sXkfMFvHjcSoLucPORZoybK mdM270yJAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCZlWXNwAKCRB33NvayMhJ0W78D/ oCk+FQ9q9uLbHzANA3J3ywHgiIWHhuvWjVjWiZYKmps6D3pduUCy41fdUaqMEe6srtqPUgZvt/uqCV N9ivLp3x4Kok6lnOIO93A4NkAoWkyPgqybRhknD+oc2EkIn0wNkRfLVEruY05Hb6HdsO+yVCji+ucD AWJV/JqC+U+2NAkVuGNcPIwPnyTfI/z2zJoN+jMSPoM+XkGIOdqU71iGulIOxkllWU7PjVSR75AxCa ezDvW3PqyYAdJo38wp2oTe8iniNETAbJntMW06MWN6h1MhqQvDhYGc8rrpP9hD2at2kzDpUF6B6NHQ KplA7OjSozQyqiz1FGiS46VvdR4YQUtCAFwAi3gMTSLIsCSR/XlXOz44WKKCZoCUKQ/7WUBEqh4Pua yOnMYbMJikshKeG1OAVsNSuK0yS6keav05KVFzK83Fe/0PG5tFwSjQoZyFUFLXYTJs3002pC7VW4wT kps3hK1CE/VL/L4aL3qW8mDC4LktOWfBPI6R9PWF5zOP7JkNVG8sHWipYsa4hh0ulOpiS8vDWUm6/T slc1SkLErzL//ny6Zfd8b+gIjnHklG0Y+2721b8UKK9iGrKu5WbtqV50SdoyhT3LXqjBXyJiNxXrqz jPkepbYXKhmzTfEtUGYQ16B7ruDak5+cR+ZOGwEDfxVaYy0at6Hbbkjnlqdw== X-Developer-Key: i=neil.armstrong@linaro.org; a=openpgp; fpr=89EC3D058446217450F22848169AB7B1A4CFF8AE X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean If the ep0 stalls or request are dequeued when gagdet is stopped, the request dma may not be mapped yet and dwc3_flush_cache() may be called with a NULL pointer. Check req->request.dma before calling dwc3_flush_cache() and later the usb_gadget_unmap_request() functions since it means that usb_gadget_map_request() hasn't been called yet. Fixes: fd15b58c1a9 ("dwc3: flush cache only if there is a buffer attached to a request") Signed-off-by: Neil Armstrong Reviewed-by: Mattijs Korpershoek --- drivers/usb/dwc3/gadget.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- base-commit: 7e52d6ccfb76e2afc2d183b357abe2a2e2f948cf change-id: 20240528-topic-sm8x50-dwc3-gadget-crash-fix-fa0404ffce33 Best regards, diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index fab32575647..92c7c6d08b7 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -248,7 +248,7 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req, list_del(&req->list); req->trb = NULL; - if (req->request.length) + if (req->request.dma && req->request.length) dwc3_flush_cache((uintptr_t)req->request.dma, req->request.length); if (req->request.status == -EINPROGRESS) @@ -256,7 +256,7 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req, if (dwc->ep0_bounced && dep->number == 0) dwc->ep0_bounced = false; - else + else if (req->request.dma) usb_gadget_unmap_request(&dwc->gadget, &req->request, req->direction);