]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
usb: dwc2: gadget: Don't write invalid mapped sg entries into dma_desc with iommu...
authorPeng Hongchi <hongchi.peng@siengine.com>
Sun, 28 Jul 2024 16:09:38 +0000 (12:09 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 9 Jan 2025 12:24:51 +0000 (13:24 +0100)
commite430962901c7eba17a9326c54e4c7fa2a93065e6
tree0fd48b8ebd7de6f52aae4aa130e4aa70a6844a0c
parent4ba1ee910938800f0599f714f1abdf06203cccc9
usb: dwc2: gadget: Don't write invalid mapped sg entries into dma_desc with iommu enabled

[ Upstream commit 1134289b6b93d73721340b66c310fd985385e8fa ]

When using dma_map_sg() to map the scatterlist with iommu enabled,
the entries in the scatterlist can be mergerd into less but longer
entries in the function __finalise_sg(). So that the number of
valid mapped entries is actually smaller than ureq->num_reqs,and
there are still some invalid entries in the scatterlist with
dma_addr=0xffffffff and len=0. Writing these invalid sg entries
into the dma_desc can cause a data transmission error.

The function dma_map_sg() returns the number of valid map entries
and the return value is assigned to usb_request::num_mapped_sgs in
function usb_gadget_map_request_by_dev(). So that just write valid
mapped entries into dma_desc according to the usb_request::num_mapped_sgs,
and set the IOC bit if it's the last valid mapped entry.

This patch poses no risk to no-iommu situation, cause
ureq->num_mapped_sgs equals ureq->num_sgs while using dma_direct_map_sg()
to map the scatterlist whith iommu disabled.

Signed-off-by: Peng Hongchi <hongchi.peng@siengine.com>
Link: https://lore.kernel.org/r/20240523100315.7226-1-hongchi.peng@siengine.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/usb/dwc2/gadget.c