Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Input: usbtouchscreen - refactor endpoint lookup

Use the common USB helpers for looking up bulk and interrupt endpoints
(and determining endpoint numbers) instead of open coding.

Note that the NEXIO data interface has two bulk endpoints (see commit
5197424cdccc ("Input: usbtouchscreen - add NEXIO (or iNexio) support")
for the descriptors).

The lookup in probe handles both bulk-in and interrupt-in endpoints and
was added to handle NEXIO devices. Replace the open coded lookup with a
lookup for the common interrupt endpoint and an explicit fallback
accepting a bulk endpoint.

This iterates over the (two) endpoints twice for NEXIO devices but makes
it more clear what is going on.

Signed-off-by: Johan Hovold <johan@kernel.org>
Link: https://patch.msgid.link/20260401082212.2180434-1-johan@kernel.org
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Johan Hovold and committed by
Dmitry Torokhov
f13b7800 df53055c

+16 -27
+16 -27
drivers/input/touchscreen/usbtouchscreen.c
··· 969 969 { 970 970 struct usb_device *dev = interface_to_usbdev(usbtouch->interface); 971 971 struct usb_host_interface *interface = usbtouch->interface->cur_altsetting; 972 + struct usb_endpoint_descriptor *ep_in, *ep_out; 972 973 struct nexio_priv *priv = usbtouch->priv; 973 - int ret = -ENOMEM; 974 974 int actual_len, i; 975 975 char *firmware_ver = NULL, *device_name = NULL; 976 - int input_ep = 0, output_ep = 0; 976 + int input_ep, output_ep; 977 + int ret; 977 978 978 979 /* find first input and output endpoint */ 979 - for (i = 0; i < interface->desc.bNumEndpoints; i++) { 980 - if (!input_ep && 981 - usb_endpoint_dir_in(&interface->endpoint[i].desc)) 982 - input_ep = interface->endpoint[i].desc.bEndpointAddress; 983 - if (!output_ep && 984 - usb_endpoint_dir_out(&interface->endpoint[i].desc)) 985 - output_ep = interface->endpoint[i].desc.bEndpointAddress; 986 - } 987 - if (!input_ep || !output_ep) 980 + ret = usb_find_common_endpoints(interface, &ep_in, &ep_out, NULL, NULL); 981 + if (ret) 988 982 return -ENXIO; 983 + 984 + input_ep = usb_endpoint_num(ep_in); 985 + output_ep = usb_endpoint_num(ep_out); 989 986 990 987 u8 *buf __free(kfree) = kmalloc(NEXIO_BUFSIZE, GFP_NOIO); 991 988 if (!buf) ··· 1424 1427 kfree(usbtouch->buffer); 1425 1428 } 1426 1429 1427 - static struct usb_endpoint_descriptor * 1428 - usbtouch_get_input_endpoint(struct usb_host_interface *interface) 1429 - { 1430 - int i; 1431 - 1432 - for (i = 0; i < interface->desc.bNumEndpoints; i++) 1433 - if (usb_endpoint_dir_in(&interface->endpoint[i].desc)) 1434 - return &interface->endpoint[i].desc; 1435 - 1436 - return NULL; 1437 - } 1438 - 1439 1430 static int usbtouch_probe(struct usb_interface *intf, 1440 1431 const struct usb_device_id *id) 1441 1432 { ··· 1432 1447 struct usb_endpoint_descriptor *endpoint; 1433 1448 struct usb_device *udev = interface_to_usbdev(intf); 1434 1449 const struct usbtouch_device_info *type; 1435 - int err = -ENOMEM; 1450 + int err; 1436 1451 1437 1452 /* some devices are ignored */ 1438 1453 type = (const struct usbtouch_device_info *)id->driver_info; 1439 1454 if (!type) 1440 1455 return -ENODEV; 1441 1456 1442 - endpoint = usbtouch_get_input_endpoint(intf->cur_altsetting); 1443 - if (!endpoint) 1444 - return -ENXIO; 1457 + err = usb_find_int_in_endpoint(intf->cur_altsetting, &endpoint); 1458 + if (err) { 1459 + err = usb_find_bulk_in_endpoint(intf->cur_altsetting, &endpoint); 1460 + if (err) 1461 + return -ENXIO; 1462 + } 1445 1463 1464 + err = -ENOMEM; 1446 1465 usbtouch = kzalloc_obj(*usbtouch); 1447 1466 input_dev = input_allocate_device(); 1448 1467 if (!usbtouch || !input_dev)