Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 920df8d7 authored by Johan Hovold's avatar Johan Hovold Committed by Greg Kroah-Hartman
Browse files

USB: iowarrior: refactor endpoint retrieval



Use the new endpoint helpers to lookup the required interrupt-in
endpoint.

IOWarror56 devices also requires an interrupt-out endpoint, which is
looked up in a second call.

Note that the descriptors are searched in reverse order to avoid any
regressions.

Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent fa38442e
Loading
Loading
Loading
Loading
+8 −17
Original line number Original line Diff line number Diff line
@@ -756,9 +756,8 @@ static int iowarrior_probe(struct usb_interface *interface,
	struct usb_device *udev = interface_to_usbdev(interface);
	struct usb_device *udev = interface_to_usbdev(interface);
	struct iowarrior *dev = NULL;
	struct iowarrior *dev = NULL;
	struct usb_host_interface *iface_desc;
	struct usb_host_interface *iface_desc;
	struct usb_endpoint_descriptor *endpoint;
	int i;
	int retval = -ENOMEM;
	int retval = -ENOMEM;
	int res;


	/* allocate memory for our device state and initialize it */
	/* allocate memory for our device state and initialize it */
	dev = kzalloc(sizeof(struct iowarrior), GFP_KERNEL);
	dev = kzalloc(sizeof(struct iowarrior), GFP_KERNEL);
@@ -781,27 +780,19 @@ static int iowarrior_probe(struct usb_interface *interface,
	iface_desc = interface->cur_altsetting;
	iface_desc = interface->cur_altsetting;
	dev->product_id = le16_to_cpu(udev->descriptor.idProduct);
	dev->product_id = le16_to_cpu(udev->descriptor.idProduct);


	/* set up the endpoint information */
	res = usb_find_last_int_in_endpoint(iface_desc, &dev->int_in_endpoint);
	for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
	if (res) {
		endpoint = &iface_desc->endpoint[i].desc;

		if (usb_endpoint_is_int_in(endpoint))
			dev->int_in_endpoint = endpoint;
		if (usb_endpoint_is_int_out(endpoint))
			/* this one will match for the IOWarrior56 only */
			dev->int_out_endpoint = endpoint;
	}

	if (!dev->int_in_endpoint) {
		dev_err(&interface->dev, "no interrupt-in endpoint found\n");
		dev_err(&interface->dev, "no interrupt-in endpoint found\n");
		retval = -ENODEV;
		retval = res;
		goto error;
		goto error;
	}
	}


	if (dev->product_id == USB_DEVICE_ID_CODEMERCS_IOW56) {
	if (dev->product_id == USB_DEVICE_ID_CODEMERCS_IOW56) {
		if (!dev->int_out_endpoint) {
		res = usb_find_last_int_out_endpoint(iface_desc,
				&dev->int_out_endpoint);
		if (res) {
			dev_err(&interface->dev, "no interrupt-out endpoint found\n");
			dev_err(&interface->dev, "no interrupt-out endpoint found\n");
			retval = -ENODEV;
			retval = res;
			goto error;
			goto error;
		}
		}
	}
	}