/* allocate memory for our device state and intialize it */ 
/* allocate memory for our device state and initialize it */ 
static int tower_probe (struct usb_interface *interface, const struct usb_device_id *id){	struct usb_device *udev = interface_to_usbdev(interface);	struct lego_usb_tower *dev = NULL;	struct usb_host_interface *iface_desc;	struct usb_endpoint_descriptor* endpoint;	struct tower_get_version_reply get_version_reply;	int i;	int retval = -ENOMEM;	int result;	dbg(2, "%s: enter", __FUNCTION__);	if (udev == NULL) {		info ("udev is NULL.");	}	/* allocate memory for our device state and intialize it */	dev = kmalloc (sizeof(struct lego_usb_tower), GFP_KERNEL);	if (dev == NULL) {		err ("Out of memory");		goto exit;	}	init_MUTEX (&dev->sem);	dev->udev = udev;	dev->open_count = 0;	dev->read_buffer = NULL;	dev->read_buffer_length = 0;	dev->read_packet_length = 0;	spin_lock_init (&dev->read_buffer_lock);	dev->packet_timeout_jiffies = packet_timeout * HZ / 1000;	dev->read_last_arrival = jiffies;	init_waitqueue_head (&dev->read_wait);	init_waitqueue_head (&dev->write_wait);	dev->interrupt_in_buffer = NULL;	dev->interrupt_in_endpoint = NULL;	dev->interrupt_in_urb = NULL;	dev->interrupt_in_running = 0;	dev->interrupt_in_done = 0;	dev->interrupt_out_buffer = NULL;	dev->interrupt_out_endpoint = NULL;	dev->interrupt_out_urb = NULL;	dev->interrupt_out_busy = 0;	iface_desc = interface->cur_altsetting;	/* set up the endpoint information */	for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {		endpoint = &iface_desc->endpoint[i].desc;		if (((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) &&		    ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)) {			dev->interrupt_in_endpoint = endpoint;		}		if (((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) &&		    ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)) {			dev->interrupt_out_endpoint = endpoint;		}	}	if(dev->interrupt_in_endpoint == NULL) {		err("interrupt in endpoint not found");		goto error;	}	if (dev->interrupt_out_endpoint == NULL) {		err("interrupt out endpoint not found");		goto error;	}	dev->read_buffer = kmalloc (read_buffer_size, GFP_KERNEL);	if (!dev->read_buffer) {		err("Couldn't allocate read_buffer");		goto error;	}	dev->interrupt_in_buffer = kmalloc (le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize), GFP_KERNEL);	if (!dev->interrupt_in_buffer) {		err("Couldn't allocate interrupt_in_buffer");		goto error;	}	dev->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL);	if (!dev->interrupt_in_urb) {		err("Couldn't allocate interrupt_in_urb");		goto error;	}	dev->interrupt_out_buffer = kmalloc (write_buffer_size, GFP_KERNEL);	if (!dev->interrupt_out_buffer) {		err("Couldn't allocate interrupt_out_buffer");		goto error;	}	dev->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL);	if (!dev->interrupt_out_urb) {		err("Couldn't allocate interrupt_out_urb");		goto error;	}	dev->interrupt_in_interval = interrupt_in_interval ? interrupt_in_interval : dev->interrupt_in_endpoint->bInterval;	dev->interrupt_out_interval = interrupt_out_interval ? interrupt_out_interval : dev->interrupt_out_endpoint->bInterval;	/* we can register the device now, as it is ready */	usb_set_intfdata (interface, dev);	retval = usb_register_dev (interface, &tower_class);	if (retval) {		/* something prevented us from registering this driver */		err ("Not able to get a minor for this device.");		usb_set_intfdata (interface, NULL);		goto error;	}	dev->minor = interface->minor;	/* let the user know what node this device is now attached to */	info ("LEGO USB Tower #%d now attached to major %d minor %d", (dev->minor - LEGO_USB_TOWER_MINOR_BASE), USB_MAJOR, dev->minor);	/* get the firmware version and log it */	result = usb_control_msg (udev,				  usb_rcvctrlpipe(udev, 0),				  LEGO_USB_TOWER_REQUEST_GET_VERSION,				  USB_TYPE_VENDOR | USB_DIR_IN | USB_RECIP_DEVICE,				  0,				  0,				  &get_version_reply,				  sizeof(get_version_reply),				  1000);	if (result < 0) {		err("LEGO USB Tower get version control request failed");		retval = result;		goto error;	}	info("LEGO USB Tower firmware version is %d.%d build %d",	     get_version_reply.major,	     get_version_reply.minor,	     le16_to_cpu(get_version_reply.build_no));exit:	dbg(2, "%s: leave, return value 0x%.8lx (dev)", __FUNCTION__, (long) dev);	return retval;error:	tower_delete(dev);	return retval;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/093cf723b2b06d774929ea07982f6a466ff22314/legousbtower.c/clean/drivers/usb/misc/legousbtower.c