From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E8AF35C1BC; Sat, 17 Oct 2026 17:31:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792258305; cv=none; b=iyxRDsqFut6jA4V02kAsQPBuBYi3UBr8xFKz1CbOvP/4Km63AF1YhXNxFM3b+GjsGAdLr2j+Ddn5Mvl/gL4pXONJzarVUBqMK3BQtiyx2CgIaDDGffbaviSpJLUeZ0CybNnPMnm53gkh8JzmAHY+PQ7B4O7TE/AELb2W+o1coQA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792258305; c=relaxed/simple; bh=UoaPdQdI7EzJvncAlVqNgClY+HYa1GujQIE4PvgVdNM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iFYbmBhIuOkhKWHB9XGAlFvyVDLAHui8mJMwI3SjpqGn+Z8eI2NQeQUCRsbexmR5sVw1INzJsmZpqwQv32dh+eHz53ebUQVTl06Uoj1cjouD4QqV5f+IYUPK/Jt8jzx91VyjAPph5VumO6hNSygo1Etq8YzbRXKK7xPOZ+2xbnw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=dT5nIEW8; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="dT5nIEW8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D43321F000C4; Sat, 17 Oct 2026 17:31:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1792258304; bh=PpKIK41tjrKgzl3JpbGG9ZUTgQCyyfpALNni6PBFPM4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=dT5nIEW8OYL2rYrM5idDIzSbgHzhGxX2/tcP0jszC8UcS5gmCAcwtsltKl8bRnN/c WL3T0ge5+An5ASAodXh8/SZ0uMB0LquopUmNt69OAmBZRUFcTipbqr0aFppFx3Xs12 gt/xZhNOknSmcOz0adxhSa3H+es8BOEnXGkzmhyg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Paul Cercueil , Sasha Levin Subject: [PATCH 6.6 0838/1674] usb: gadget: Support already-mapped DMA SGs Date: Sat, 17 Oct 2026 17:51:50 +0200 Message-ID: <20261017160452.640193565@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261017160431.119607952@linuxfoundation.org> References: <20261017160431.119607952@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Paul Cercueil [ Upstream commit 99f638dd49ca80538addec6b3733ddb5784c9373 ] Add a new 'sg_was_mapped' field to the struct usb_request. This field can be used to indicate that the scatterlist associated to the USB transfer has already been mapped into the DMA space, and it does not have to be done internally. Signed-off-by: Paul Cercueil Link: https://lore.kernel.org/r/20240130122340.54813-2-paul@crapouillou.net Signed-off-by: Greg Kroah-Hartman Stable-dep-of: e5bf5ee26663 ("functionfs: fix the open/removal races") Signed-off-by: Sasha Levin --- drivers/usb/gadget/udc/core.c | 7 ++++++- include/linux/usb/gadget.h | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c index 2ef28760e9ad9..365d1f77856e2 100644 --- a/drivers/usb/gadget/udc/core.c +++ b/drivers/usb/gadget/udc/core.c @@ -913,6 +913,11 @@ int usb_gadget_map_request_by_dev(struct device *dev, if (req->length == 0) return 0; + if (req->sg_was_mapped) { + req->num_mapped_sgs = req->num_sgs; + return 0; + } + if (req->num_sgs) { int mapped; @@ -958,7 +963,7 @@ EXPORT_SYMBOL_GPL(usb_gadget_map_request); void usb_gadget_unmap_request_by_dev(struct device *dev, struct usb_request *req, int is_in) { - if (req->length == 0) + if (req->length == 0 || req->sg_was_mapped) return; if (req->num_mapped_sgs) { diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h index 1a13d0c01b0aa..6ec7f94c5adc2 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -54,6 +54,7 @@ struct usb_ep; * @short_not_ok: When reading data, makes short packets be * treated as errors (queue stops advancing till cleanup). * @dma_mapped: Indicates if request has been mapped to DMA (internal) + * @sg_was_mapped: Set if the scatterlist has been mapped before the request * @complete: Function called when request completes, so this request and * its buffer may be re-used. The function will always be called with * interrupts disabled, and it must not sleep. @@ -114,6 +115,7 @@ struct usb_request { unsigned zero:1; unsigned short_not_ok:1; unsigned dma_mapped:1; + unsigned sg_was_mapped:1; void (*complete)(struct usb_ep *ep, struct usb_request *req); -- 2.53.0