Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp342186pxj; Thu, 20 May 2021 10:32:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhPpYwMYPqAwC09ehQ7n8WcEGgJ8MHFjY0FeaEWUj/I/V254SwiecH00xEKxCpLxML78pj X-Received: by 2002:a17:906:edaf:: with SMTP id sa15mr5824103ejb.174.1621531965183; Thu, 20 May 2021 10:32:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621531965; cv=none; d=google.com; s=arc-20160816; b=jjQOaz84DNAcdEnW0ZXJE1EiK73ISwpJKpWIyYgrr66X6sq/rGVedwlAHMiVhhLEV1 iEKlC+ReoZeZGTayicotwLVKcTAtMO59BtNtnaXfYihmPq77XFk2MuVGQRFZQ5odoIan q9nc6lirTbzJwCeE9hXOQShsRMOK7F1RGCW4v0L4YaUzHYxQjfEmV6tzkGPV/G+5iOs8 jaUQs/TvdHllkBwptXFg2oo8yS/TUi8xwAHG9hj2R13Y5XY54s/sxq3R7O2l10egx40k oePe22oRjzuXrepD1IVSCMa/jti7gLmIEZOFtstNfcMb27jzIGy48rp5hgqgnnD1jOk8 c53w== 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=af80CkrDNagZBletGN003ZQSItyqbH1aW37GIHjwDaI=; b=JngLP/jdM5nySCNTA7XGF1kzhxpErGNX6IaQ5YF1wuq7yCsJCs8Zoq2EtE9x+nNBXl I/Zc1AWQaXecVpk4BE1iISBXz2UMqjt+PezZ30OZtiBqSLsu8pVmNyZucnxidpsSNITg LscSGP8x7rxaVlNIWZ7ylTpubYX5onZIPH8bDN+Ub/YFdLvYOHizzrWOq1exyN1/wb/o g49zQJIJYAm9syoio76RPoLCTVl4qkgOD6hEMDGtDsphY2uY4xot7YB5gX9sJQc2FaYn TwJSHjI95gD/2ke0FSsICyqUTJnGtI/8lZamTpEG8Clai9+z5rqREaYr45Q5V8EWbgiq 0AwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="I7w2c/tU"; 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 bg21si3316108ejb.58.2021.05.20.10.32.21; Thu, 20 May 2021 10:32:45 -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="I7w2c/tU"; 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 S235114AbhETJ7Z (ORCPT + 99 others); Thu, 20 May 2021 05:59:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:58884 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234999AbhETJz3 (ORCPT ); Thu, 20 May 2021 05:55:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A020361407; Thu, 20 May 2021 09:37:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503436; bh=DNbB14rNDgp36EwfV0cee1kPB1JosHYihntvhZHWNME=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I7w2c/tU92BT/HNahDzusf8VB/Az4YDPnAdsCxrBXB2mXmuUZBGln2n1kr5JsE++y UtRd37+b4Vu9GIv4YXqPQ0hAjoGw0w4fZxNLTg/7JwiJXM50tJwxaEFaFEyUdQWRq4 2Q8ELfpwbkFdW5RDBecVYpD1wZPYVuPRXkcU0gKg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Fabian Vogt , Sasha Levin Subject: [PATCH 4.19 187/425] fotg210-udc: Dont DMA more than the buffer can take Date: Thu, 20 May 2021 11:19:16 +0200 Message-Id: <20210520092137.566807812@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@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 41cc5babd50d..7ae0243c32e5 100644 --- a/drivers/usb/gadget/udc/fotg210-udc.c +++ b/drivers/usb/gadget/udc/fotg210-udc.c @@ -337,8 +337,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