public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/6] media: refactor USB endpoint lookups
@ 2026-03-30 10:11 Johan Hovold
  2026-03-30 10:11 ` [PATCH 1/6] media: si470x-usb: refactor endpoint lookup Johan Hovold
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Johan Hovold @ 2026-03-30 10:11 UTC (permalink / raw)
  To: Hans Verkuil, Sean Young, Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel, Johan Hovold

Use the common USB helpers for looking up bulk and interrupt endpoints
instead of open coding.

Johan


Johan Hovold (6):
  media: si470x-usb: refactor endpoint lookup
  media: imon_raw: refactor endpoint lookup
  media: irtoy: refactor endpoint lookup
  media: gspca: refactor endpoint lookup
  media: hdpvr: refactor endpoint lookup
  media: s2255: refactor endpoint lookup

 drivers/media/radio/si470x/radio-si470x-usb.c | 11 +++-----
 drivers/media/rc/imon_raw.c                   | 18 +++----------
 drivers/media/rc/ir_toy.c                     | 23 +++++-----------
 drivers/media/usb/gspca/gspca.c               | 17 +++++-------
 drivers/media/usb/hdpvr/hdpvr-core.c          | 26 ++++++-------------
 drivers/media/usb/s2255/s2255drv.c            | 12 +++------
 6 files changed, 31 insertions(+), 76 deletions(-)

-- 
2.52.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/6] media: si470x-usb: refactor endpoint lookup
  2026-03-30 10:11 [PATCH 0/6] media: refactor USB endpoint lookups Johan Hovold
@ 2026-03-30 10:11 ` Johan Hovold
  2026-03-30 10:11 ` [PATCH 2/6] media: imon_raw: " Johan Hovold
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Johan Hovold @ 2026-03-30 10:11 UTC (permalink / raw)
  To: Hans Verkuil, Sean Young, Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel, Johan Hovold

Use the common USB helper for looking up interrupt-in endpoints instead
of open coding.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/media/radio/si470x/radio-si470x-usb.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/media/radio/si470x/radio-si470x-usb.c b/drivers/media/radio/si470x/radio-si470x-usb.c
index 318b5f6d4202..869b1e7e34b9 100644
--- a/drivers/media/radio/si470x/radio-si470x-usb.c
+++ b/drivers/media/radio/si470x/radio-si470x-usb.c
@@ -565,8 +565,7 @@ static int si470x_usb_driver_probe(struct usb_interface *intf,
 {
 	struct si470x_device *radio;
 	struct usb_host_interface *iface_desc;
-	struct usb_endpoint_descriptor *endpoint;
-	int i, int_end_size, retval;
+	int int_end_size, retval;
 	unsigned char version_warning = 0;
 
 	/* private data allocation and initialization */
@@ -595,12 +594,8 @@ static int si470x_usb_driver_probe(struct usb_interface *intf,
 	iface_desc = intf->cur_altsetting;
 
 	/* Set up interrupt endpoint information. */
-	for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
-		endpoint = &iface_desc->endpoint[i].desc;
-		if (usb_endpoint_is_int_in(endpoint))
-			radio->int_in_endpoint = endpoint;
-	}
-	if (!radio->int_in_endpoint) {
+	retval = usb_find_int_in_endpoint(iface_desc, &radio->int_in_endpoint);
+	if (retval) {
 		dev_info(&intf->dev, "could not find interrupt in endpoint\n");
 		retval = -EIO;
 		goto err_usbbuf;
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/6] media: imon_raw: refactor endpoint lookup
  2026-03-30 10:11 [PATCH 0/6] media: refactor USB endpoint lookups Johan Hovold
  2026-03-30 10:11 ` [PATCH 1/6] media: si470x-usb: refactor endpoint lookup Johan Hovold
@ 2026-03-30 10:11 ` Johan Hovold
  2026-03-30 10:11 ` [PATCH 3/6] media: irtoy: " Johan Hovold
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Johan Hovold @ 2026-03-30 10:11 UTC (permalink / raw)
  To: Hans Verkuil, Sean Young, Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel, Johan Hovold

