int			mem_flags 
unsigned		mem_flags 
int usb_sg_init (	struct usb_sg_request	*io,	struct usb_device	*dev,	unsigned		pipe, 	unsigned		period,	struct scatterlist	*sg,	int			nents,	size_t			length,	int			mem_flags){	int			i;	int			urb_flags;	int			dma;	if (!io || !dev || !sg			|| usb_pipecontrol (pipe)			|| usb_pipeisoc (pipe)			|| nents <= 0)		return -EINVAL;	spin_lock_init (&io->lock);	io->dev = dev;	io->pipe = pipe;	io->sg = sg;	io->nents = nents;	/* not all host controllers use DMA (like the mainstream pci ones);	 * they can use PIO (sl811) or be software over another transport.	 */	dma = (dev->dev.dma_mask != NULL);	if (dma)		io->entries = usb_buffer_map_sg (dev, pipe, sg, nents);	else		io->entries = nents;	/* initialize all the urbs we'll use */	if (io->entries <= 0)		return io->entries;	io->count = io->entries;	io->urbs = kmalloc (io->entries * sizeof *io->urbs, mem_flags);	if (!io->urbs)		goto nomem;	urb_flags = URB_ASYNC_UNLINK | URB_NO_TRANSFER_DMA_MAP			| URB_NO_INTERRUPT;	if (usb_pipein (pipe))		urb_flags |= URB_SHORT_NOT_OK;	for (i = 0; i < io->entries; i++) {		unsigned		len;		io->urbs [i] = usb_alloc_urb (0, mem_flags);		if (!io->urbs [i]) {			io->entries = i;			goto nomem;		}		io->urbs [i]->dev = NULL;		io->urbs [i]->pipe = pipe;		io->urbs [i]->interval = period;		io->urbs [i]->transfer_flags = urb_flags;		io->urbs [i]->complete = sg_complete;		io->urbs [i]->context = io;		io->urbs [i]->status = -EINPROGRESS;		io->urbs [i]->actual_length = 0;		if (dma) {			/* hc may use _only_ transfer_dma */			io->urbs [i]->transfer_dma = sg_dma_address (sg + i);			len = sg_dma_len (sg + i);		} else {			/* hc may use _only_ transfer_buffer */			io->urbs [i]->transfer_buffer =				page_address (sg [i].page) + sg [i].offset;			len = sg [i].length;		}		if (length) {			len = min_t (unsigned, len, length);			length -= len;			if (length == 0)				io->entries = i + 1;		}		io->urbs [i]->transfer_buffer_length = len;	}	io->urbs [--i]->transfer_flags &= ~URB_NO_INTERRUPT;	/* transaction state */	io->status = 0;	io->bytes = 0;	init_completion (&io->complete);	return 0;nomem:	sg_clean (io);	return -ENOMEM;}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/5db539e49fc7471e23bf3c94ca304f008cb7b7f3/message.c/buggy/drivers/usb/core/message.c