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 |
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 |
778 /* check if endpoint limit has been reached */ 779 if (temp >= USB_MAX_EP_UNITS) { 780 DPRINTF("Endpoint limit reached\n"); 781 break; 782 } |
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 } |
822#endif 823#if (USB_HAVE_FIXED_ENDPOINT == 0) |
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 |
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 |
852#if (USB_HAVE_FIXED_IFACE == 0) 853 free(udev->ifaces, M_USB); |
854 udev->ifaces = NULL; |
855#endif 856#if (USB_HAVE_FIXED_ENDPOINT == 0) 857 free(udev->endpoints, M_USB); |
858 udev->endpoints = NULL; |
859#endif |
860 udev->ifaces_max = 0; 861 } 862 } 863 return (err); 864} 865 866/*------------------------------------------------------------------------* 867 * usbd_set_alt_interface_index --- 1955 unchanged lines hidden --- |