Input: refactor USB endpoint lookups
Subsystems (2)
cover Input: refactor USB endpoint lookups
Use the common USB helpers for looking up bulk and interrupt endpoints instead of open coding.
Johan
Johan Hovold (4):
Input: keyspan-remote - refactor endpoint lookup
Input: appletouch - refactor endpoint lookup
Input: synaptics_usb - refactor endpoint lookup
Input: usbtouchscreen - refactor endpoint lookup
drivers/input/misc/keyspan_remote.c | 22 ++----------- drivers/input/mouse/appletouch.c | 21 ++++-------- drivers/input/mouse/synaptics_usb.c | 23 ++----------- drivers/input/touchscreen/usbtouchscreen.c | 38 +++++++--------------- 4 files changed, 22 insertions(+), 82 deletions(-)
Signature · 1 line
2.52.0
PATCH 1/4 Input: keyspan-remote - refactor endpoint lookup
Use the common USB helper for looking up interrupt-in endpoints instead of open coding.
--- drivers/input/misc/keyspan_remote.c | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-)
drivers/input/misc/keyspan_remote.c +2 -20
@@ -420,24 +420,6 @@ static void keyspan_close(struct input_dev *dev)usb_kill_urb (remote->irq_urb); } -static struct usb_endpoint_descriptor *keyspan_get_in_endpoint (struct usb_host_interface *iface) -{ - -struct usb_endpoint_descriptor *endpoint; -int i; - -for (i =0 ; i < iface->desc.bNumEndpoints; ++i) { - endpoint = &iface->endpoint[i].desc; - -if (usb_endpoint_is_int_in (endpoint)) { -/* we found our interrupt in endpoint */ -return endpoint; - } - } - -return NULL ; -} -/* * Routine that sets up the driver to handle a specific USB device detected on the bus. */
@@ -449,8 +431,8 @@ static int keyspan_probe(struct usb_interface *interface, const struct usb_devicstruct input_dev *input_dev;int i, error; - endpoint =keyspan_get_in_endpoint (interface->cur_altsetting); -if (!endpoint) + error =usb_find_int_in_endpoint (interface->cur_altsetting, &endpoint); +if (error)return -ENODEV ; remote =kzalloc_obj (*remote);
Signature · 1 line
2.52.0
PATCH 2/4 Input: appletouch - refactor endpoint lookup
In reply to Johan HovoldUse the common USB helpers for looking up interrupt-in endpoints (and determining endpoint numbers) instead of open coding.
--- drivers/input/mouse/appletouch.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-)
drivers/input/mouse/appletouch.c +6 -15
@@ -829,29 +829,20 @@ static int atp_probe(struct usb_interface *iface,struct atp *dev;struct input_dev *input_dev;struct usb_device *udev =interface_to_usbdev (iface); -struct usb_host_interface *iface_desc; -struct usb_endpoint_descriptor *endpoint; -int int_in_endpointAddr =0 ; -int i, error = -ENOMEM ; +struct usb_endpoint_descriptor *ep; +int error;const struct atp_info *info = (const struct atp_info *)id->driver_info;/* set up the endpoint information */ /* use only the first interrupt-in endpoint */ - iface_desc = iface->cur_altsetting; -for (i =0 ; i < iface_desc->desc.bNumEndpoints; i++) { - endpoint = &iface_desc->endpoint[i].desc; -if (!int_in_endpointAddr &&usb_endpoint_is_int_in (endpoint)) { -/* we found an interrupt in endpoint */ - int_in_endpointAddr = endpoint->bEndpointAddress; -break ; - } - } -if (!int_in_endpointAddr) { + error =usb_find_int_in_endpoint (iface->cur_altsetting, &ep); +if (error) {dev_err (&iface->dev,"Could not find int-in endpoint\n" );return -EIO ; }/* allocate memory for our device state and initialize it */ + error = -ENOMEM ; dev =kzalloc_obj (*dev); input_dev =input_allocate_device ();if (!dev || !input_dev) {
@@ -875,7 +866,7 @@ static int atp_probe(struct usb_interface *iface, goto err_free_urb;usb_fill_int_urb (dev->urb, udev, -usb_rcvintpipe (udev, int_in_endpointAddr), +usb_rcvintpipe (udev,usb_endpoint_num (ep)), dev->data, dev->info->datalen, dev->info->callback, dev,1 );
Signature · 1 line
2.52.0
PATCH 3/4 Input: synaptics_usb - refactor endpoint lookup
In reply to Johan HovoldUse the common USB helper for looking up interrupt-in endpoints instead of open coding.
--- drivers/input/mouse/synaptics_usb.c | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-)
drivers/input/mouse/synaptics_usb.c +2 -21
@@ -220,25 +220,6 @@ static void synusb_irq(struct urb *urb) __func__, error); } -static struct usb_endpoint_descriptor * -synusb_get_in_endpoint (struct usb_host_interface *iface) -{ - -struct usb_endpoint_descriptor *endpoint; -int i; - -for (i =0 ; i < iface->desc.bNumEndpoints; ++i) { - endpoint = &iface->endpoint[i].desc; - -if (usb_endpoint_is_int_in (endpoint)) { -/* we found our interrupt in endpoint */ -return endpoint; - } - } - -return NULL ; -} -static int synusb_open (struct input_dev *dev) {struct synusb *synusb =input_get_drvdata (dev);
@@ -307,8 +288,8 @@ static int synusb_probe(struct usb_interface *intf,return error; } - ep =synusb_get_in_endpoint (intf->cur_altsetting); -if (!ep) + error =usb_find_int_in_endpoint (intf->cur_altsetting, &ep); +if (error)return -ENODEV ; synusb =kzalloc_obj (*synusb);
Signature · 1 line
2.52.0
PATCH 4/4 Input: usbtouchscreen - refactor endpoint lookup
In reply to Johan HovoldUse the common USB helpers for looking up bulk and interrupt endpoints (and determining endpoint numbers) instead of open coding.
--- drivers/input/touchscreen/usbtouchscreen.c | 38 +++++++--------------- 1 file changed, 12 insertions(+), 26 deletions(-)
drivers/input/touchscreen/usbtouchscreen.c +12 -26
@@ -969,24 +969,21 @@ static int nexio_init(struct usbtouch_usb *usbtouch) {struct usb_device *dev =interface_to_usbdev (usbtouch->interface);struct usb_host_interface *interface = usbtouch->interface->cur_altsetting; +struct usb_endpoint_descriptor *ep_in, *ep_out;struct nexio_priv *priv = usbtouch->priv; -int ret = -ENOMEM ;int actual_len, i;char *firmware_ver =NULL , *device_name =NULL ; -int input_ep =0 , output_ep =0 ; +int input_ep, output_ep; +int ret;/* find first input and output endpoint */ -for (i =0 ; i < interface->desc.bNumEndpoints; i++) { -if (!input_ep && -usb_endpoint_dir_in (&interface->endpoint[i].desc)) - input_ep = interface->endpoint[i].desc.bEndpointAddress; -if (!output_ep && -usb_endpoint_dir_out (&interface->endpoint[i].desc)) - output_ep = interface->endpoint[i].desc.bEndpointAddress; - } -if (!input_ep || !output_ep) + ret =usb_find_common_endpoints (interface, &ep_in, &ep_out,NULL ,NULL ); +if (ret)return -ENXIO ; + input_ep =usb_endpoint_num (ep_in); + output_ep =usb_endpoint_num (ep_out); + u8 *buf __free(kfree) = kmalloc(NEXIO_BUFSIZE, GFP_NOIO);if (!buf)return -ENOMEM ;
@@ -1427,18 +1424,6 @@ static void usbtouch_free_buffers(struct usb_device *udev,kfree (usbtouch->buffer); } -static struct usb_endpoint_descriptor * -usbtouch_get_input_endpoint (struct usb_host_interface *interface) -{ -int i; - -for (i =0 ; i < interface->desc.bNumEndpoints; i++) -if (usb_endpoint_dir_in (&interface->endpoint[i].desc)) -return &interface->endpoint[i].desc; - -return NULL ; -} -static int usbtouch_probe (struct usb_interface *intf,const struct usb_device_id *id) {
@@ -1447,17 +1432,18 @@ static int usbtouch_probe(struct usb_interface *intf,struct usb_endpoint_descriptor *endpoint;struct usb_device *udev =interface_to_usbdev (intf);const struct usbtouch_device_info *type; -int err = -ENOMEM ; +int err;/* some devices are ignored */ type = (const struct usbtouch_device_info *)id->driver_info;if (!type)return -ENODEV ; - endpoint =usbtouch_get_input_endpoint (intf->cur_altsetting); -if (!endpoint) + err =usb_find_int_in_endpoint (intf->cur_altsetting, &endpoint); +if (err)return -ENXIO ; + err = -ENOMEM ; usbtouch =kzalloc_obj (*usbtouch); input_dev =input_allocate_device ();if (!usbtouch || !input_dev)
Signature · 1 line
2.52.0
Dmitry Torokhov
maintainerQuoted 2 lines · Johan Hovold
Use the common USB helpers for looking up bulk and interrupt endpoints instead of open coding.
Applied the lot, thank you.
Signature · 1 line
Dmitry
Dmitry Torokhov
maintainerQuoted 5 lines · Dmitry Torokhov
Quoted 2 lines · Johan Hovold
Use the common USB helpers for looking up bulk and interrupt endpoints instead of open coding.
Applied the lot, thank you.
Actually, dropped patch #4:
https://sashiko.dev/#/patchset/20260330095948.1663141-1-johan%40kernel.org
Thanks.
Signature · 1 line
Dmitry
Quoted 10 lines · Dmitry Torokhov
Quoted 5 lines · Dmitry Torokhov
Quoted 2 lines · Johan Hovold
Use the common USB helpers for looking up bulk and interrupt endpoints instead of open coding.
Applied the lot, thank you.
Actually, dropped patch #4:
https://sashiko.dev/#/patchset/20260330095948.1663141-1-johan%40kernel.org
Thanks, I saw this one last night as well (after reading the LWN article).
I'll send a v2.
Johan