Re: how can i make the skeleton read function blocking function?

"Wael Adel" <[email protected]>
Newsgroups gmane.linux.usb.devel
Message-ID <[email protected]>
Dear Oliver forgive me for my many questions but here are the
modificaions that u adviced me to do but i think there is still
something wrong because when the gadget sends "hello" for example to
the host, my computer is hanging so what is the error ,i m gonna be
made:

here is the last code for skel_read:


static void skel_read_bulk_callback(struct urb *urb, struct pt_regs *regs)
{
	struct usb_skel *dev;
	complete((struct completion *)urb->context);
	dev = (struct usb_skel *)urb->context;
	up(&dev->limit_sem);
}

static ssize_t skel_read(struct file *file, char *user_buffer, size_t
count, loff_t *ppos)

{
	struct completion done;
	struct usb_skel *dev;
	int retval = 0;
	struct urb *urb = NULL;
	char *buf = NULL;

	size_t readsize = min(count, (size_t)MAX_TRANSFER);

	dev = (struct usb_skel *)file->private_data;

	/* verify that we actually have some data to read */
	if (count == 0)
		goto exit;

	/* limit the number of URBs in flight to stop a user from using up all RAM */
	if (down_interruptible(&dev->limit_sem)) {
		retval = -ERESTARTSYS;
		goto exit;
	}

	init_completion(&done);

	/* create a urb, and a buffer for it, and copy the data to the urb */
	urb = usb_alloc_urb(0, GFP_KERNEL);
	if (!urb) {
		retval = -ENOMEM;
		goto error;
	}

	buf = usb_buffer_alloc(dev->udev, readsize, GFP_KERNEL, &urb->transfer_dma);
	if (!buf) {
		retval = -ENOMEM;
		goto error;
	}

	/* initialize the urb properly */
	usb_fill_bulk_urb(urb, dev->udev,
			  usb_rcvbulkpipe(dev->udev, dev->bulk_in_endpointAddr),
			  buf, readsize, skel_read_bulk_callback, &done);
	urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;

	/* send the data out the bulk port */
	retval = usb_submit_urb(urb, GFP_KERNEL);
	if (retval) {
		err("%s - failed submitting read urb, error %d", __FUNCTION__, retval);
		goto error;
	}

	wait_for_completion(&done);

	if (   copy_to_user(user_buffer, dev->bulk_in_buffer, urb->actual_length) )
		retval = -EFAULT;
	else
		retval = urb->actual_length;

	
	/* free up our allocated buffer */
	usb_buffer_free(urb->dev, urb->transfer_buffer_length,
			urb->transfer_buffer, urb->transfer_dma);
	/* release our reference to this urb, the USB core will eventually
free it entirely */
	usb_free_urb(urb);

	return retval;

exit:
	return retval;

error:
	usb_buffer_free(dev->udev, readsize, buf, urb->transfer_dma);
	usb_free_urb(urb);
	up(&dev->limit_sem);
	return retval;
}


thanks in advance
yours nesta

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.