[PATCH 70/75] backports: Move usb_check_bulk_endpoints to 6.4

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



usb_check_bulk_endpoints() was added in kernel 6.4 and then backported
to older kernel versions.

Signed-off-by: Hauke Mehrtens <hauke@xxxxxxxxxx>
---
 backport/backport-include/linux/usb.h |  6 ++-
 backport/compat/Makefile              |  1 +
 backport/compat/backport-5.15.c       | 52 -----------------------
 backport/compat/backport-6.4.c        | 61 +++++++++++++++++++++++++++
 4 files changed, 67 insertions(+), 53 deletions(-)
 create mode 100644 backport/compat/backport-6.4.c

diff --git a/backport/backport-include/linux/usb.h b/backport/backport-include/linux/usb.h
index ba39657b..0f6c3b88 100644
--- a/backport/backport-include/linux/usb.h
+++ b/backport/backport-include/linux/usb.h
@@ -3,7 +3,11 @@
 #include_next <linux/usb.h>
 #include <linux/version.h>
 
-#if LINUX_VERSION_IS_LESS(5,15,0)
+#if LINUX_VERSION_IS_LESS(6,3,5) && \
+	!LINUX_VERSION_IN_RANGE(6,1,31, 6,2,0) &&     \
+	!LINUX_VERSION_IN_RANGE(5,15,114, 5,16,0) &&     \
+	!LINUX_VERSION_IN_RANGE(5,10,181, 5,11,0) &&     \
+	!LINUX_VERSION_IN_RANGE(5,4,244, 5,5,0)
 #define usb_check_bulk_endpoints LINUX_BACKPORT(usb_check_bulk_endpoints)
 bool usb_check_bulk_endpoints(
 		const struct usb_interface *intf, const u8 *ep_addrs);
diff --git a/backport/compat/Makefile b/backport/compat/Makefile
index 0e48ca01..51b95384 100644
--- a/backport/compat/Makefile
+++ b/backport/compat/Makefile
@@ -17,4 +17,5 @@ compat-$(CPTCFG_KERNEL_5_10) += backport-5.10.o
 compat-$(CPTCFG_KERNEL_5_11) += backport-5.11.o
 compat-$(CPTCFG_KERNEL_5_13) += backport-5.13.o
 compat-$(CPTCFG_KERNEL_5_15) += backport-5.15.o
+compat-$(CPTCFG_KERNEL_6_4) += backport-6.4.o
 
diff --git a/backport/compat/backport-5.15.c b/backport/compat/backport-5.15.c
index bfafaec5..c93f922e 100644
--- a/backport/compat/backport-5.15.c
+++ b/backport/compat/backport-5.15.c
@@ -4,7 +4,6 @@
 #include <linux/export.h>
 #include <linux/uaccess.h>
 #include <linux/netdevice.h>
-#include <linux/usb.h>
 
 #include <uapi/linux/if.h>
 
@@ -51,54 +50,3 @@ int put_user_ifreq(struct ifreq *ifr, void __user *arg)
 	return 0;
 }
 EXPORT_SYMBOL(put_user_ifreq);
-
-
-/**
- * usb_find_endpoint() - Given an endpoint address, search for the endpoint's
- * usb_host_endpoint structure in an interface's current altsetting.
- * @intf: the interface whose current altsetting should be searched
- * @ep_addr: the endpoint address (number and direction) to find
- *
- * Search the altsetting's list of endpoints for one with the specified address.
- *
- * Return: Pointer to the usb_host_endpoint if found, %NULL otherwise.
- */
-static const struct usb_host_endpoint *usb_find_endpoint(
-		const struct usb_interface *intf, unsigned int ep_addr)
-{
-	int n;
-	const struct usb_host_endpoint *ep;
-
-	n = intf->cur_altsetting->desc.bNumEndpoints;
-	ep = intf->cur_altsetting->endpoint;
-	for (; n > 0; (--n, ++ep)) {
-		if (ep->desc.bEndpointAddress == ep_addr)
-			return ep;
-	}
-	return NULL;
-}
-
-/**
- * usb_check_bulk_endpoints - Check whether an interface's current altsetting
- * contains a set of bulk endpoints with the given addresses.
- * @intf: the interface whose current altsetting should be searched
- * @ep_addrs: 0-terminated array of the endpoint addresses (number and
- * direction) to look for
- *
- * Search for endpoints with the specified addresses and check their types.
- *
- * Return: %true if all the endpoints are found and are bulk, %false otherwise.
- */
-bool usb_check_bulk_endpoints(
-		const struct usb_interface *intf, const u8 *ep_addrs)
-{
-	const struct usb_host_endpoint *ep;
-
-	for (; *ep_addrs; ++ep_addrs) {
-		ep = usb_find_endpoint(intf, *ep_addrs);
-		if (!ep || !usb_endpoint_xfer_bulk(&ep->desc))
-			return false;
-	}
-	return true;
-}
-EXPORT_SYMBOL_GPL(usb_check_bulk_endpoints);
diff --git a/backport/compat/backport-6.4.c b/backport/compat/backport-6.4.c
new file mode 100644
index 00000000..73177e24
--- /dev/null
+++ b/backport/compat/backport-6.4.c
@@ -0,0 +1,61 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/export.h>
+#include <linux/usb.h>
+
+#if LINUX_VERSION_IS_LESS(6,3,5) && \
+	!LINUX_VERSION_IN_RANGE(6,1,31, 6,2,0) &&     \
+	!LINUX_VERSION_IN_RANGE(5,15,114, 5,16,0) &&     \
+	!LINUX_VERSION_IN_RANGE(5,10,181, 5,11,0) &&     \
+	!LINUX_VERSION_IN_RANGE(5,4,244, 5,5,0)
+
+/**
+ * usb_find_endpoint() - Given an endpoint address, search for the endpoint's
+ * usb_host_endpoint structure in an interface's current altsetting.
+ * @intf: the interface whose current altsetting should be searched
+ * @ep_addr: the endpoint address (number and direction) to find
+ *
+ * Search the altsetting's list of endpoints for one with the specified address.
+ *
+ * Return: Pointer to the usb_host_endpoint if found, %NULL otherwise.
+ */
+static const struct usb_host_endpoint *usb_find_endpoint(
+		const struct usb_interface *intf, unsigned int ep_addr)
+{
+	int n;
+	const struct usb_host_endpoint *ep;
+
+	n = intf->cur_altsetting->desc.bNumEndpoints;
+	ep = intf->cur_altsetting->endpoint;
+	for (; n > 0; (--n, ++ep)) {
+		if (ep->desc.bEndpointAddress == ep_addr)
+			return ep;
+	}
+	return NULL;
+}
+
+/**
+ * usb_check_bulk_endpoints - Check whether an interface's current altsetting
+ * contains a set of bulk endpoints with the given addresses.
+ * @intf: the interface whose current altsetting should be searched
+ * @ep_addrs: 0-terminated array of the endpoint addresses (number and
+ * direction) to look for
+ *
+ * Search for endpoints with the specified addresses and check their types.
+ *
+ * Return: %true if all the endpoints are found and are bulk, %false otherwise.
+ */
+bool usb_check_bulk_endpoints(
+		const struct usb_interface *intf, const u8 *ep_addrs)
+{
+	const struct usb_host_endpoint *ep;
+
+	for (; *ep_addrs; ++ep_addrs) {
+		ep = usb_find_endpoint(intf, *ep_addrs);
+		if (!ep || !usb_endpoint_xfer_bulk(&ep->desc))
+			return false;
+	}
+	return true;
+}
+EXPORT_SYMBOL_GPL(usb_check_bulk_endpoints);
+#endif
-- 
2.45.2





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux