Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4592200pxj; Wed, 12 May 2021 08:51:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsEXuuxU0SBEQpJ83hdG7hRQMz4D5Yuu4NKHVZ4bPcT0KuOOj/SWSK0h1Hy39nRBHVw6mS X-Received: by 2002:a17:907:948d:: with SMTP id dm13mr36289446ejc.180.1620834679481; Wed, 12 May 2021 08:51:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620834679; cv=none; d=google.com; s=arc-20160816; b=jMwOSsbqLIsVpC3xiDSUd6PqiREqfyhETonPqtTx2Z0CvlygVwxQhJ2eboBC+zcMlY v2y1b4e2wSVFfxJKN0zLLAxDOI/uYq/g/4jjrIpdAfLr6M/NUoN+3jKxtnnpq0ztvyRW JSecEEKCpmthD5JQJEpGHu4MKZdvOhZ6ovw6zEh1046+4HMS3WbDYT/bL0SFaQSAdrFG uShbdqg0hBtbndWkQkD8A4nW4fzng6ZpvXgmNTnxHczikl6gQ+2EmNZucUQHy30rqTPv 9gZs+3o38a0qi/7XzgCeImfS9D1MchxUEqMNjZ+kXTCQu9NAwAvnUXY5C2YzhlrgDTyZ tSfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fTj3rJ17BKSIU1Hw7Hf4pgus7GLlWk4+NDQXHHCiz0Y=; b=EdaDfy/ogxtyLSi+WgM+uk87rlsP+gPM7oAZ8lRSQIT42ZaUqDUQHvHLqUBkFAqShz s/ZeFybjvA/R4TXp+qjkCNLBN/Jqb1m06zBQgsfkIhhPGt3huMYKZo6KJI/P319x03+3 oQ2juaTOBuWALkQbk+NOgXbRQG8A7bww8gKlE/wrTZ1EbDLD2Yw4cobxdfHNQ0AOF3FT SBsW+QZUeZMazdg/CacRE6I1UCnoe55AsG8c70TPxb4eyJPGT5ybzMDlVtUOWDxc56e9 wsynJYlgzBMyiO8X9U22niPe4hlaVZHQ/0Hok6BNd6G8tyX7vRRvto7Gjx+rIv9mVd52 9vvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BQVBXqIT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nc2si314003ejc.593.2021.05.12.08.50.54; Wed, 12 May 2021 08:51:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BQVBXqIT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237463AbhELPue (ORCPT + 99 others); Wed, 12 May 2021 11:50:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:60804 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234310AbhELPYm (ORCPT ); Wed, 12 May 2021 11:24:42 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 45EA7619C3; Wed, 12 May 2021 15:10:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832212; bh=MVFaAo/NS3ForVKeb4f440SGh3vpacOwrE40HKLW2eM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BQVBXqITjf4U83Sy9Kbant+fuUGpslbPAv02r2y1p8AOHMQt1iBZ/4u50XZJ0D2Tx vwuc900pTfTOkAH5AyCIbQr8SPebR3wzLbQQsBoH2zPw+pGx3d7QnWwJVl5Hvm5giW q4hBtj+zol7Q+ySBq/2wsz3q76v+g3PqWdu02hm4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Fabian Vogt , Sasha Levin Subject: [PATCH 5.10 180/530] fotg210-udc: Dont DMA more than the buffer can take Date: Wed, 12 May 2021 16:44:50 +0200 Message-Id: <20210512144825.749061136@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Fabian Vogt [ Upstream commit 3e7c2510bdfe89a9ec223dd7acd6bfc8bb1cbeb6 ] Before this, it wrote as much as available into the buffer, even if it didn't fit. Fixes: b84a8dee23fd ("usb: gadget: add Faraday fotg210_udc driver") Signed-off-by: Fabian Vogt Link: https://lore.kernel.org/r/20210324141115.9384-7-fabian@ritter-vogt.de Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/gadget/udc/fotg210-udc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/udc/fotg210-udc.c b/drivers/usb/gadget/udc/fotg210-udc.c index bbcc92376307..9925d7ac9138 100644 --- a/drivers/usb/gadget/udc/fotg210-udc.c +++ b/drivers/usb/gadget/udc/fotg210-udc.c @@ -338,8 +338,9 @@ static void fotg210_start_dma(struct fotg210_ep *ep, } else { buffer = req->req.buf + req->req.actual; length = ioread32(ep->fotg210->reg + - FOTG210_FIBCR(ep->epnum - 1)); - length &= FIBCR_BCFX; + FOTG210_FIBCR(ep->epnum - 1)) & FIBCR_BCFX; + if (length > req->req.length - req->req.actual) + length = req->req.length - req->req.actual; } } else { buffer = req->req.buf + req->req.actual; -- 2.30.2