Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: chipidea: udc: limit usb request length to max 16KB

To let the device controller work properly on short packet limitations,
one usb request should only correspond to one dTD. Then every dTD will
set IOC. In theory, each dTD support up to 20KB data transfer if the
offset is 0. Due to we cannot predetermine the offset, this will limit
the usb request length to max 16KB. This should be fine since most of
the user transfer data based on this size policy.

Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
Acked-by: Peter Chen <peter.chen@kernel.org>
Link: https://lore.kernel.org/r/20240923081203.2851768-2-xu.yang_2@nxp.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Xu Yang and committed by
Greg Kroah-Hartman
ca8d18aa ec841b8d

+7
+1
drivers/usb/chipidea/ci.h
··· 25 25 #define TD_PAGE_COUNT 5 26 26 #define CI_HDRC_PAGE_SIZE 4096ul /* page size for TD's */ 27 27 #define ENDPT_MAX 32 28 + #define CI_MAX_REQ_SIZE (4 * CI_HDRC_PAGE_SIZE) 28 29 #define CI_MAX_BUF_SIZE (TD_PAGE_COUNT * CI_HDRC_PAGE_SIZE) 29 30 30 31 /******************************************************************************
+6
drivers/usb/chipidea/udc.c
··· 960 960 return -EMSGSIZE; 961 961 } 962 962 963 + if (ci->has_short_pkt_limit && 964 + hwreq->req.length > CI_MAX_REQ_SIZE) { 965 + dev_err(hwep->ci->dev, "request length too big (max 16KB)\n"); 966 + return -EMSGSIZE; 967 + } 968 + 963 969 /* first nuke then test link, e.g. previous status has not sent */ 964 970 if (!list_empty(&hwreq->queue)) { 965 971 dev_err(hwep->ci->dev, "request already in queue\n");