Use the common USB helper for looking up interrupt-in endpoints instead
of open coding.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/media/rc/imon_raw.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git a/drivers/media/rc/imon_raw.c b/drivers/media/rc/imon_raw.c
index 3a526dea6532..295acd6ba9e1 100644
--- a/drivers/media/rc/imon_raw.c
+++ b/drivers/media/rc/imon_raw.c
@@ -105,26 +105,16 @@ static void imon_ir_rx(struct urb *urb)
 static int imon_probe(struct usb_interface *intf,
 		      const struct usb_device_id *id)
 {
-	struct usb_endpoint_descriptor *ir_ep = NULL;
-	struct usb_host_interface *idesc;
+	struct usb_endpoint_descriptor *ir_ep;
 	struct usb_device *udev;
 	struct rc_dev *rcdev;
 	struct imon *imon;
-	int i, ret;
+	int ret;
 
 	udev = interface_to_usbdev(intf);
-	idesc = intf->cur_altsetting;
-
-	for (i = 0; i < idesc->desc.bNumEndpoints; i++) {
-		struct usb_endpoint_descriptor *ep = &idesc->endpoint[i].desc;
-
-		if (usb_endpoint_is_int_in(ep)) {
-			ir_ep = ep;
-			break;
-		}
-	}
 
-	if (!ir_ep) {
+	ret = usb_find_int_in_endpoint(intf->cur_altsetting, &ir_ep);
+	if (ret) {
 		dev_err(&intf->dev, "IR endpoint missing");
 		return -ENODEV;
 	}
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/6] media: irtoy: refactor endpoint lookup
  2026-03-30 10:11 [PATCH 0/6] media: refactor USB endpoint lookups Johan Hovold
  2026-03-30 10:11 ` [PATCH 1/6] media: si470x-usb: refactor endpoint lookup Johan Hovold
  2026-03-30 10:11 ` [PATCH 2/6] media: imon_raw: " Johan Hovold
@ 2026-03-30 10:11 ` Johan Hovold
  2026-03-30 10:11 ` [PATCH 4/6] media: gspca: " Johan Hovold
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Johan Hovold @ 2026-03-30 10:11 UTC (permalink / raw)
  To: Hans Verkuil, Sean Young, Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel, Johan Hovold

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

Note that the device has two bulk endpoints so there is no functional
change here.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/media/rc/ir_toy.c | 23 ++++++-----------------
 1 file changed, 6 insertions(+), 17 deletions(-)

diff --git a/drivers/media/rc/ir_toy.c b/drivers/media/rc/ir_toy.c
index d6472de5da87..f63f06509786 100644
--- a/drivers/media/rc/ir_toy.c
+++ b/drivers/media/rc/ir_toy.c
@@ -393,27 +393,15 @@ static int irtoy_probe(struct usb_interface *intf,
 {
 	struct usb_host_interface *idesc = intf->cur_altsetting;
 	struct usb_device *usbdev = interface_to_usbdev(intf);
-	struct usb_endpoint_descriptor *ep_in = NULL;
-	struct usb_endpoint_descriptor *ep_out = NULL;
-	struct usb_endpoint_descriptor *ep = NULL;
+	struct usb_endpoint_descriptor *ep_in, *ep_out;
 	struct irtoy *irtoy;
 	struct rc_dev *rc;
 	struct urb *urb;
-	int i, pipe, err = -ENOMEM;
+	int pipe, err;
 
-	for (i = 0; i < idesc->desc.bNumEndpoints; i++) {
-		ep = &idesc->endpoint[i].desc;
-
-		if (!ep_in && usb_endpoint_is_bulk_in(ep) &&
-		    usb_endpoint_maxp(ep) == MAX_PACKET)
-			ep_in = ep;
-
-		if (!ep_out && usb_endpoint_is_bulk_out(ep) &&
-		    usb_endpoint_maxp(ep) == MAX_PACKET)
-			ep_out = ep;
-	}
-
-	if (!ep_in || !ep_out) {
+	err = usb_find_common_endpoints(idesc, &ep_in, &ep_out, NULL, NULL);
+	if (err || usb_endpoint_maxp(ep_in) != MAX_PACKET ||
+	    usb_endpoint_maxp(ep_out) != MAX_PACKET) {
 		dev_err(&intf->dev, "required endpoints not found\n");
 		return -ENODEV;
 	}
@@ -422,6 +410,7 @@ static int irtoy_probe(struct usb_interface *intf,
 	if (!irtoy)
 		return -ENOMEM;
 
+	err = -ENOMEM;
 	irtoy->in = kmalloc(MAX_PACKET,  GFP_KERNEL);
 	if (!irtoy->in)
 		goto free_irtoy;
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/6] media: gspca: refactor endpoint lookup
  2026-03-30 10:11 [PATCH 0/6] media: refactor USB endpoint lookups Johan Hovold
                   ` (2 preceding siblings ...)
  2026-03-30 10:11 ` [PATCH 3/6] media: irtoy: " Johan Hovold
@ 2026-03-30 10:11 ` Johan Hovold
  2026-03-30 10:11 ` [PATCH 5/6] media: hdpvr: " Johan Hovold
  2026-03-30 10:11 ` [PATCH 6/6] media: s2255: " Johan Hovold
  5 siblings, 0 replies; 7+ messages in thread
From: Johan Hovold @ 2026-03-30 10:11 UTC (permalink / raw)
  To: Hans Verkuil, Sean Young, Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel, Johan Hovold

Use the common USB helper for looking up interrupt-in endpoints instead
of open coding.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/media/usb/gspca/gspca.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/drivers/media/usb/gspca/gspca.c b/drivers/media/usb/gspca/gspca.c
index 3fc15d16df8e..94f448819d84 100644
--- a/drivers/media/usb/gspca/gspca.c
+++ b/drivers/media/usb/gspca/gspca.c
@@ -208,22 +208,17 @@ static int alloc_and_submit_int_urb(struct gspca_dev *gspca_dev,
 static void gspca_input_create_urb(struct gspca_dev *gspca_dev)
 {
 	struct usb_interface *intf;
-	struct usb_host_interface *intf_desc;
 	struct usb_endpoint_descriptor *ep;
-	int i;
+	int ret;
 
 	if (gspca_dev->sd_desc->int_pkt_scan)  {
 		intf = usb_ifnum_to_if(gspca_dev->dev, gspca_dev->iface);
-		intf_desc = intf->cur_altsetting;
-		for (i = 0; i < intf_desc->desc.bNumEndpoints; i++) {
-			ep = &intf_desc->endpoint[i].desc;
-			if (usb_endpoint_dir_in(ep) &&
-			    usb_endpoint_xfer_int(ep)) {
 
-				alloc_and_submit_int_urb(gspca_dev, ep);
-				break;
-			}
-		}
+		ret = usb_find_int_in_endpoint(intf->cur_altsetting, &ep);
+		if (ret)
+			return;
+
+		alloc_and_submit_int_urb(gspca_dev, ep);
 	}
 }
 
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 5/6] media: hdpvr: refactor endpoint lookup
  2026-03-30 10:11 [PATCH 0/6] media: refactor USB endpoint lookups Johan Hovold
                   ` (3 preceding siblings ...)
  2026-03-30 10:11 ` [PATCH 4/6] media: gspca: " Johan Hovold
@ 2026-03-30 10:11 ` Johan Hovold
  2026-03-30 10:11 ` [PATCH 6/6] media: s2255: " Johan Hovold
  5 siblings, 0 replies; 7+ messages in thread
From: Johan Hovold @ 2026-03-30 10:11 UTC (permalink / raw)
  To: Hans Verkuil, Sean Young, Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel, Johan Hovold

Use the common USB helper for looking up bulk-in endpoints instead of
open coding.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/media/usb/hdpvr/hdpvr-core.c | 26 ++++++++------------------
 1 file changed, 8 insertions(+), 18 deletions(-)

diff --git a/drivers/media/usb/hdpvr/hdpvr-core.c b/drivers/media/usb/hdpvr/hdpvr-core.c
index d42336836b18..849a2be416bd 100644
--- a/drivers/media/usb/hdpvr/hdpvr-core.c
+++ b/drivers/media/usb/hdpvr/hdpvr-core.c
@@ -265,13 +265,10 @@ static int hdpvr_probe(struct usb_interface *interface,
 		       const struct usb_device_id *id)
 {
 	struct hdpvr_device *dev;
-	struct usb_host_interface *iface_desc;
 	struct usb_endpoint_descriptor *endpoint;
 #if IS_ENABLED(CONFIG_I2C)
 	struct i2c_client *client;
 #endif
-	size_t buffer_size;
-	int i;
 	int dev_num;
 	int retval = -ENOMEM;
 
@@ -321,25 +318,18 @@ static int hdpvr_probe(struct usb_interface *interface,
 
 	/* set up the endpoint information */
 	/* use only the first bulk-in and bulk-out endpoints */
-	iface_desc = interface->cur_altsetting;
-	for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
-		endpoint = &iface_desc->endpoint[i].desc;
-
-		if (!dev->bulk_in_endpointAddr &&
-		    usb_endpoint_is_bulk_in(endpoint)) {
-			/* USB interface description is buggy, reported max
-			 * packet size is 512 bytes, windows driver uses 8192 */
-			buffer_size = 8192;
-			dev->bulk_in_size = buffer_size;
-			dev->bulk_in_endpointAddr = endpoint->bEndpointAddress;
-		}
-
-	}
-	if (!dev->bulk_in_endpointAddr) {
+	if (usb_find_bulk_in_endpoint(interface->cur_altsetting, &endpoint)) {
 		v4l2_err(&dev->v4l2_dev, "Could not find bulk-in endpoint\n");
 		goto error_put_usb;
 	}
 
+	/*
+	 * USB interface description is buggy, reported max packet size is 512
+	 * bytes, windows driver uses 8192
+	 */
+	dev->bulk_in_size = 8192;
+	dev->bulk_in_endpointAddr = endpoint->bEndpointAddress;
+
 	/* init the device */
 	if (hdpvr_device_init(dev)) {
 		v4l2_err(&dev->v4l2_dev, "device init failed\n");
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 6/6] media: s2255: refactor endpoint lookup
  2026-03-30 10:11 [PATCH 0/6] media: refactor USB endpoint lookups Johan Hovold
                   ` (4 preceding siblings ...)
  2026-03-30 10:11 ` [PATCH 5/6] media: hdpvr: " Johan Hovold
@ 2026-03-30 10:11 ` Johan Hovold
  5 siblings, 0 replies; 7+ messages in thread
From: Johan Hovold @ 2026-03-30 10:11 UTC (permalink / raw)
  To: Hans Verkuil, Sean Young, Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel, Johan Hovold

Use the common USB helper for looking up bulk-in endpoints instead of
open coding.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/media/usb/s2255/s2255drv.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/media/usb/s2255/s2255drv.c b/drivers/media/usb/s2255/s2255drv.c
index 2c02873d09b5..0b8182edf8e4 100644
--- a/drivers/media/usb/s2255/s2255drv.c
+++ b/drivers/media/usb/s2255/s2255drv.c
@@ -2240,18 +2240,14 @@ static int s2255_probe(struct usb_interface *interface,
 	iface_desc = interface->cur_altsetting;
 	dev_dbg(&interface->dev, "num EP: %d\n",
 		iface_desc->desc.bNumEndpoints);
-	for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
-		endpoint = &iface_desc->endpoint[i].desc;
-		if (!dev->read_endpoint && usb_endpoint_is_bulk_in(endpoint)) {
-			/* we found the bulk in endpoint */
-			dev->read_endpoint = endpoint->bEndpointAddress;
-		}
-	}
 
-	if (!dev->read_endpoint) {
+	if (usb_find_bulk_in_endpoint(iface_desc, &endpoint)) {
 		dev_err(&interface->dev, "Could not find bulk-in endpoint\n");
 		goto errorEP;
 	}
+
+	dev->read_endpoint = endpoint->bEndpointAddress;
+
 	timer_setup(&dev->timer, s2255_timer, 0);
 	init_waitqueue_head(&dev->fw_data->wait_fw);
 	for (i = 0; i < MAX_CHANNELS; i++) {
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-03-30 10:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-30 10:11 [PATCH 0/6] media: refactor USB endpoint lookups Johan Hovold
2026-03-30 10:11 ` [PATCH 1/6] media: si470x-usb: refactor endpoint lookup Johan Hovold
2026-03-30 10:11 ` [PATCH 2/6] media: imon_raw: " Johan Hovold
2026-03-30 10:11 ` [PATCH 3/6] media: irtoy: " Johan Hovold
2026-03-30 10:11 ` [PATCH 4/6] media: gspca: " Johan Hovold
2026-03-30 10:11 ` [PATCH 5/6] media: hdpvr: " Johan Hovold
2026-03-30 10:11 ` [PATCH 6/6] media: s2255: " Johan Hovold

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox