Oliver Neukum 324082
From 46ed6026ca2181c917c8334a82e3eaf40a6234dd Mon Sep 17 00:00:00 2001
Oliver Neukum 324082
From: Linus Walleij <linus.walleij@linaro.org>
Oliver Neukum 324082
Date: Fri, 11 Nov 2022 10:03:17 +0100
Oliver Neukum 324082
Subject: [PATCH] usb: fotg210-udc: Fix ages old endianness issues
Oliver Neukum 324082
Git-commit: 46ed6026ca2181c917c8334a82e3eaf40a6234dd
Oliver Neukum 324082
References: git-fixes
Oliver Neukum 324082
Patch-mainline: v6.2-rc1
Oliver Neukum 324082
Oliver Neukum 324082
The code in the FOTG210 driver isn't entirely endianness-agnostic
Oliver Neukum 324082
as reported by the kernel robot sparse testing. This came to
Oliver Neukum 324082
the surface while moving the files around.
Oliver Neukum 324082
Oliver Neukum 324082
The driver is only used on little-endian systems, so this causes
Oliver Neukum 324082
no real-world regression, but it is nice to be strict and have
Oliver Neukum 324082
some compile coverage also on big endian machines, so fix it
Oliver Neukum 324082
up with the right LE accessors.
Oliver Neukum 324082
Oliver Neukum 324082
Fixes: b84a8dee23fd ("usb: gadget: add Faraday fotg210_udc driver")
Oliver Neukum 324082
Reported-by: kernel test robot <lkp@intel.com>
Oliver Neukum 324082
Link: https://lore.kernel.org/linux-usb/202211110910.0dJ7nZCn-lkp@intel.com/
Oliver Neukum 324082
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Oliver Neukum 324082
Link: https://lore.kernel.org/r/20221111090317.94228-1-linus.walleij@linaro.org
Oliver Neukum 324082
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Oliver Neukum 324082
Signed-off-by: Oliver Neukum <oneukum@suse.com>
Oliver Neukum 324082
---
Oliver Neukum 324082
 drivers/usb/fotg210/fotg210-udc.c | 12 ++++++------
Oliver Neukum 324082
 1 file changed, 6 insertions(+), 6 deletions(-)
Oliver Neukum 324082
Oliver Neukum 324082
diff --git a/drivers/usb/fotg210/fotg210-udc.c b/drivers/usb/fotg210/fotg210-udc.c
Oliver Neukum 324082
index 7757aaa11d6f..3c357ce42d3b 100644
Oliver Neukum 324082
--- a/drivers/usb/gadget/udc/fotg210-udc.c
Oliver Neukum 324082
+++ b/drivers/usb/gadget/udc/fotg210-udc.c
Oliver Neukum 324082
@@ -630,10 +630,10 @@ static void fotg210_request_error(struct fotg210_udc *fotg210)
Oliver Neukum 324082
 static void fotg210_set_address(struct fotg210_udc *fotg210,
Oliver Neukum 324082
 				struct usb_ctrlrequest *ctrl)
Oliver Neukum 324082
 {
Oliver Neukum 324082
-	if (ctrl->wValue >= 0x0100) {
Oliver Neukum 324082
+	if (le16_to_cpu(ctrl->wValue) >= 0x0100) {
Oliver Neukum 324082
 		fotg210_request_error(fotg210);
Oliver Neukum 324082
 	} else {
Oliver Neukum 324082
-		fotg210_set_dev_addr(fotg210, ctrl->wValue);
Oliver Neukum 324082
+		fotg210_set_dev_addr(fotg210, le16_to_cpu(ctrl->wValue));
Oliver Neukum 324082
 		fotg210_set_cxdone(fotg210);
Oliver Neukum 324082
 	}
Oliver Neukum 324082
 }
Oliver Neukum 324082
@@ -714,17 +714,17 @@ static void fotg210_get_status(struct fotg210_udc *fotg210,
Oliver Neukum 324082
 
Oliver Neukum 324082
 	switch (ctrl->bRequestType & USB_RECIP_MASK) {
Oliver Neukum 324082
 	case USB_RECIP_DEVICE:
Oliver Neukum 324082
-		fotg210->ep0_data = 1 << USB_DEVICE_SELF_POWERED;
Oliver Neukum 324082
+		fotg210->ep0_data = cpu_to_le16(1 << USB_DEVICE_SELF_POWERED);
Oliver Neukum 324082
 		break;
Oliver Neukum 324082
 	case USB_RECIP_INTERFACE:
Oliver Neukum 324082
-		fotg210->ep0_data = 0;
Oliver Neukum 324082
+		fotg210->ep0_data = cpu_to_le16(0);
Oliver Neukum 324082
 		break;
Oliver Neukum 324082
 	case USB_RECIP_ENDPOINT:
Oliver Neukum 324082
 		epnum = ctrl->wIndex & USB_ENDPOINT_NUMBER_MASK;
Oliver Neukum 324082
 		if (epnum)
Oliver Neukum 324082
 			fotg210->ep0_data =
Oliver Neukum 324082
-				fotg210_is_epnstall(fotg210->ep[epnum])
Oliver Neukum 324082
-				<< USB_ENDPOINT_HALT;
Oliver Neukum 324082
+				cpu_to_le16(fotg210_is_epnstall(fotg210->ep[epnum])
Oliver Neukum 324082
+					    << USB_ENDPOINT_HALT);
Oliver Neukum 324082
 		else
Oliver Neukum 324082
 			fotg210_request_error(fotg210);
Oliver Neukum 324082
 		break;
Oliver Neukum 324082
-- 
Oliver Neukum 324082
2.39.0
Oliver Neukum 324082