Skip to contentSkip to conversation

media: refactor USB endpoint lookups

PATCH In review Johan Hovold 2 participants 10 messages Mar 30 – Apr 30 1 message not in the archive

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover media: refactor USB endpoint lookups

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(-)
Signature · 1 line
2.52.0
#1 lore raw

PATCH 1/6 media: si470x-usb: refactor endpoint lookup

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

---
 drivers/media/radio/si470x/radio-si470x-usb.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/media/radio/si470x/radio-si470x-usb.c +3 -8
index 318b5f6d4202..869b1e7e34b9 100644
@@ -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;
Signature · 1 line
2.52.0
#2 lore raw

PATCH 2/6 media: imon_raw: refactor endpoint lookup

In reply to Johan Hovold

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

---
 drivers/media/rc/imon_raw.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
drivers/media/rc/imon_raw.c +4 -14
index 3a526dea6532..295acd6ba9e1 100644
@@ -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;
 	}
Signature · 1 line
2.52.0
#3 lore raw

PATCH 3/6 media: irtoy: refactor endpoint lookup

In reply to 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.

---
 drivers/media/rc/ir_toy.c | 23 ++++++-----------------
 1 file changed, 6 insertions(+), 17 deletions(-)
drivers/media/rc/ir_toy.c +6 -17
index d6472de5da87..f63f06509786 100644
@@ -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;
Signature · 1 line
2.52.0
#4 lore raw

PATCH 4/6 media: gspca: refactor endpoint lookup

In reply to Johan Hovold

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

---
 drivers/media/usb/gspca/gspca.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)
drivers/media/usb/gspca/gspca.c +6 -11
index 3fc15d16df8e..94f448819d84 100644
@@ -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);
 	}
 }
 
Signature · 1 line
2.52.0
#5 lore raw

PATCH 5/6 media: hdpvr: refactor endpoint lookup

In reply to Johan Hovold

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

---
 drivers/media/usb/hdpvr/hdpvr-core.c | 26 ++++++++------------------
 1 file changed, 8 insertions(+), 18 deletions(-)
drivers/media/usb/hdpvr/hdpvr-core.c +8 -18
index d42336836b18..849a2be416bd 100644
@@ -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");
Signature · 1 line
2.52.0
#6 lore raw

PATCH 6/6 media: s2255: refactor endpoint lookup

In reply to Johan Hovold

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

---
 drivers/media/usb/s2255/s2255drv.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/media/usb/s2255/s2255drv.c +4 -8
index 2c02873d09b5..0b8182edf8e4 100644
@@ -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++) {
Signature · 1 line
2.52.0
#8 lore raw
In reply to a message not in the archive
Quoted 12 lines · Patchwork Integration

Thanks for your patches! Unfortunately the Media CI robot detected some issues:

# Test checkpatch:./0005-media-hdpvr-refactor-endpoint-lookup.patch checkpatch
CHECK: Avoid CamelCase: <bulk_in_endpointAddr>
#62: FILE: drivers/media/usb/hdpvr/hdpvr-core.c:331:
+dev->bulk_in_endpointAddr = endpoint->bEndpointAddress;

total: 0 errors, 0 warnings, 1 checks, 46 lines checked

Quoted 6 lines

Please fix your series, and upload a new version. If you have a patchwork account, do not forget to mark the current series as Superseded.

If you believe that the CI is wrong, kindly open an issue at
https://gitlab.freedesktop.org/linux-media/media-ci/-/issues or reply-all to this message.

Checkpatch is complaining about an existing issue in the driver so this bot warning is not valid.

Johan

#9 lore raw
In reply to Johan Hovold
Quoted 10 lines · Johan Hovold

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

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

Can these be picked up now?

There was some complaint from the media CI robot which did not look valid so I'm hoping these have not been silently rejected.

Johan

#10 lore raw
Quoted 7 lines · Johan Hovold
Quoted 6 lines · Johan Hovold

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

Johan Hovold (6):
media: imon_raw: refactor endpoint lookup
media: irtoy: refactor endpoint lookup

These two are in my queue - they look good, just need some testing. Sorry they should've been included for 7.1.

Thanks

Sean

Quoted 11 lines
Quoted 4 lines

media: gspca: refactor endpoint lookup
media: si470x-usb: refactor endpoint lookup
media: hdpvr: refactor endpoint lookup
media: s2255: refactor endpoint lookup

Can these be picked up now?

There was some complaint from the media CI robot which did not look valid so I'm hoping these have not been silently rejected.

Johan