hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/usb/core/usb.c
....@@ -208,6 +208,82 @@
208208 EXPORT_SYMBOL_GPL(usb_find_common_endpoints_reverse);
209209
210210 /**
211
+ * usb_find_endpoint() - Given an endpoint address, search for the endpoint's
212
+ * usb_host_endpoint structure in an interface's current altsetting.
213
+ * @intf: the interface whose current altsetting should be searched
214
+ * @ep_addr: the endpoint address (number and direction) to find
215
+ *
216
+ * Search the altsetting's list of endpoints for one with the specified address.
217
+ *
218
+ * Return: Pointer to the usb_host_endpoint if found, %NULL otherwise.
219
+ */
220
+static const struct usb_host_endpoint *usb_find_endpoint(
221
+ const struct usb_interface *intf, unsigned int ep_addr)
222
+{
223
+ int n;
224
+ const struct usb_host_endpoint *ep;
225
+
226
+ n = intf->cur_altsetting->desc.bNumEndpoints;
227
+ ep = intf->cur_altsetting->endpoint;
228
+ for (; n > 0; (--n, ++ep)) {
229
+ if (ep->desc.bEndpointAddress == ep_addr)
230
+ return ep;
231
+ }
232
+ return NULL;
233
+}
234
+
235
+/**
236
+ * usb_check_bulk_endpoints - Check whether an interface's current altsetting
237
+ * contains a set of bulk endpoints with the given addresses.
238
+ * @intf: the interface whose current altsetting should be searched
239
+ * @ep_addrs: 0-terminated array of the endpoint addresses (number and
240
+ * direction) to look for
241
+ *
242
+ * Search for endpoints with the specified addresses and check their types.
243
+ *
244
+ * Return: %true if all the endpoints are found and are bulk, %false otherwise.
245
+ */
246
+bool usb_check_bulk_endpoints(
247
+ const struct usb_interface *intf, const u8 *ep_addrs)
248
+{
249
+ const struct usb_host_endpoint *ep;
250
+
251
+ for (; *ep_addrs; ++ep_addrs) {
252
+ ep = usb_find_endpoint(intf, *ep_addrs);
253
+ if (!ep || !usb_endpoint_xfer_bulk(&ep->desc))
254
+ return false;
255
+ }
256
+ return true;
257
+}
258
+EXPORT_SYMBOL_GPL(usb_check_bulk_endpoints);
259
+
260
+/**
261
+ * usb_check_int_endpoints - Check whether an interface's current altsetting
262
+ * contains a set of interrupt endpoints with the given addresses.
263
+ * @intf: the interface whose current altsetting should be searched
264
+ * @ep_addrs: 0-terminated array of the endpoint addresses (number and
265
+ * direction) to look for
266
+ *
267
+ * Search for endpoints with the specified addresses and check their types.
268
+ *
269
+ * Return: %true if all the endpoints are found and are interrupt,
270
+ * %false otherwise.
271
+ */
272
+bool usb_check_int_endpoints(
273
+ const struct usb_interface *intf, const u8 *ep_addrs)
274
+{
275
+ const struct usb_host_endpoint *ep;
276
+
277
+ for (; *ep_addrs; ++ep_addrs) {
278
+ ep = usb_find_endpoint(intf, *ep_addrs);
279
+ if (!ep || !usb_endpoint_xfer_int(&ep->desc))
280
+ return false;
281
+ }
282
+ return true;
283
+}
284
+EXPORT_SYMBOL_GPL(usb_check_int_endpoints);
285
+
286
+/**
211287 * usb_find_alt_setting() - Given a configuration, find the alternate setting
212288 * for the given interface.
213289 * @config: the configuration to search (not necessarily the current config).