All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fabian Vogt <fabian@ritter-vogt.de>
To: Felipe Balbi <balbi@kernel.org>
Cc: Fabian Vogt <fabian@ritter-vogt.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Yuan-Hsin Chen <yhchen@faraday-tech.com>,
	linux-usb@vger.kernel.org
Subject: [PATCH 6/7] fotg210-udc: Don't DMA more than the buffer can take
Date: Wed, 24 Mar 2021 15:11:14 +0100	[thread overview]
Message-ID: <20210324141115.9384-7-fabian@ritter-vogt.de> (raw)
In-Reply-To: <20210324141115.9384-1-fabian@ritter-vogt.de>

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 <fabian@ritter-vogt.de>
---
 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 6a4c60d5b2c2..7716bd1c8753 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.25.1


  parent reply	other threads:[~2021-03-24 14:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-24 14:11 [PATCH 0/7] Fix the fotg210-udc driver Fabian Vogt
2021-03-24 14:11 ` [PATCH 1/7] fotg210-udc: Fix DMA on EP0 for length > max packet size Fabian Vogt
2021-03-24 14:11 ` [PATCH 2/7] fotg210-udc: Fix EP0 IN requests bigger than two packets Fabian Vogt
2021-03-24 14:11 ` [PATCH 3/7] fotg210-udc: Remove a dubious condition leading to fotg210_done Fabian Vogt
2021-03-24 14:11 ` [PATCH 4/7] fotg210-udc: Mask GRP2 interrupts we don't handle Fabian Vogt
2021-03-24 14:11 ` [PATCH 5/7] fotg210-udc: Call usb_gadget_udc_reset Fabian Vogt
2021-03-24 14:11 ` Fabian Vogt [this message]
2021-03-24 14:11 ` [PATCH 7/7] fotg210-udc: Complete OUT requests on short packets Fabian Vogt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210324141115.9384-7-fabian@ritter-vogt.de \
    --to=fabian@ritter-vogt.de \
    --cc=balbi@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=yhchen@faraday-tech.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.