Skip to content

Commit f13b780

Browse files
jhovolddtor
authored andcommitted
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 5197424 ("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>
1 parent df53055 commit f13b780

1 file changed

Lines changed: 16 additions & 27 deletions

File tree

drivers/input/touchscreen/usbtouchscreen.c

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -969,24 +969,21 @@ static int nexio_init(struct usbtouch_usb *usbtouch)
969969
{
970970
struct usb_device *dev = interface_to_usbdev(usbtouch->interface);
971971
struct usb_host_interface *interface = usbtouch->interface->cur_altsetting;
972+
struct usb_endpoint_descriptor *ep_in, *ep_out;
972973
struct nexio_priv *priv = usbtouch->priv;
973-
int ret = -ENOMEM;
974974
int actual_len, i;
975975
char *firmware_ver = NULL, *device_name = NULL;
976-
int input_ep = 0, output_ep = 0;
976+
int input_ep, output_ep;
977+
int ret;
977978

978979
/* 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)
988982
return -ENXIO;
989983

984+
input_ep = usb_endpoint_num(ep_in);
985+
output_ep = usb_endpoint_num(ep_out);
986+
990987
u8 *buf __free(kfree) = kmalloc(NEXIO_BUFSIZE, GFP_NOIO);
991988
if (!buf)
992989
return -ENOMEM;
@@ -1427,18 +1424,6 @@ static void usbtouch_free_buffers(struct usb_device *udev,
14271424
kfree(usbtouch->buffer);
14281425
}
14291426

1430-
static struct usb_endpoint_descriptor *
1431-
usbtouch_get_input_endpoint(struct usb_host_interface *interface)
1432-
{
1433-
int i;
1434-
1435-
for (i = 0; i < interface->desc.bNumEndpoints; i++)
1436-
if (usb_endpoint_dir_in(&interface->endpoint[i].desc))
1437-
return &interface->endpoint[i].desc;
1438-
1439-
return NULL;
1440-
}
1441-
14421427
static int usbtouch_probe(struct usb_interface *intf,
14431428
const struct usb_device_id *id)
14441429
{
@@ -1447,17 +1432,21 @@ static int usbtouch_probe(struct usb_interface *intf,
14471432
struct usb_endpoint_descriptor *endpoint;
14481433
struct usb_device *udev = interface_to_usbdev(intf);
14491434
const struct usbtouch_device_info *type;
1450-
int err = -ENOMEM;
1435+
int err;
14511436

14521437
/* some devices are ignored */
14531438
type = (const struct usbtouch_device_info *)id->driver_info;
14541439
if (!type)
14551440
return -ENODEV;
14561441

1457-
endpoint = usbtouch_get_input_endpoint(intf->cur_altsetting);
1458-
if (!endpoint)
1459-
return -ENXIO;
1442+
err = usb_find_int_in_endpoint(intf->cur_altsetting, &endpoint);
1443+
if (err) {
1444+
err = usb_find_bulk_in_endpoint(intf->cur_altsetting, &endpoint);
1445+
if (err)
1446+
return -ENXIO;
1447+
}
14601448

1449+
err = -ENOMEM;
14611450
usbtouch = kzalloc_obj(*usbtouch);
14621451
input_dev = input_allocate_device();
14631452
if (!usbtouch || !input_dev)

0 commit comments

Comments
 (0)