Deleted Added
full compact
usb_device.c (250202) usb_device.c (250204)
1/* $FreeBSD: head/sys/dev/usb/usb_device.c 250202 2013-05-03 08:19:09Z hselasky $ */
1/* $FreeBSD: head/sys/dev/usb/usb_device.c 250204 2013-05-03 09:23:06Z hselasky $ */
2/*-
3 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.

--- 714 unchanged lines hidden (view full) ---

724
725 memset(&ips, 0, sizeof(ips));
726
727 ep_curr = 0;
728 ep_max = 0;
729
730 while ((id = usb_idesc_foreach(udev->cdesc, &ips))) {
731
2/*-
3 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.

--- 714 unchanged lines hidden (view full) ---

724
725 memset(&ips, 0, sizeof(ips));
726
727 ep_curr = 0;
728 ep_max = 0;
729
730 while ((id = usb_idesc_foreach(udev->cdesc, &ips))) {
731
732 /* check for interface overflow */
733 if (ips.iface_index == USB_IFACE_MAX)
734 break; /* crazy */
735
736 iface = udev->ifaces + ips.iface_index;
737
738 /* check for specific interface match */
739
740 if (cmd == USB_CFG_INIT) {
741 if ((iface_index != USB_IFACE_INDEX_ANY) &&
742 (iface_index != ips.iface_index)) {
743 /* wrong interface */

--- 30 unchanged lines hidden (view full) ---

774
775 ed = (struct usb_endpoint_descriptor *)id;
776
777 temp = ep_curr;
778
779 /* iterate all the endpoint descriptors */
780 while ((ed = usb_edesc_foreach(udev->cdesc, ed))) {
781
732 iface = udev->ifaces + ips.iface_index;
733
734 /* check for specific interface match */
735
736 if (cmd == USB_CFG_INIT) {
737 if ((iface_index != USB_IFACE_INDEX_ANY) &&
738 (iface_index != ips.iface_index)) {
739 /* wrong interface */

--- 30 unchanged lines hidden (view full) ---

770
771 ed = (struct usb_endpoint_descriptor *)id;
772
773 temp = ep_curr;
774
775 /* iterate all the endpoint descriptors */
776 while ((ed = usb_edesc_foreach(udev->cdesc, ed))) {
777
782 if (temp == USB_EP_MAX)
783 break; /* crazy */
778 /* check if endpoint limit has been reached */
779 if (temp >= USB_MAX_EP_UNITS) {
780 DPRINTF("Endpoint limit reached\n");
781 break;
782 }
784
785 ep = udev->endpoints + temp;
786
787 if (do_init) {
788 void *ecomp;
789
790 ecomp = usb_ed_comp_foreach(udev->cdesc, (void *)ed);
791 if (ecomp != NULL)

--- 13 unchanged lines hidden (view full) ---

805 id = (struct usb_interface_descriptor *)ed;
806 }
807 }
808
809 /* NOTE: It is valid to have no interfaces and no endpoints! */
810
811 if (cmd == USB_CFG_ALLOC) {
812 udev->ifaces_max = ips.iface_index;
783
784 ep = udev->endpoints + temp;
785
786 if (do_init) {
787 void *ecomp;
788
789 ecomp = usb_ed_comp_foreach(udev->cdesc, (void *)ed);
790 if (ecomp != NULL)

--- 13 unchanged lines hidden (view full) ---

804 id = (struct usb_interface_descriptor *)ed;
805 }
806 }
807
808 /* NOTE: It is valid to have no interfaces and no endpoints! */
809
810 if (cmd == USB_CFG_ALLOC) {
811 udev->ifaces_max = ips.iface_index;
812#if (USB_HAVE_FIXED_IFACE == 0)
813 udev->ifaces = NULL;
814 if (udev->ifaces_max != 0) {
815 udev->ifaces = malloc(sizeof(*iface) * udev->ifaces_max,
816 M_USB, M_WAITOK | M_ZERO);
817 if (udev->ifaces == NULL) {
818 err = USB_ERR_NOMEM;
819 goto done;
820 }
821 }
813 udev->ifaces = NULL;
814 if (udev->ifaces_max != 0) {
815 udev->ifaces = malloc(sizeof(*iface) * udev->ifaces_max,
816 M_USB, M_WAITOK | M_ZERO);
817 if (udev->ifaces == NULL) {
818 err = USB_ERR_NOMEM;
819 goto done;
820 }
821 }
822#endif
823#if (USB_HAVE_FIXED_ENDPOINT == 0)
822 if (ep_max != 0) {
823 udev->endpoints = malloc(sizeof(*ep) * ep_max,
824 M_USB, M_WAITOK | M_ZERO);
825 if (udev->endpoints == NULL) {
826 err = USB_ERR_NOMEM;
827 goto done;
828 }
829 } else {
830 udev->endpoints = NULL;
831 }
824 if (ep_max != 0) {
825 udev->endpoints = malloc(sizeof(*ep) * ep_max,
826 M_USB, M_WAITOK | M_ZERO);
827 if (udev->endpoints == NULL) {
828 err = USB_ERR_NOMEM;
829 goto done;
830 }
831 } else {
832 udev->endpoints = NULL;
833 }
834#endif
832 USB_BUS_LOCK(udev->bus);
833 udev->endpoints_max = ep_max;
834 /* reset any ongoing clear-stall */
835 udev->ep_curr = NULL;
836 USB_BUS_UNLOCK(udev->bus);
837 }
838
839done:
840 if (err) {
841 if (cmd == USB_CFG_ALLOC) {
842cleanup:
843 USB_BUS_LOCK(udev->bus);
844 udev->endpoints_max = 0;
845 /* reset any ongoing clear-stall */
846 udev->ep_curr = NULL;
847 USB_BUS_UNLOCK(udev->bus);
848
835 USB_BUS_LOCK(udev->bus);
836 udev->endpoints_max = ep_max;
837 /* reset any ongoing clear-stall */
838 udev->ep_curr = NULL;
839 USB_BUS_UNLOCK(udev->bus);
840 }
841
842done:
843 if (err) {
844 if (cmd == USB_CFG_ALLOC) {
845cleanup:
846 USB_BUS_LOCK(udev->bus);
847 udev->endpoints_max = 0;
848 /* reset any ongoing clear-stall */
849 udev->ep_curr = NULL;
850 USB_BUS_UNLOCK(udev->bus);
851
849 /* cleanup */
850 if (udev->ifaces != NULL)
851 free(udev->ifaces, M_USB);
852 if (udev->endpoints != NULL)
853 free(udev->endpoints, M_USB);
854
852#if (USB_HAVE_FIXED_IFACE == 0)
853 free(udev->ifaces, M_USB);
855 udev->ifaces = NULL;
854 udev->ifaces = NULL;
855#endif
856#if (USB_HAVE_FIXED_ENDPOINT == 0)
857 free(udev->endpoints, M_USB);
856 udev->endpoints = NULL;
858 udev->endpoints = NULL;
859#endif
857 udev->ifaces_max = 0;
858 }
859 }
860 return (err);
861}
862
863/*------------------------------------------------------------------------*
864 * usbd_set_alt_interface_index

--- 1955 unchanged lines hidden ---
860 udev->ifaces_max = 0;
861 }
862 }
863 return (err);
864}
865
866/*------------------------------------------------------------------------*
867 * usbd_set_alt_interface_index

--- 1955 unchanged lines hidden ---